TeamsActivityHandler OnTeamsCardActionInvokeAsync未在卡片提交操作上触发

问题描述

我有一个简单的自适应卡,其中有几个输入字段和一个带有“提交”操作的“操作”按钮。

var card = new AdaptiveCard("1.0")
{
    Body = new List<AdaptiveElement>()
    {
        new AdaptiveTextBlock()
        {
            Text = "Title",Separator = true
        },new AdaptiveTextBlock()
        {
            Text = "Product Line"
        },new AdaptiveChoiceSetinput()
        {
            Id = "cmbProductLine",Choices = new List<AdaptiveChoice>()
            {
                new AdaptiveChoice() {
                    Title = "Choice 1",Value = "1"},new AdaptiveChoice() {
                    Title = "Choice 2",Value = "2"}
            },Style = AdaptiveChoiceInputStyle.Compact
        },new AdaptiveTextBlock()
        {
            Text = "Organization"
        },new AdaptiveTextinput()
        {
            Id = "txtOrgName",Placeholder = "Name"
        },},Actions = new List<AdaptiveAction>()
    {
        new AdaptiveSubmitaction()
        {
            Title = "Save",DataJson = @"{'Action':'Save'}"
        }
    }
};

现在,单击“保存操作”按钮时,由于我的Bot是从TeamsActivityHandler继承的,因此我希望OnTeamsCardActionInvokeAsync事件触发。但是该按钮仅触发OnMessageActivityAsync事件。这是Bot框架中的错误还是我缺少一些东西?

这是从此代码创建的JSON。

{
  "type": "AdaptiveCard","version": "1.2","body": [
    {
      "type": "TextBlock","text": "Please provide organization details to proceed:","separator": true
    },{
      "type": "TextBlock","text": "Organization"
    },{
      "type": "Input.Text","id": "txtOrgName","placeholder": "Organization Name","style": "email"
    }
  ],"actions": [
    {
      "type": "Action.Submit","data": {
        "Action": "OrgName","msteams": {
          "type": "task/fetch"
        },"data": "Invoke"
      },"title": "Save Configuration"
    },{
      "type": "Action.Submit","data": {
        "Action": "Cancel"
      },"title": "Cancel"
    }
  ]
}

解决方法

要在Adaptive Card中包含Invoke操作,请在msteams对象中包含数据对象。您能否查看this文档以了解更多信息?

示例:自适应卡JSON:

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json","type": "AdaptiveCard","version": "1.2","body": [
    {
      "type": "TextBlock","size": "large","weight": "bolder","text": "Adaptive card"
    }
  ],"actions": [
    {
      "type": "Action.Submit","data": {
        "msteams": {
          "type": "task/fetch"
        },"data": "Invoke"
      },"title": "Invoke"
    }
  ]
}