Twilio API not receiving current location via WhatsApp channel - location

I am currently building a bot using Twilio's WhatsApp integration with Twilio Studio. I need users to be able to share their current location with the bot, but found that if I send a location through WhatsApp, the body of the message that is sent to Twilio Studio is blank. I have tested other scenarios, such as sending a textual message, images, etc. and it all works fine, except when sharing location messages.
Does anyone know if WhatsApp location messages are currently not supported by Twilio?
Below is an example of the trigger message that is received by Twilio Studio whenever I send my current location through WhatsApp.
Thanks!
{
"contact": {
"channel": {
"address": "whatsapp:+34..."
}
},
"trigger": {
"message": {
"ApiVersion": "2010-04-01",
"SmsSid": "SM32631478ffaaf810cf5976df7586708f",
"SmsStatus": "received",
"SmsMessageSid": "SM32631478ffaaf810cf5976df7586708f",
"NumSegments": "1",
"From": "whatsapp:+34...",
"To": "whatsapp:+1...",
"MessageSid": "SM32631478ffaaf810cf5976df7586708f",
"Body": "",
"AccountSid": "ACc66461614830932cb12fdc6ab9d1d0a7",
"NumMedia": "0"
}
},
"widgets": {},
"flow": {
"flow_sid": "FWf8aae0f75a993b4a497aa6a569a54114",
"channel": {
"address": "whatsapp:+1..."
},
"sid": "FN522a44cadf024dc69d055c6690244db0"
}
}

If a location is present in your whatsApp text you can fetch it the same way you fetch your body
if (req.body.Latitude && req.body.Longitude) {
console.log('Whatsapp location received...');
console.log(req.body.Latitude + ', ' + req.body.Longitude);
}

I have just received an answer from Twilio that clarifies this is not something that Twilio supports at this stage. They do not currently have any ETA for when this feature will be available.

Related

Teams is not displaying my unfurl response

I have a Teams integration with link unfurling set up. I have the messaging endpoint pointed to a public ngrok URL and ngrok proxying a local node.js server that returns the example payload Microsoft has in it's documentation.
This is my endpoint (express.js):
app.post('/bot-test', (req, res) => {
res.send({
"composeExtension": {
"type": "result",
"attachmentLayout": "list",
"attachments": [
{
"contentType": "application/vnd.microsoft.teams.card.o365connector",
"content": {
"sections": [
{
"activityTitle": "[85069]: Create a cool app",
"activityImage": "https://placekitten.com/200/200"
},
{
"title": "Details",
"facts": [
{
"name": "Assigned to:",
"value": "[Larry Brown](mailto:larryb#example.com)"
},
{
"name": "State:",
"value": "Active"
}
]
}
]
}
}
]
}
});
});
When I post a URL in a message in Teams, I see it POST to that endpoint and it responds without errors, but nothing shows up in Teams. What's going wrong? I can't find any logs on Microsoft's side either. I would expect that Teams renders a card with the response payload.
Office 365 Connector cards are not supported for link unfurls ("Message extension previews" in MS parlance). Changing the response to a supported card type worked. Unfortunately, MS doesn't surface this problem anywhere and it just silently discards the response. I was able to find a somewhat useful error description by inspecting the network request that went out from the Teams web client, however.
See this for supported card types: https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference

Cannot send messages in other channels except General msbot for teams (nodejs)

