如何在Teams的PVA中通过Bot Framework Composer实现可跳转自适应卡片
解决方案:Adaptive Card 关联 Bot Framework Composer 实现 Teams 中主题跳转
一、修正 Adaptive Card 配置(核心问题:缺少提交标识数据)
你当前的 Adaptive Card 中,Action.Submit 未携带自定义选项标识,导致 Composer 无法识别用户选择;同时重复设置 id: dialog.UserChoice 无实际作用。需要给每个提交按钮添加data字段,传递唯一的选项值,让 Composer 能区分用户选择。
修改后的 Adaptive Card 代码如下:
[import](common.lg) # adaptivecardjson_Main_Menu(Location) - ``` { "type": "AdaptiveCard", "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.5", "body": [ { "type": "Container", "items": [ { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "Employee Handbook", "associatedInputs": "none", "data": { "UserChoice": "Employee Handbook" } } ], "spacing": "Small", "separator": true }, { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "Policy Manual", "associatedInputs": "none", "data": { "UserChoice": "Policy Manual" } } ], "spacing": "Small", "separator": true }, { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "Payroll", "associatedInputs": "none", "data": { "UserChoice": "Payroll" } } ], "spacing": "Small", "separator": true }, { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "Insurance Benefits", "associatedInputs": "none", "data": { "UserChoice": "Insurance Benefits" } } ], "spacing": "Small", "separator": true }, { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "Health Savings Account", "associatedInputs": "none", "data": { "UserChoice": "Health Savings Account" } } ], "spacing": "Small", "separator": true }, { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "401(k)", "associatedInputs": "none", "data": { "UserChoice": "401(k)" } } ], "spacing": "Small", "separator": true }, { "type": "ActionSet", "actions": [ { "type": "Action.Submit", "title": "Other", "associatedInputs": "none", "data": { "UserChoice": "Other" } } ], "spacing": "Small", "separator": true } ] } ] }
二、在 Bot Framework Composer 中配置触发逻辑
添加活动触发:在当前对话框中新建一个活动触发,触发类型选择
MessageActivity,并设置触发条件:turn.activity.value.UserChoice != null该条件用于识别用户点击卡片提交按钮后返回的消息。
绑定变量接收选项值:在对话框的变量面板中,添加字符串类型变量
dialog.UserChoice;然后在触发的步骤里添加设置属性动作,将dialog.UserChoice的值设为:turn.activity.value.UserChoice
三、关联选项与主题跳转
在触发规则下添加分支条件(If/Else),根据dialog.UserChoice的值匹配对应主题跳转:
- 第一个分支条件设为
dialog.UserChoice == "Employee Handbook",添加跳转对话框动作,选择对应的“Employee Handbook”主题对话框。 - 重复上述操作,为每个选项(Policy Manual、Payroll等)配置对应的分支条件和跳转动作。
四、测试验证
- 在 Composer 本地测试机器人,点击卡片选项,确认
dialog.UserChoice能正确接收值,且成功跳转对应主题。 - 发布到 Teams 渠道,验证卡片垂直显示样式和跳转功能正常。
内容的提问来源于stack exchange,提问作者Riiz0
相关产品推荐
相关产品推荐

