Why are my chatbot refresh cards in Teams not refreshing? - botframework

I am serving out O365 connector cards to my teams channel in my chatbot, for the user to use an HttpPost action to send data back to the bot.
Here is a sample invoke message when the user saves:
{
"name": "actionableMessage/executeAction",
"type": "invoke",
"timestamp": "2018-06-16T20:58:24.388Z",
"localTimestamp": "2018-06-16T21:58:24.388+01:00",
"id": "snip",
"channelId": "msteams",
"serviceUrl": "https://smba.trafficmanager.net/emea-client-ss.msg/",
"from": {
"id": "snip",
"name": "my name",
"aadObjectId": "snip"
},
"conversation": {
"conversationType": "personal",
"id": "long conversation id"
},
"recipient": {
"id": "bot id",
"name": "bot name"
},
"entities": [
{
"locale": "en-US",
"country": "US",
"platform": "Web",
"type": "clientInfo"
}
],
"channelData": {
"tenant": {
"id": "tenant id"
},
"source": {
"name": "message"
}
},
"replyToId": "message id",
"value": {
"body": "{\"sportType\":\"1\", \"tournamentName\":\"FIFA Soccer World Cup\",\"startTime\":\"2018-06-14T03: 00: 00.000Z\", \"endTime\":\"2018-07-16T07: 30: 00.000Z\", \"timeZone\":\"Russian Standard Time\", \"tournamentId\": \"1\"}",
"actionId": "SaveTournament"
}
}
In response to a save card, I am returning an ActionCard in the response body, and I am including an HTTP header "CARD-UPDATE-IN-BODY" with a value "true". Here is a sample response message:
{
"#type": "ActionCard",
"inputs": [
{
"#type": "TextInput",
"isMultiline": true,
"maxLength": 500.0,
"id": "SaveStatus",
"isRequired": false,
"title": "Save Status",
"value": "You updated the tournament FIFA Soccer World Cup running from 6/14/2018 to 7/16/2018 in timezone Russian Standard Time"
}
],
"actions": [
{
"#type": "HttpPOST",
"body": "{\"tournamentId\": \"1\"}",
"name": "Update FIFA Soccer World Cup again",
"#id": "UpdateTournament#1"
}
],
"name": "Save Tournament",
"#id": "SaveTournament"
}
I have traced this in my web app so I know that is what is being returned to the bot framework middleware.
In my teams app in the browser,when I trace the response message with Fiddler, the card invoke response is not getting the refresh card I send, it is just getting a generic 200 response with an empty response body. Can anyone point me to a demo of refresh cards that work with Teams, or tell me what's wrong with my messages?

Teams doesn't support updating the original card by responding to the invoke message. Instead, you need to explicitly update the message by calling the Bot Framework API (see https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bot-conversations/bots-conversations#updating-messages).
The incoming invoke message has the information you need to update the original message:
<serviceurl>/v3/conversations/<conversationid>/activities/<activityid>
<serviceurl>: serviceUrl
<conversationid>: conversation.id
<activityid>: replyToId
(The details of how to update a message depends on exactly which SDK you're using, but in the end you'll need those 3 items to refer to the message.)

Related

Microsoft Teams bot: Card including Action.OpenUrl with task deeplink