I have created a bot for teams and added it to a channel (testChannel1) as a tab (using a configuration page). I have received a ConversationUpdate event to my server. When I try to send message using the context object that I have received in ConversationUpdate event the message was sent in General channel instead of testChannel1. I have added my bot to testChannel1 but I dont know why the message is sent in General. I am also not able to get the channels list using that context object it is throwing error Error: This method is only valid within the scope of a MS Teams Team..
contextActivityObject :- {
"membersAdded": [
{
"id": "28:[guid]"
}
],
"type": "conversationUpdate",
"timestamp": "2020-04-24T12:00:06.7125247Z",
"id": "f:[guid]",
"channelId": "msteams",
"serviceUrl": "https://smba.trafficmanager.net/in/",
"from": {
"id": "29:[id]",
"aadObjectId": "[guid]"
},
"conversation": {
"isGroup": true,
"conversationType": "channel",
"tenantId": "[guid]",
"id": "19:aba[id]#thread.tacv2"
},
"recipient": {
"id": "28:[guid]",
"name": "teststandups"
},
"channelData": {
"team": {
"aadGroupId": "[guid]",
"name": "nikhilp",
"id": "19:aba[id]#thread.tacv2"
},
"eventType": "teamMemberAdded",
"tenant": {
"id": "[guid]"
}
}
}
The scope I have provided for my bot is Team
I would be thankful for any help
So you've asked a couple of questions, I'll try answer as best as possible. Basically, that Conversation ID (19:aba[id]#thread.tacv2) is unique per channel, so if you're using the "General" channel one, it will for sure go into General.
To find out how to get the channel Ids, have a look at Get the list of channels in a team. That will show you -how- to get the info, but you need to get a trigger in order to be able to make that call. To do that, the best way is to hook into one of the triggers, like receiving a message from a user, or being added to the team. Included in these set of events, are channels being added and deleted. See more here.

Bot is not responding to #Mention when sending message using Graph API

I have created and deployed a bot in Microsoft Teams. Bot Works properly and responds when user talks to the bot using #Mention (e.g. #mybot) in a channel. I just tried to send message to the bot using graph API call:
https://graph.microsoft.com/beta/teams/{group-id-for-teams}/channels/{channel-id}/messages
Method: POST
Content-type: application/json
Body:
"body": {
"contentType": "html",
"content": "Hello World <at id=\"0\">standupbot</at>"
},
"mentions": [
{
"id": 0,
"mentionText": "StandupBot",
"mentioned": {
"application": {
"id": "[my-bot-id]",
"displayName": "StandupBot",
"applicationIdentityType": "bot"
}
}
}
]
}
The Post request goes well, message is posted in my team and bot gets mentioned. But bot is not responding to the mention. However, if user manually mentions the bot in team then bot responds.
What is wrong here, Am i missing something or is it a bug? Please guide.
P.S: I am using Graph Explorer.

When sending multiple messages using await context.PostAsync(reply), they are sometimes received out of order

When we send messages using the below code using the Directline channel, the messages are sometimes received with their order swapped.
await context.PostAsync(msg1);
await context.PostAsync(msg2);
Expected:
mgs1
msg2
But in some cases, they're coming through as
msg2
msg1
Is there any way to handle and prevent this?
I'm going to write this answer assuming you're using the Directline or REST API for receiving messages. I can update if that's not the case.
This entire answer is based off of the Receive activities from the bot docs as well as doing some testing of the Directline API to confirm.
If you're connected via WebSocket, you should always be receiving the messages in order, provided there isn't some kind of size difference in the messages (like one has an attachment) that requires additional processing.
If you're not, messages are retrieved via a polling interval, meaning that your client likely sends a GET request every 5 or 10 seconds (varies by client) to retrieve all messages that have not already been retrieved.
Upon doing so, the client will receive something like this:
{
"activities": [
{
"type": "message",
"channelId": "directline",
"conversation": {
"id": "abc123"
},
"id": "abc123|0000",
"from": {
"id": "user1"
},
"text": "hello"
},
{
"type": "message",
"channelId": "directline",
"conversation": {
"id": "abc123"
},
"id": "abc123|0001",
"from": {
"id": "bot1"
},
"text": "Nice to see you, user1!"
}
],
"watermark": "0001a-95"
}
My guess is that your client is just running a foreach on the array of activities, which could be displaying them out of order. If you have the client order them by either timestamp or id, it should work.

How can I send mail in office 365 REST API?

I've found the following documentation on how to send email using Office 365 rest API.
This is the example given on the doucmentation:
POST https://outlook.office.com/api/v2.0/me/sendmail
{
"Message": {
"Subject": "Meet for lunch?",
"Body": {
"ContentType": "Text",
"Content": "The new cafeteria is open."
},
"ToRecipients": [
{
"EmailAddress": {
"Address": "garthf#a830edad9050849NDA1.onmicrosoft.com"
}
}
],
"Attachments": [
{
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "menu.txt",
"ContentBytes": "bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}
]
},
"SaveToSentItems": "false"
}
This works fine if the user authorizes the application to act on it's behalf. However, I am using client crednetial to build a daemon application that acts on behalf of all users in the given tenant hence "POST https://outlook.office.com/api/v2.0/me/sendmail" couldn't work because its is referencing the "me" and can't tell which user is sending the email.
I would appericiate if you can help with sample example. FYI: I am using Java but your answer doesn't have to be in Java.
Replace the /me bit of the URL with /users/<userid>. You can not use /me for any API call with a token from client credentials.

Resources