Using DirectLine v3, how do you send a message to the USER? - rest

I'm implementing a DirectLine client for connecting WhatsApp via Twilio and the BotFramework. I've been able to:
Create conversations
Listen to the conversation's websocket
Send activities to the bot
For the life of me I cannot figure out how I can send an activity to the DirectLine client, so it can forward it to the user. In other words, how can I get some activity to pop-up on the DL client's websocket?
On the bot side, what I'm doing is:
Ask the client to create a conversation in DirectLine between the bot and the user (I'm using phone numbers as recipient/from IDs)
Use the new conversation and its serviceUrl to post an activity from the bot to the user
I've tried a bunch of different auth tokens to do this, the closest I've gotten was using the conversation's DirectLine token as a bearer auth:
POST https://directline.botframework.com/v3/directline/conversations/CONVERSATION_ID/activities
{
"type": "message",
"text": "message",
"from": { "id": "whatsapp:BOT_PHONE_NUMBER" },
"recipient": { "id": "whatsapp:USER_PHONE_NUMBER" }
}
Which results in this activity popping up in the websocket:
{
"channelId": "directline",
"conversation": {"id": "CONVERSATION_ID"},
"from": {"id": "whatsapp:BOT_PHONE_NUMBER"},
"id": "CONVERSATION_ID|0000006",
"recipient": {
"id": "BOT_ID#something",
"name": "Bot"
},
"serviceUrl": "https://directline.botframework.com/",
"text": "pls",
"timestamp": "2019-08-26T23:14:13.3099739Z",
"type": "message"
}
Which is obviously useless because the user's phone number is missing?! Instead the "recipient" was overwritten to the bot's.
My question is: What exactly is the canonical way to achieve this?
I can just bypass the BF altogether, call my client and have it send a message to the user. This means, however, that the implementation for this channel is different from all others. If this is the way to go, what's the point of the websockets then?

Related

End Google Assistant Conversation

I have an application that communicates with Google Assistant via Webhook. When a user asks for something, my app sends the question to AI (Watson IBM). After it gets the response, I want to show it to the user and end the conversation. So I send a text from Watson and nextSecene =actions.scene.END_CONVERSATION. But Google Assistant just ends the conversation without showing the response to user. So is it possible to show the response message to the user and than end the conversation?
Example of my app JSON format response:
GAResponse(prompt=GAPrompt(override=false, firstSimple=GAFirstSimple(speech=<speak>You are very smart bro,y<break time="100ms"/> and i love monsters like you.</speak>, text=You are very smart bro and i love monsters like you), content=null, lastSimple=null, link=null, canvas=null, orderUpdate=null), scene=GAScene(name=null, slotFillingStatus=null, slots=null, next=actions.scene.END_CONVERSATION) ...)
Yes this is possible.
I'm not sure which library your using to generate your response json, but below is an example that provides the speech and text data and ends the conversation. You can learn more on the fulfillment (aka webhook) on the reference documentation
{
"session": {
"id": "example_session_id",
"params": {}
},
"prompt": {
"override": false,
"firstSimple": {
"speech": "<speak>You are very smart bro, <break time="100ms"/> and i love monsters like you.</speak>",
"text": "You are very smart bro and i love monsters like you"
}
},
"scene": {
"name": "SceneName",
"slots": {},
"next": {
"name": "actions.scene.END_CONVERSATION"
}
}
}
If you're interested in using Assistant Conversation libraray, check out this link to see an example response

Trigger Botframework v4 on Facebook Messenger from an external website call

i am trying to open a specific messenger page and trigger a dialog to display carousels based on the parameters that my users entered on my website.
i am leveraging the m.me link to open my messenger page (where my botframeowrk bot is deployed). After opening the page I am not able to invoke a dialog.
How can I achieve this ???
I went through the Ms Botframework V4 docs and didn't find any mention of channel specific trigger.I want to pass 4 parameters to my Bot from the website and then further make an api call in the dialog that i will invoke to display results.
Thanks in Advance.
You need to enable Messaging Referrals in the Facebook Developer portal to use m.me links. In the portal, click on the settings blade on the left, scroll down to webhooks, and click edit events. A window should pop up where you can enable messaging_referrals.
Facebook only lets you add the ref parameter to the m.me link, so to send additional data to the bot using this link, you will have to encode the values in the ref parameter and parse the data on the bot side - I would recommend using a separator value like a comma or a slash to organize your data.
https://m.me/<PAGE_NAME>?ref=my,additional,data
The event will be send to the bot as a message activity with a referral attribute where you can grab your data.
m.me link bot activity
{
"type": "message",
"id": "CDbQi3u62J7",
"timestamp": "2019-03-19T19:30:11.219Z",
"serviceUrl": "https://facebook.botframework.com/",
"channelId": "facebook",
"from": {
"id": "2031650190235097",
"name": "TJ Durnford"
},
"conversation": {
"isGroup": false,
"id": "2031650190235097-218838049015546"
},
"recipient": {
"id": "218838049015546",
"name": "thdurn-all-channels"
},
"channelData": {
"sender": {
"id": "2031650190235097"
},
"recipient": {
"id": "218838049015546"
},
"timestamp": 1553023811219,
"referral": {
"ref": "my,additional,data",
"source": "SHORTLINK",
"type": "OPEN_THREAD"
}
}
Hope this helps!

Skype Bot sending message (not a reply)

Trying to create a Skype Bot, but I have a problem. Please, help me.
I use PHP so I use REST (not NodeJS or C# SDK).
The task: I have to send data from html form on my website to Skype (so I don’t have to reply to a message, but just send).
Well, I have successfully create a bot in Microsoft Bot Framework.
Then I have successfully received an access_token.
Then they say in docs that I have to send a POST to:
/v3/conversations/{conversationId}/activities
According to https://learn.microsoft.com/en-us/bot-framework/rest-api/bot-framework-rest-connector-send-and-receive-messages I have to send a request to /v3/conversations with JSON like that:
{
"bot": {
"id": "12345678",
"name": "bot's name"
},
"isGroup": false,
"members": [
{
"id": "1234abcd",
"name": "recipient's name"
}
],
"topicName": "News Alert"
}
But what is the "member's id and member's name"?
To get the member ids of some members, add all those members in a group and add the bot, too, to the group and preferably send a message in the group, mentioning the bot. You will receive a json with a conversationId. With this conversationId, make a get request to v3/conversations/{conversationId}/members in order to receive the member-ids and member-names of the members in the group.
You can now proceed with these member-ids and member-names to start individual conversations with the members (which is illustrated in my answer to this question).

setting event organizer with Outlook Calendar REST API

I am using the Outlook REST API for creating events and sending its invitations, based on this documentation
I authenticate the logged in user, and send its Bearer token through the Authorization header of the request, and the json-formatted event on its content.
If I set the "Organizer" to another user rather than the authenticated one, as well as the "IsOrganizer" property to "false", it gets totally ignored and sets the current logged in user as the organizer.
Any clues of what could be happening?
Is there another way of doing this?
Thank you!
I'm posting this in case someone else finds and needs an answer for this scenario...
You (Account A) can create a calendar event as someone else (Account B) through Office365 REST APIs as long as the account has permission to send as the other user account.
Here are the steps:
1) Call the Office365 REST API as follows,where {{{user2email}}} is the user you want the event to be created as (Account B's email address):
https://outlook.office365.com/api/v1.0/users/{{{user2email}}}/calendar
This should return Account B's user's calendar ID.
2) Pass in your JSON - the following is an example of what I used during unit testing:
{
"Subject": "Test - Created using Office365 Calendar REST API should be from Technology Notice",
"IsOrganizer": "False",
"Body": {
"ContentType": "HTML",
"Content": "This is where body copy goes HTML supported"
},
"Start": "2015-12-11T19:00:00Z",
"End": "2015-12-11T20:00:00Z",
"Attendees": [
{
"EmailAddress": {
"Address": "attendee1#yourcompany.com",
"Name": "Attendee One"
},
"Type": "Required"
}
],
"Organizer": {
"EmailAddress": {
"Address": "tnotice#yourcompany.com",
"Name": "Technology Notice"
}
}
}
'Technology Notice' will be who the calendar invite is from.
3) Use the ID from step 2 in your POST request, for example:
https://outlook.office365.com/api/v1.0/users/{{{user2email}}}/calendars/{{{ID}}}/events
Note: Make sure you're sending the POST request as the authenticated user account (Account A) who's account the mailbox/calendar it actually belongs to.
If everything is right you should be able to send a calendar invite and have it show up as originating from Account B instead of Account A.
Hope this helps someone out.
This is the correct behavior. You cannot create an event on User A's calendar but set the organizer to User B.

Facebook: Link Request's sender to it's recipient?

When using the requests dialog, facebook issues a notification like this:
What I'm looking to achieve is for the user to click the request link shown above and to present a "Random User invited you to..." message on our App.
However, when clicking that link Facebook doesn't seem to pass through the id of "Random User" to the App. The url accessed by the link looks something like:
http://apps.facebook.com/randomcomp/?fb_source=notification&request_ids=350578327437399,350578327437399&ref=notif&app_request_type=user_to_user&notif_t=app_request
which doesn't contain any reference to the user who initiated the request.
From the App's side, there doesn't seem to be a way to get this information from Facebook. Sure, you can get a list of requests, but that list can contain information for many requests, including requests from other users in addition to the one we're interested in, so it's not useful in this case. For example, here's a snapshot of data:
{
"data": [
{
"id": "340083146057323_100003817986566",
"application": {
"name": "Random Competition",
"namespace": "randomcomp",
"id": "350578327437399"
},
"to": {
"name": "Hannah Smith",
"id": "100003817986566"
},
"from": {
"name": "Random User",
"id": "100002286042525"
},
"data": "100002286042525",
"message": "Use the app!",
"created_time": "2012-05-14T13:26:30+0000"
}, {
"id": "358318457550141_100003817986566",
"application": {
"name": "Random Competition",
"namespace": "randomcomp",
"id": "350578327437399"
},
"to": {
"name": "Hannah Smith",
"id": "100003817986566"
},
"from": {
"name": "Jane Young",
"id": "100003771838663"
},
"data": "100002286042525",
"message": "Use the app!",
"created_time": "2012-05-14T10:54:25+0000"
}],
}
}
As you can see, the data is being passed in, but there's still no way to join the click from the link mentioned above (for Random User) to the correct request in the list; the link passes through the ID for both requests, not just the one for Random User, and while the link states "Random User" it doesn't pass through an identifier.
Am I missing something? Is there a mechanism that isn't in the docs that will allow me to pick-up the "Random User" id so I can provide a nice "Random User invited you to..." message in the App when they click through?
Edit:
Turns out that this isn't possible - see my answer.
You can add some data to the request so that when you process the request you can differentiate that from other requests.
The data can be sent with app requests and users requests and the parameter name is "data".
For example, in the guide for the Requests Dialog you can see it in the properties table at the (almost) end of the document, it says:
Optional, additional data you may pass for tracking. This will be
stored as part of the request objects created. The maximum length is
255 characters
There's also some info about it in the Social Channels documentation, and a sample of (php) usage in the official blog post about Upgrade to Requests 2.0.
I hope that this is what you're looking for.
Edit
When you send the request you know who is sending it right? It's the logged in user, and so you can put the user id/name/etc in the data parameter of the request.
Then, when someone clicks on a request, get the request by the id that facebook passes to you, and from the data extract the user id of the sender.
As the documentation states, you have 255 characters to use, and with that you can do what ever you want, you can even serialize an object to that parameter and deserialize it later.
As it turns out, this is in fact not possible at all.
The link, as shown in the image below, can present multiple users:
which is why multiple request IDs are passed in, and the sender's ID isn't.