You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在点击Adaptive Card的Action.Submit按钮时显示自定义用户消息

解决方案

1. 调整Action.Submit的data结构

使用messageBack类型时,要同时设置text和displayText字段(部分渠道依赖text来显示用户侧消息),并将业务标识放在value对象中:

"actions": [
    {
        "type": "Action.Submit",
        "title": "Tell me more",
        "data": {
            "type": "messageBack",
            "text": "Ok, tell me more please!",
            "displayText": "Ok, tell me more please!",
            "value": {
                "choice": "TELL_ME_MORE"
            }
        }
    }
]
  • text/displayText:控制用户侧聊天窗口显示的消息文本
  • value:传递给Bot的业务逻辑标识(比如TELL_ME_MORE)

2. 在Bot代码中解析提交数据

在TypeScript的Turn处理逻辑里,从activity.value中提取value字段的业务标识,而非直接使用text内容:

async onTurn(context: TurnContext) {
    if (context.activity.type === ActivityTypes.Message) {
        // 处理Adaptive Card提交的数据
        if (context.activity.value) {
            const submitPayload = context.activity.value as {
                type?: string,
                value?: { choice: string }
            };

            if (submitPayload.type === 'messageBack' && submitPayload.value?.choice === 'TELL_ME_MORE') {
                // 执行对应的业务逻辑
                await context.sendActivity("Here's the additional information you asked for.");
            }
        }
    }
}

3. 跨渠道兼容性说明

部分聊天渠道对messageBack字段的支持有差异,若遇到显示问题,可以尝试只保留text字段(部分渠道优先读取text作为用户显示消息)。如果目标渠道支持Action.Execute,也可以用它实现更灵活的交互,但messageBack方案的跨渠道兼容性更好。


内容的提问来源于stack exchange,提问作者Garu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 13:35:24