Send a hero card or Adaptive card in notification

Viewed 930

I am trying to send a Teams notification with a hero card or an Adaptive Card. I can send a simple text message as a notification.

I don't know how to wrap a Hero card or an Adaptive Card in an Activity as SendToConversationAsync only accepts an Activity.

1 Answers

Here is the code which you can use to send any card created using the adaptivecard.io

const resultOutputCard = {
                "type": "AdaptiveCard",
                "version": "1.0",
                "body": [
                     {  
                       "type" : "TextBlock",
                       "text" : "Sample Text"
                     }
                ],
                "actions": [
                   {
                    "type": "Action.OpenUrl",
                    "title": "Google Link",
                    "url": "www.google.com"
                   }
                ],
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
            };
            const card = CardFactory.adaptiveCard(resultOutputCard);
            await step.context.sendActivity({ attachments: [card] });

Below is the code which you can use to send hero card

const { MessageFactory, CardFactory } = require('botbuilder');

const card = CardFactory.heroCard(
     'White T-Shirt',
     ['https://example.com/whiteShirt.jpg'],
     ['buy']
);
const message = MessageFactory.attachment(card);
await context.sendActivity(message);

Below is the link where you can find the above example.

https://docs.microsoft.com/en-us/javascript/api/botbuilder-core/cardfactory?view=botbuilder-ts-latest

Related