c# - 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"
}
]
}
解决方案
要使用自适应卡包含调用操作,请在 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"
}
]
}
推荐阅读
- python - 如何制作基于命令行的库,例如 pip 或 conda
- c# - Dynamics Crm 插件中的 Interlocked.Increment?
- excel - 使用 VBA 打开单元格的双下划线
- javascript - 如何仅从 mySQL 获取值,以便查询结果不在表内?
- javascript - 使用 jquery 将 div 内容剪切到表体
- hive - 为什么删除功能在 hive shell 中不起作用?
- unity3d - Unity - 动画属性未达到最终值?
- asp.net-mvc - 后退按钮上的间歇性 iframe CORS 错误
- c++ - 将2个字符转换为字符串
- javascript - 如何将十进制转换为十六进制,以便结果是数字而不是字符串?