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

Bot Framework SDK:JavaScript版onAdaptiveCardInvoke方法在模拟器中未触发

解决Adaptive Card Invoke在Bot Framework Emulator不触发的问题
  • 更新Bot Framework Emulator到最新版本
    旧版本Emulator对Adaptive Card的Action.Execute支持不完善,直接安装最新版可解决大部分基础兼容性问题。

  • 确认Adaptive Card的Action配置正确
    必须使用Action.Execute类型,而非Action.Submit或其他类型,示例Card结构如下:

    {
      "type": "AdaptiveCard",
      "version": "1.4",
      "actions": [
        {
          "type": "Action.Execute",
          "title": "触发Invoke",
          "data": {
            "action": "myCustomAction"
          }
        }
      ]
    }
    

    注意Card版本至少为1.0,Action.Execute是触发onAdaptiveCardInvoke的核心配置。

  • 确保Bot代码正确处理Invoke请求
    若使用Bot Framework SDK v4,需在Bot类中正确重写OnAdaptiveCardInvokeAsync方法,或在OnTurnAsync中判断Activity类型为Invoke并处理:

    protected override async Task<AdaptiveCardInvokeResponse> OnAdaptiveCardInvokeAsync(ITurnContext<IInvokeActivity> turnContext, AdaptiveCardInvokeValue invokeValue, CancellationToken cancellationToken)
    {
        // 业务逻辑处理
        return new AdaptiveCardInvokeResponse()
        {
            StatusCode = 200,
            Type = "application/vnd.microsoft.card.adaptive",
            Value = new AdaptiveCardInvokeResponseValue()
            {
                // 返回响应内容
            }
        };
    }
    

    若是JavaScript/TypeScript,需注册Adaptive Card的invoke处理:

    this.onAdaptiveCardInvoke(async (context, invokeValue) => {
        // 业务逻辑处理
        return {
            statusCode: 200,
            type: 'application/vnd.microsoft.card.adaptive',
            value: {}
        };
    });
    
  • 在Emulator中启用Teams仿真环境
    打开Emulator的「Settings」面板,找到「Teams Emulation」选项,勾选「Enable Teams Emulation」后重启Emulator,模拟Teams环境的请求处理逻辑。

  • 通过Emulator日志排查问题
    在Emulator的「Log」标签页,查看Invoke请求是否发送成功、是否返回错误状态码(如400、404)。若请求未发送,检查Card配置;若返回错误,根据信息调整代码或配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 00:22:09