AdaptiveCards中的动态ChoiceSet:向Teams用户发布AdaptiveCard并等待响应”
创始人
2024-05-24 00:57:30
0

Adaptive Cards 是一种用于呈现有关数据的交互式卡片的开放式规范。在 Adaptive Cards 中,ChoiceSet 是一组预定义选项,用户可以从中选择一个或多个选项。有时,我们需要动态添加 ChoiceSet 中的选项并等待用户响应。

以下是向 Teams 用户发布 Adaptive Card 并等待响应的代码示例,其中包括动态 ChoiceSet:

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

class MyBot extends TeamsActivityHandler {
    async onMessageActivity(turnContext) {
        if (turnContext.activity.value) {
            // A response to the previous message was received
            console.log(turnContext.activity.value);

            // Generate a new card with updated options
            const updatedCard = {
                $schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
                type: 'AdaptiveCard',
                version: '1.0',
                body: [
                    {
                        type: 'TextBlock',
                        text: 'Please select an option:',
                        wrap: true
                    },
                    {
                        type: 'Input.ChoiceSet',
                        id: 'myChoice',
                        style: 'compact',
                        spacing: 'none',
                        choices: [
                            { title: 'Option 1', value: '1' },
                            { title: 'Option 2', value: '2' },
                            { title: 'Option 3', value: '3' }
                        ]
                    }
                ],
                actions: [
                    {
                        type: 'Action.Submit',
                        title: 'Submit',
                        data: { type: 'myChoice' }
                    }
                ]
            };

            // Send the updated card to the user
            await turnContext.sendActivity(MessageFactory.attachment(CardFactory.adaptiveCard(updatedCard)));

        } else {
            // Send the initial card to the user
            const card = {
                $schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
                type: 'AdaptiveCard',
                version: '1.0',
                body: [
                    {
                        type: 'TextBlock',
                        text: 'Please select an option:',
                        wrap: true
                    },
                    {
                        type: 'Input.ChoiceSet',
                        id: 'myChoice',
                        style: 'compact',
                        spacing: 'none',
                        choices: [
                            { title: 'Option 1', value: '1' }
                        ]
                    }
                ],
                actions: [
                    {
                        type: 'Action.Submit',
                        title: 'Submit',
                        data: { type: 'myChoice' }
                    }
                ]

相关内容

热门资讯

玻璃硬盘原理图 玻璃硬盘原理 玻璃硬盘,又称为磁头悬浮硬盘(Magnetic Head Flying Disk,MHFD),是一种...
Proton Mail 匿名注... 在数字监控无处不在的今天,你的邮箱可能比你想象的更「透明」——主流邮箱服务商在注册时就要求手机号验证...
闲鱼搜索规则与技巧 闲鱼最新特... 在闲鱼这个二手交易平台上,有很多用户都希望能够找到一些特殊的东西,比如一些罕见的收藏品、独特的手工艺...
家里监控最长能保存多少天的记录... 家里监控一般保存多久 随着科技的发展,家庭监控系统已经成为了许多家庭的必备设备,它不仅可以帮助我们...
华为tag有用吗 华为tag-... 华为Tag是华为手机中的一种功能,它可以帮助用户更好地管理自己的手机数据和应用,通过使用华为Tag,...
ps5手柄可用手机快充充电吗 ... PS5手柄,即PlayStation 5的DualSense手柄,是索尼公司为PlayStation...
QQ音乐提示代理模式可能无法正... QQ音乐提示代理模式可能无法正常访问,如上图所示,是怎么回事呢? 这个可能和你的网络设置有关系,首先...
收到微信有提示音怎么去掉 微信... 微信收到信息没有提示音,可能是由多种原因导致的,以下是一些可能的原因及解决方法: 1. 手机静音或...
a100显卡对应的cuda版本 在进行GPU加速的编程中,CUDA是常用的架构和平台,其版本和显卡型号之间存在着一定的对应关系。本篇...
网站服务器不稳定怎么解决 外网... 服务器稳定性是任何在线业务的关键,无论是网站、应用还是其他在线服务,有时候,即使我们尽了最大的努力,...