Created
November 3, 2020 15:22
-
-
Save dardourimohamed/293237cb04259a08a5e2a799967770b6 to your computer and use it in GitHub Desktop.
Send Adaptive card to MS Teams channel using REST JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
/* | |
1- In Microsoft Teams, choose More options (⋯) next to the channel name and then choose Connectors. | |
2- Scroll through the list of Connectors to Incoming Webhook, and choose Add. | |
3- Enter a name for the webhook, upload an image to associate with data from the webhook, and choose Create. | |
4- Replace the webhook URL into this variable. | |
*/ | |
const webhookURL = "https://outlook.office.com/webhook/XXXXX...XXXXX/IncomingWebhook/XXXXX...XXXXX"; | |
// this card can be created via https://amdesigner.azurewebsites.net/ then replace the JSON payload into this variable. | |
const card = { | |
"type": "AdaptiveCard", | |
"body": [ | |
{ | |
"type": "TextBlock", | |
"id": "8e071ee0-9f3a-1b27-dc92-b6b424b564c2", | |
"text": "Hello World", | |
"wrap": true | |
} | |
], | |
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json", | |
"version": "1.0", | |
"padding": "None" | |
}; | |
(async () => { | |
try { | |
const res = await axios.post(webhookURL, { | |
"type": "message", | |
"attachments": [ | |
{ | |
"contentType": "application/vnd.microsoft.card.adaptive", | |
"contentUrl": null, | |
"content": card | |
} | |
] | |
}); | |
console.log(res.status, res.statusText, res.data); | |
} catch (error) { | |
console.error(error.response.status, error.response.statusText, error.response.data); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment