使用传出 Webhook 在 MSTeams 中提交自适应卡片
Submit Adaptive Cards in MSTeams with Outgoing Webhook
我正在关注 Add Outgoing Webhooks 以显示带有文本提示的自适应卡片:
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.3",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": " Input.Text elements",
"horizontalAlignment": "Center",
"wrap": true
},
{
"type": "TextBlock",
"text": "Comments",
"wrap": true
},
{
"type": "Input.Text",
"isMultiline": true,
"id": "MultiLineVal"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit",
"data": {
"id": "1234567890"
}
},
{
"type": "Action.ShowCard",
"title": "Show Card",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Enter comment",
"wrap": true
},
{
"type": "Input.Text",
"id": "CommentVal"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
}
]
}
}
]
}
卡片 json 是从 https://adaptivecards.io/designer/
上的标准输入模板生成的
bot 配置为 https://teamsbot.free.beeceptor.com/test4 作为传出 webhook:
向机器人发送消息有效,我在 https://beeceptor.com/console/teamsbot 上看到了请求,它 returns 模拟并且我在团队中显示了卡片。
当我点击“提交”时,出现 Something went wrong. Please try again.
错误:
beeceptor 上没有新请求,我在 chrome devtools 中看到连续 2 个 400 错误:
curl 'https://uk.ng.msg.teams.microsoft.com/v1/agents/f9f5e125-xxxx-xxxx-xxxx-9a9a8dcb1824/invoke' \
-H 'authority: uk.ng.msg.teams.microsoft.com' \
... many irrelevant headers ...
-H 'accept: json' \
-H 'x-ms-client-version: 1415/1.0.0.2022020411' \
-H 'x-ms-user-type: null' \
-H 'authentication: skypetoken=eyJhbGciOiJSUzI...very long token ... zZy_S4a0zp8m_a72SMuew' \
-H 'origin: https://teams.microsoft.com' \
-H 'referer: https://teams.microsoft.com/' \
--data-raw '{"value":{"id":"1234567890"},"conversation":{"id":"19:F32YIP...long id...@thread.tacv2;messageid=1644066509347"},"clientMessageId":"3673456194497933931","serverMessageId":"1644067693444","messageType":"RichText/Media_Card","name":"messageback","imdisplayname":"Azure Admin","complianceData":{"action":{"type":"Action.Submit","title":"Submit"}}}'
结果为 400 响应,正文如下:
{"errorCode":201,"message":"The resource URL agentMri is misformatted."}
请求后跟一个非常相似的请求:
curl 'https://uk.ng.msg.teams.microsoft.com/v1/agents/f9f5e125-xxxx-xxxx-xxxx-9a9a8dcb1824/invoke' \
-H 'authority: uk.ng.msg.teams.microsoft.com' \
... same irrelevant headers ...
-H 'accept: json' \
-H 'x-ms-client-version: 1415/1.0.0.2022020411' \
-H 'x-ms-user-type: null' \
-H 'authentication: skypetoken=eyJhbGciOiJSUz ... same token ...tzZy_S4a0zp8m_a72SMuew' \
-H 'origin: https://teams.microsoft.com' \
-H 'referer: https://teams.microsoft.com/' \
--data-raw '{"value":{"id":"1234567890","MultiLineVal":"My comment"},"conversation":{"id":"19:F32YIP...same id..1@thread.tacv2;messageid=1644066509347"},"clientMessageId":"3673456194497933931","serverMessageId":"1644067693444","messageType":"RichText/Media_Card","name":"messageback","imdisplayname":"Azure Admin","complianceData":{"action":{"type":"Action.Submit","title":"Submit"}}}'
响应相同 400:
{"errorCode":201,"message":"The resource URL agentMri is misformatted."}
我能发现的唯一区别是 --data-raw '{"value":{"id":"1234567890","MultiLineVal":"My comment"},"
部分。第二个请求有 "MultiLineVal":"My comment"
。这正是我希望在蜂感受器方面看到的,但它从未达到 API.
不太清楚什么是 agentMri
、格式错误的位置和方式,以及在自适应卡中更改什么以使表单提交到相同的 webhook 域。我不确定这个 agentMri“格式错误”是否相关,但这是来自 Teams 的唯一包含我在自适应卡中输入的字符串的 http 请求。
传出 Webhook 不能使用除 openURL 之外的任何卡片操作。
文档参考:Key features of Outgoing Webhook:
Standard HTTP message exchange
Responses appear in the same chain as the original request message and can include any Bot Framework message content. For example, rich text, images, cards, and emojis. Although Outgoing Webhooks can use cards, they can't use any card actions except for openURL.
我正在关注 Add Outgoing Webhooks 以显示带有文本提示的自适应卡片:
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.3",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": " Input.Text elements",
"horizontalAlignment": "Center",
"wrap": true
},
{
"type": "TextBlock",
"text": "Comments",
"wrap": true
},
{
"type": "Input.Text",
"isMultiline": true,
"id": "MultiLineVal"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit",
"data": {
"id": "1234567890"
}
},
{
"type": "Action.ShowCard",
"title": "Show Card",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Enter comment",
"wrap": true
},
{
"type": "Input.Text",
"id": "CommentVal"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK"
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
}
}
]
}
}
]
}
卡片 json 是从 https://adaptivecards.io/designer/
上的标准输入模板生成的bot 配置为 https://teamsbot.free.beeceptor.com/test4 作为传出 webhook:
向机器人发送消息有效,我在 https://beeceptor.com/console/teamsbot 上看到了请求,它 returns 模拟并且我在团队中显示了卡片。
当我点击“提交”时,出现 Something went wrong. Please try again.
错误:
beeceptor 上没有新请求,我在 chrome devtools 中看到连续 2 个 400 错误:
curl 'https://uk.ng.msg.teams.microsoft.com/v1/agents/f9f5e125-xxxx-xxxx-xxxx-9a9a8dcb1824/invoke' \
-H 'authority: uk.ng.msg.teams.microsoft.com' \
... many irrelevant headers ...
-H 'accept: json' \
-H 'x-ms-client-version: 1415/1.0.0.2022020411' \
-H 'x-ms-user-type: null' \
-H 'authentication: skypetoken=eyJhbGciOiJSUzI...very long token ... zZy_S4a0zp8m_a72SMuew' \
-H 'origin: https://teams.microsoft.com' \
-H 'referer: https://teams.microsoft.com/' \
--data-raw '{"value":{"id":"1234567890"},"conversation":{"id":"19:F32YIP...long id...@thread.tacv2;messageid=1644066509347"},"clientMessageId":"3673456194497933931","serverMessageId":"1644067693444","messageType":"RichText/Media_Card","name":"messageback","imdisplayname":"Azure Admin","complianceData":{"action":{"type":"Action.Submit","title":"Submit"}}}'
结果为 400 响应,正文如下:
{"errorCode":201,"message":"The resource URL agentMri is misformatted."}
请求后跟一个非常相似的请求:
curl 'https://uk.ng.msg.teams.microsoft.com/v1/agents/f9f5e125-xxxx-xxxx-xxxx-9a9a8dcb1824/invoke' \
-H 'authority: uk.ng.msg.teams.microsoft.com' \
... same irrelevant headers ...
-H 'accept: json' \
-H 'x-ms-client-version: 1415/1.0.0.2022020411' \
-H 'x-ms-user-type: null' \
-H 'authentication: skypetoken=eyJhbGciOiJSUz ... same token ...tzZy_S4a0zp8m_a72SMuew' \
-H 'origin: https://teams.microsoft.com' \
-H 'referer: https://teams.microsoft.com/' \
--data-raw '{"value":{"id":"1234567890","MultiLineVal":"My comment"},"conversation":{"id":"19:F32YIP...same id..1@thread.tacv2;messageid=1644066509347"},"clientMessageId":"3673456194497933931","serverMessageId":"1644067693444","messageType":"RichText/Media_Card","name":"messageback","imdisplayname":"Azure Admin","complianceData":{"action":{"type":"Action.Submit","title":"Submit"}}}'
响应相同 400:
{"errorCode":201,"message":"The resource URL agentMri is misformatted."}
我能发现的唯一区别是 --data-raw '{"value":{"id":"1234567890","MultiLineVal":"My comment"},"
部分。第二个请求有 "MultiLineVal":"My comment"
。这正是我希望在蜂感受器方面看到的,但它从未达到 API.
不太清楚什么是 agentMri
、格式错误的位置和方式,以及在自适应卡中更改什么以使表单提交到相同的 webhook 域。我不确定这个 agentMri“格式错误”是否相关,但这是来自 Teams 的唯一包含我在自适应卡中输入的字符串的 http 请求。
传出 Webhook 不能使用除 openURL 之外的任何卡片操作。
文档参考:Key features of Outgoing Webhook:
Standard HTTP message exchange | Responses appear in the same chain as the original request message and can include any Bot Framework message content. For example, rich text, images, cards, and emojis. Although Outgoing Webhooks can use cards, they can't use any card actions except for openURL. |