【问题标题】:Send a hero card or Adaptive card in notification在通知中发送英雄卡或自适应卡
【发布时间】:2020-03-06 13:46:55
【问题描述】:

我正在尝试发送Teams notificationhero cardAdaptive Card。我可以发送一条简单的短信作为notification

我不知道如何将Hero cardAdaptive Card 包装在Activity 中,因为SendToConversationAsync 只接受Activity

【问题讨论】:

标签: botframework


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2020-10-07
    • 2021-09-06
    • 1970-01-01
    • 2019-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    相关资源
    最近更新 更多