在通知中发送英雄卡或自适应卡

时间:2020-02-29 06:11:00

标签: botframework

我正在尝试发送带有Teams notificationhero card的{​​{1}}。我可以以Adaptive Card的形式发送一条简单的短信。

我不知道如何在notification中将Hero cardAdaptive Card包裹起来,因为Activity仅接受SendToConversationAsync

1 个答案:

答案 0 :(得分:0)

这是您可以用来发送使用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] });

以下是可用于发送英雄卡的代码

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

下面是您可以找到上面的示例的链接。

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