json - 机器人框架用户选择的按钮文本未显示在机器人中
问题描述
我正在使用 ms bot 框架开发 Microsoft 团队机器人。在那,我使用自适应卡来显示描述和两个按钮。
当用户单击按钮时,我需要将 json 数据传递给后端。如果我在按钮操作上传递字符串数据("data": "ONE"),那么我可以读取后端中的参数,并且用户单击的按钮文本将进入机器人。请看下面的代码和输出图像
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Hi, this is your Botzer personal assistant , how can I help you? <a href=\"https://www.powerupcloud.com/blogs/\" target=\"_blank\">Click Here </a>",
"weight": "bolder",
"isSubtle": false,
"wrap": true
}
],
"actions": [
{
"type": "Action.Submit",
"title": "ONE",
"data": "ONE"
},
{
"type": "Action.Submit",
"title": "TWO",
"data": "TWO"
}
]
}
}
但是,当我发送关于按钮操作的 json 数据(“data”:{“id”:“action2”,“name”:“two”,“value”:“TWO”})时,我可以在后端读取数据. 但是,按钮文本不会出现在机器人上。请看下面的代码和输出图像
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Choose the number",
"weight": "bolder",
"isSubtle": false,
"wrap": true
}
],
"actions": [
{
"type": "Action.Submit",
"title": "ONE",
"data": {
"id": "action1",
"name": "one",
"value": "ONE"}
},
{
"type": "Action.Submit",
"title": "TWO",
"data": {
"id": "action2",
"name": "two",
"value": "TWO"}
}
]
}
}
解决方案
你想要的是一个消息返回,它结合了字符串提交动作和对象提交动作的功能。由于您的自适应卡中没有任何输入,因此您可以将其替换为英雄卡并messageBack
直接使用动作。如果您仍想使用自适应卡,那么您很幸运,因为 Teams 实际上具有允许您将消息放回自适应卡的特殊功能。您可以在 Hessel 链接到的博客文章的“团队中的自适应卡”部分中查看如何执行此操作,或者您可以直接查阅文档。
推荐阅读
- javascript - 从数组中返回一个字符串
- java - Google Maps JavaScript API - Billing
- powershell - 如何修复@{DisplayName=Firstname Lastname}
- docker - 在没有云的 Windows 虚拟机上使用 docker 的优缺点是什么?
- c# - 输入字符串的格式不正确 - 使用了错误的上下文
- git - Composer 克隆 GIT Commit 而不是 Tag
- java - 使用子字符串从Java中的字符串中获取整数和字符?
- php - 如何直接将每列值作为数组获取,而不使用 pluck laravel?
- c++ - 在没有服务器的情况下运行客户端应用程序以验证响应有哪些不同的方法?
- c# - 碰撞后音频剪辑不播放