For our bot in Teams, using the Microsoft Bot Framework, I want the bot to send a card with a button that, when clicked, will open a task module through a deep link
Deep link:
https://teams.microsoft.com/l/task/<BOT_ID>?fallbackUrl=https://google.com&completionBotId=<BOT_ID>&height=large&width=large&title=Title&card=<card>
Where <card> comes from the example in the docs:
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Here is a ninja cat:"
},
{
"type": "Image",
"url": "http://adaptivecards.io/content/cats/1.png",
"size": "Medium"
}
],
"version": "1.0"
}
URL encode the JSON to: %7B%0A%20%20%20%20%22type%22%3A%20%22AdaptiveCard%22%2C%0A%20%20%20%20%22body%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22TextBlock%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%3A%20%22Here%20is%20a%20ninja%20cat%3A%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22Image%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22url%22%3A%20%22http%3A%2F%2Fadaptivecards.io%2Fcontent%2Fcats%2F1.png%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22size%22%3A%20%22Medium%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%5D%2C%0A%20%20%20%20%22version%22%3A%20%221.0%22%0A%7D
We then have deep link:
https://teams.microsoft.com/l/task/<BOT_ID>?fallbackUrl=https://google.com&completionBotId=<BOT_ID>&height=large&width=large&title=Title&card=%7B%0A%20%20%20%20%22type%22%3A%20%22AdaptiveCard%22%2C%0A%20%20%20%20%22body%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22TextBlock%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%3A%20%22Here%20is%20a%20ninja%20cat%3A%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22Image%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22url%22%3A%20%22http%3A%2F%2Fadaptivecards.io%2Fcontent%2Fcats%2F1.png%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22size%22%3A%20%22Medium%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%5D%2C%0A%20%20%20%20%22version%22%3A%20%221.0%22%0A%7D
Finally, send message through Bot Framework API:
POST https://smba.trafficmanager.net/emea/v3/conversations/<conv_id>/activities
Body:
{
"recipient": {
"id": "29:1uuzUvFTkcseXZ1Q2wOva1inGkpH1SqbHwqdXjG8MhUa8mkFsdUnvrgn4FnPbX8CwBl_GwDHSQGIlRSPKczwUFg"
},
"type": "message",
"text": "Hi 👋<br/><br/>What do you need?",
"textFormat": "xml",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content" : {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"actions": [{
"type": "Action.OpenUrl",
"title": "Display task",
"url": "https://teams.microsoft.com/l/task/<BOT_ID>?fallbackUrl=https://google.com&completionBotId=<BOT_ID>&height=large&width=large&title=Title&card=%7B%0A%20%20%20%20%22type%22%3A%20%22AdaptiveCard%22%2C%0A%20%20%20%20%22body%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22TextBlock%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22text%22%3A%20%22Here%20is%20a%20ninja%20cat%3A%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22type%22%3A%20%22Image%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22url%22%3A%20%22http%3A%2F%2Fadaptivecards.io%2Fcontent%2Fcats%2F1.png%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22size%22%3A%20%22Medium%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%5D%2C%0A%20%20%20%20%22version%22%3A%20%221.0%22%0A%7D"
}],
"body": []}}]}
The message appears in Teams as expected, but when clicking the button nothing happens. What am I doing wrong?
The issue was that I was sending my bot id instead of my app id for the APP_ID parameter.
I don't understand this in the docs though:
Note that it's valid for APP_ID and BOT_APP_ID to be the same, and in many cases will be if an app has a bot since it's recommended to use that as an app's ID if there is one.
How is one supposed to achieve this?

Input value substitution not working for message cards in MS Teams

I'm doing a HttpPost from a message card with some user input fields. The message card is sent to MS teams and contains a Http Post action to another target which receives the user's selected inputs. I'm sending User's data in body of the Http Post. Input value substitution works fine in MS teams desktop but not working in MS teams android. Any suggestions are highly appreciated.
Snippet with httpPost:
{
"#type": "ActionCard",
"actions": [
{
"#type": "HttpPOST",
"body": "{\"Comment\":\"{{Comment.value}}\",\"Choice1\" : \"{{1c.value}}\",\"Choice2\" : \"{{2c.value}}\"}",
"name": "Submit Edit",
"target": "https://.."
}
],
"inputs": [
{
"#type": "TextInput",
"id": "Comment",
"isMultiline": true,
"isRequired": true,
"title": "Comment"
},
{
"#type": "TextInput",
"id": "1c",
"title": "Choice 1"
},
{
"#type": "TextInput",
"id": "2c",
"title": "Choice 2"
}
],
"name": "Edit"
}
]
}
Body received from MS teams android:
"body": {
"Comment": "{{Comment.value}}",
"Choice1": "{{1c.value}}",
"Choice2": "{{2c.value}}"
}
Body received from MS teams desktop:
"body": {
"Comment": "Test",
"Choice1": "Myinput",
"Choice2": "Myinput"
}

Make POST call with HttpPOST Action form Teams message

I have a MessageCard which I am sending to my Teams channel via the Incoming Webhook connector. This is working well. However, the card has the button with HttpPOST Action. In "target" I defined URL to my API in the format: "http://user:pass#address/resource/action.html?add2Queue=test". When I am trying to push button I am getting the error: "Target URL scheme 'http://user:pass#address/resource/action.html?add2Queue=test' is not allowed.". I didn't find any restrictions for using HTTP. I am using the "Incoming Webhook" connector.
Is it works with HTTP or only HTTPS?
JSON:
{
"#type": "MessageCard",
"#context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "Action on environments status change",
"sections": [{
"activityTitle": "Envrionments status are going to change",
"facts": [{
"name": "Environment:",
"value": "3"
}, {
"name": "Due date",
"value": "On Friday 8:00 PM Central Time"
}, {
"name": "Pending Action",
"value": "Environment are going to be stopped"
}, {
"name": "Notes",
"value": "You can pause this action by pressing Pause button bellow"
}],
"markdown": true
}],
"potentialAction": [{
"#type": "HttpPOST",
"name": "Pause Action",
"actions": [{
"#type": "HttpPOST",
"name": "Pause",
"target": "http://user:pass#server/teamcity/httpAuth/action.html?add2Queue=Marlin_Infrastructure_MarlinInfrastructureStopStartEnvironments_TechnicalTasks_N"
}]
}]
}
Explanation of Teams sending a bearer authorization token can be found here
Based on that I did:
"#type": "HttpPOST",
"name": "Your Action",
"target": "https://www.your-url.com",
"headers": [
{
"name": "Authorization",
"value": null
}
],
"body": "{\"whateverdata\"}"
and it worked for me. Works on Teams , I imagine it should work for outlook as well

Posting to Microsoft bot telegram channel return error 400

When I post a message to my Microsoft bot using Postman, the message is sent to my Skype. When I post the message to Telegram channel, I get error message 400 Bad Request (The request cannot be fulfilled due to bad syntax. The following is post body.
{
"type": "message",
"locale": "en-Us",
"channelID":"telegram",
"from": {
"id": "28:01a4752e-6cb0-459f-b94f-.....",
"name": "bot"
},
"recipient": {
"id": "29:1rNJPaNGCMPithEDVjoN00SU5S6fG......",
"name": "My name"
},
"conversation": {
"id": "29:1rNJPaNGCMPithEDVjoN00SU5S6fGZ"
},
"channelData":
{
"method": "sendMessage",
"parameters":
{
"text": "This message is HTMLformatted.",
"parse_mode": "HTML"
}
}
}

Skype Bot Rest API Conversation ID

So I used an account and message my skype bot.
I get this json response on my endpoint url. I sent a text "add"
{"text":"add"
,"type":"message"
,"timestamp":"2017-01-13T15:38:32.242Z"
,"id":"1234567"
,"channelId":"skype"
,"serviceUrl":"https:\/\/smba.trafficmanager.net\/apis\/"
,"from":{"id":"29:yyyy","name":"Real Person"}
,"conversation":{"id":"29:yyyy"}
,"recipient":{"id":"28:xxxx","name":"Skype Test"}
}
When I return a reponse to this url using yyyy as conversationId
POST /v3/directline/conversations/{conversationId}/activities
https://directline.botframework.com/v3/directline/conversations/yyyy/activities
with this parameter:
{
"type": "message",
"text": "registration",
"from": {
"id":"xxxx","name":"Skype Test"
},
"recipient": {"id":"yyyy","name":"Real Person"}
}
I get an unknown conversation response. Not sure what is wrong.
Your Response should look like:
{
"type": "message",
"from": {
"id": "recipient_id",
"name": "recipient_name"
},
"conversation": {
"id": "conversation_id",
"name": "conversation_name(if available)"
},
"recipient": {
"id": "from_id",
"name": "from_name"
},
"text": "response_text",
"replyToId": "activity_id"
}
Hope that Help :)

Resources