Call Microsoft Graph API from Actionable Message - outlook

I'm trying to send an email using Microsoft Graph API from an action in an actionable message. (So send an email from a button in an email) However I'm always receiving a 401 Error. I tested the graph API in normal setting and the Auth token is valid, but here it seems to work differently.
Is it possible at all to achieve this?
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "ActionSet",
"id": "f8d6ddb5-ed34-e8e4-59ec-73084e885bbb",
"actions": [
{
"type": "Action.Http",
"id": "6a807e29-1023-ed90-713a-94209c847c7b",
"title": "Envoyer",
"url": "https://graph.microsoft.com/v1.0/me/sendMail",
"style": "positive",
"isPrimary": true,
"method": "POST",
"headers": [
{
"name": "Authorization",
"value": "Bearer ..."
},
{
"name": "Content-Type",
"value": "application/json"
}
],
"body": "..."
}
]
}
],
"padding": "None",
"#type": "AdaptiveCard",
"#context": "http://schema.org/extensions"
}
(Edit)
This is how I get the token:
Providers.globalProvider = new TeamsProvider ({
clientId: {my client id},
authPopupUrl: '/auth.html'
});
const token = await Providers.globalProvider.getAccessToken({scopes: ['Mail.Send', 'Mail.ReadWrite']});

Regardless of how you generate the Adaptive Card, you cannot use the Microsoft Graph API from the context of Outlook using Outlook Actionable Messages :
https://github.com/microsoft/AdaptiveCards/issues/5674

Currently teams does not support http card action. Please go through this documentation for supported card actions.

Related

AdaptiveCard with "mailto" Action.OpenUrl no longer works

On Microsoft Teams, we have a bot that sends AdaptiveCard message activities to users through the Microsoft Bot Framework REST API. Sometimes, the AdaptiveCard contains an Action.OpenUrl. With regular links such as https://google.com it works as expected, but since about one month, URL parameters with a mailto url such as mailto:recipient#domain.com no longer work: the message is sent, the button appears but clicking it does not do anything.
Sample request:
POST https://smba.trafficmanager.net/emea/v3/conversations/<conversation_id>/activities
Body:
"recipient": {
"id": "29:1uuzUvFTkcseXZ1Q2wOva1inGkpH1SqbHwqdXjG8MhUa8mkFsdUnvrgn4FnPbX8CwBl_GwDHSQGIlRSPKczwUFg"
},
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "ActionSet",
"actions": [
{
"type": "Action.OpenUrl",
"url": "mailto:antoine.chopin#heyaxel.com",
"title": "TEST"
}
]
}
],
"actions": []
}
}
]
}
Currently openSafeUrlMT does not allow mailto urls. we already have a backlog feature request on this. Concern team is working on this.

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?

Microsoft Teams Connector: HttpPOST on MessageCard returns ODataContentTypeException

We set up a new Microsoft Teams Connector and successfully set the settings to POST cards to the received WebhookUrl.
In the body that we send, we included the option to make HttpPost requests to a defined target URL (using ngrok.io tunnel for development). You can see the sent messageCard below:
{
"#type": "MessageCard",
"#context": "https://schema.org/extensions",
"summary": "Card \"Test card\"",
"themeColor": "0078D7",
"title": "Card created: \"Just another test\"",
"potentialAction": [
{
"#type": "ActionCard",
"name": "Add a comment",
"inputs": [
{
"#type": "TextInput",
"id": "comment",
"isMultiline": true,
"title": "Enter your comment"
}
],
"actions": [
{
"#type": "HttpPOST",
"name": "Ok",
"target": "https://dd846f80.ngrok.io/teamshooks/actions",
"body": "{\"Comment\":\"This is a test\"}",
"headers": [
{
"Content-Type": "application/json"
},
{
"aw-teamid": "00000000-0000-0000-0000-000000000001"
}
]
}
]
}
]
}
The card is displayed correctly in the channel in Microsoft Teams.
When a user clicks on this button, to make a HttpPOST to the specified url, we never receive the request on our side but can see that Microsoft returns the following response to the internal "executeAction" request:
The request was sent on: Fri, 13 Dec 2019 11:09:48 GMT
{
"status": "Failed",
"actionId": "c520b20a-3e04-4e21-b4fd-c3a2f760c533",
"properties":
{
"displayMessage": "<p>Could not complete the requested action. Please try again later.</p>\n",
"errorCode": "ODataContentTypeException"
}
}
The following settings are set-up in the Connectors Developer Dashboard (and in the manifest.json):
"connectors": [
{
"connectorId": "6b2ba9c0-7c0a-4524-9e6d-64f061350aa4",
"scopes": [
"team"
],
"configurationUrl": "https://dd846f80.ngrok.io/msteams/aworkConnector/config.html"
}
]
"validDomains": [
"dd846f80.ngrok.io"
]
Do you want to enable actions on your Connector cards? - Yes
Actions Url: https://dd846f80.ngrok.io/teamshooks/actions
Is there anything we are currently doing wrong or does anyone have an idea on how to solve the returned ODataContentTypeException? We need to receive the request in our backend, in order to integrate Micorsoft Teams into our software.
Upload the manifest.json from an admin account, and add the ngrok url in the valid domains. Microsoft teams have blocked custom connectors from performing actions when uploaded by non admin users

Why are my chatbot refresh cards in Teams not refreshing?

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.)

What is the Json response we should send to microsoft botFramework to route my response to telegram channel

I am sending below response to the service url provided by botFramework request https://telegram.botframework.com/v3/conversations/-263387177/activities/
My intent is that using sendMessage method of telegram I am able to route a text to the telegram channel via microsoft botframework
The http post which I am sending is as below
{
"type": "message",
"locale": "en-Us",
"chat_id":-263387177,
"channelID":"telegram",
"from": {
"id": "GTSFIBot",
"name": "sapeops"
},
"text":"hi , Greetings!",
"replyToId": "1505813737353",
"recipient": {
"id": "DirectLineClient"
},
"conversation": {
"isGroup": true,
"id": "-263387177",
"name": "sapeops group"
},
"channelData": {
"method": "sendMessage",
"parameters": {
"chat_id": -263387177,
"parse_mode": "HTML",
"text": "<B>Greetings! How are you doing?</B>"
},
"chat": {
"id": -263387177,
"title": "sapeops group",
"type": "group",
"all_members_are_administrators": true
}
}
}
I get 502 bad gateway response and a below JSON.
{
"error": {
"code": "ServiceError",
"message": "Telegram API returned a result code indicating non-success"
}
}

Resources