首页 > 解决方案 > 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'}"
        }
    }
};

现在点击保存操作按钮,我期待 OnTeamsCardActionInvokeAsync 事件触发,因为我的 Bot 继承自 TeamsActivityHandler。但是该按钮仅触发 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"
    }
  ]
}

标签: c#botframeworkbotsmicrosoft-teamsadaptive-cards

解决方案


要使用自适应卡包含调用操作,请在 msteams 对象中包含数据对象。您能否查看文档以获取更多信息?

示例:自适应卡片 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"
    }
  ]
}
    

推荐阅读