Forum Discussion
MrZakaz
May 23, 2024Copper Contributor
Calling adaptive card from the channel message level using the button (Message created from Tab).
Hello, I am struggling with one problem, I am adding a message to a channel using a Tab I created, I would like the message to contain a button that would trigger an adaptive card popup. This popup ...
Nivedipa-MSFT
Microsoft
May 23, 2024MrZakaz -
To call an Adaptive Card from the channel message level using a button created from a Tab, you can follow these steps:
- Create an Adaptive Card with a Button:
- You can create an Adaptive Card with a button that, when clicked, will invoke the card. Here is an example of an Adaptive Card with a button:
{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Click the button to invoke the Adaptive Card"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Invoke Adaptive Card",
"data": {
"cardType": "adaptiveCard"
}
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
- Handle the Button Click Event in the Tab:
- In your Tab code, you need to handle the button click event and send a message to the channel with the Adaptive Card. Here is an example of handling the button click event in a Tab using Javascript:
// Handle the button click event
document.getElementById('invokeButton').addEventListener('click', function() {
microsoftTeams.tasks.submitTask({
cardType: 'adaptiveCard'
});
});
- Send a Message with the Adaptive Card from the Tab:
- When the button is clicked, you can use the
microsoftTeams.tasks.submitTaskmethod to send a message with the Adaptive Card to the channel. Here is an example of sending a message with the Adaptive Card:
- When the button is clicked, you can use the
// Send a message with the Adaptive Card
microsoftTeams.tasks.submitTask({
type: 'message',
value: {
text: 'Here is the Adaptive Card:',
attachments: [
{
contentType: 'application/vnd.microsoft.card.adaptive',
content: {
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'
}
}
]
}
});
By following these steps, you can call an Adaptive Card from the channel message level using a button created from a Tab in Microsoft Teams.
Ref Doc: Build Adaptive Card Tabs - Teams | Microsoft Learn
Thanks,
Nivedipa
------------------------------------------------------------------------------------------
If the response is helpful, please click "**Mark as Best Response**" and like it. You can share your feedback via Microsoft Teams Developer Feedback link. Click here to escalate.