c# - 在bot框架v4中,如何实现带有评论框和提交按钮的评分卡

标签 c# botframework adaptive-cards

我使用C#制作了一个机器人框架V4。我已经在自适应卡中进行了星级评级,但我需要在其中添加评论框和提交按钮,但我的提交按钮不起作用。在 Debug模式下,它没有命中机器人的任何方法。请帮助我。我还附上了我的评分卡的代码,其中有评论框和提交按钮。

 {
  "type": "AdaptiveCard",
  "body": [
   {
  "type": "TextBlock",
  "size": "Medium",
  "weight": "Bolder",
  "color": "Accent",
  "text": "Rate your experience!"
    },
    {
  "type": "TextBlock",
  "separator": true,
  "text": "Please rate your experience! Your feedback is very appreciated and will help improve your 
  experience in the future. ",
  "wrap": true
},
  {
  "type": "ColumnSet",
  "spacing": "Medium",
  "columns": [
    {
      "type": "Column",
      "selectAction": {
        "type": "Action.Submit",
        "data": "awful"
      },
      "items": [
        {
          "type": "Image",
          "horizontalAlignment": "Center",
          "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg"
        },
        {
          "type": "TextBlock",
          "horizontalAlignment": "Center",
          "text": "Awful"
        }
      ],
      "width": "stretch"
    },
    {
      "type": "Column",
      "selectAction": {
        "type": "Action.Submit",
        "data": "bad"
      },
      "items": [
        {
          "type": "Image",
          "horizontalAlignment": "Center",
          "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg"
        },
        {
          "type": "TextBlock",
          "horizontalAlignment": "Center",
          "text": "Bad"
        }
      ],
      "width": "stretch"
    },
    {
      "type": "Column",
      "selectAction": {
        "type": "Action.Submit",
        "data": "ok"
      },
      "items": [
        {
          "type": "Image",
          "horizontalAlignment": "Center",
          "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg"
        },
        {
          "type": "TextBlock",
          "horizontalAlignment": "Center",
          "text": "Ok"
        }
      ],
      "width": "stretch"
    },
    {
      "type": "Column",
      "selectAction": {
        "type": "Action.Submit",
        "data": "good"
      },
      "items": [
        {
          "type": "Image",
          "horizontalAlignment": "Center",
          "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg"
        },
        {
          "type": "TextBlock",
          "horizontalAlignment": "Center",
          "text": "Good"
        }
      ],
      "width": "stretch"
    },
    {
      "type": "Column",
      "selectAction": {
        "type": "Action.Submit",
        "data": "terrific"
      },
      "items": [
        {
          "type": "Image",
          "horizontalAlignment": "Center",
          "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg"
        },
        {
          "type": "TextBlock",
          "horizontalAlignment": "Center",
          "text": "Terrific"
        }
          ],
          "width": "stretch"
        }
      ]
     },
{
      "type": "Input.Text",
      "id": "comment",
      "placeholder": "Add a comment",
      "isMultiline": true
    }
      ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "version": "1.0",
       "actions": [
    {
      "type": "Action.Submit",
      "title": "Ok",
      "data": "ok"
    }
      ]
    }

最佳答案

您的卡 JSON 存在一些问题需要修复:

  1. 您的操作没有标题。
  2. 您应该将data 设为对象而不是字符串。字符串大部分情况下都可以工作,但一致性较差。

您可以通过复制/粘贴代码in the Designer来查找/修复卡的大多数错误。并查找错误:

enter image description here

我已经重新创建了您的卡,以便它可以正常工作:

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "TextBlock",
            "text": "Rate your experience!",
            "weight": "Bolder",
            "color": "Accent",
            "size": "Medium"
        },
        {
            "type": "TextBlock",
            "text": "Please rate your experience! Your feedback is very appreciated and will help improve your experience in the future. ",
            "wrap": true
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Image",
                            "altText": "",
                            "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg",
                            "selectAction": {
                                "type": "Action.Submit",
                                "data": { "rating": "awful" },
                                "title": "awful"
                            }
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Image",
                            "altText": "",
                            "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg",
                            "selectAction": {
                                "type": "Action.Submit",
                                "data": { "rating": "bad" },
                                "title": "bad"
                            }
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Image",
                            "altText": "",
                            "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg",
                            "selectAction": {
                                "type": "Action.Submit",
                                "data": { "rating": "ok" },
                                "title": "ok"
                            }
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Image",
                            "altText": "",
                            "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg",
                            "selectAction": {
                                "type": "Action.Submit",
                                "data": { "rating": "good" },
                                "title": "good"
                            }
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "Image",
                            "altText": "",
                            "url": "https://upload.wikimedia.org/wikipedia/commons/1/18/Five-pointed_star.svg",
                            "selectAction": {
                                "type": "Action.Submit",
                                "data": { "rating": "terrific" },
                                "title": "terrific"
                            }
                        }
                    ]
                }
            ]
        },
        {
            "type": "Input.Text",
            "placeholder": "Add a comment",
            "isMultiline": true,
            "id": "comment"
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0",
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Ok"
        }
    ]
}

请注意,反馈将来自 Activity.Value. rating

关于c# - 在bot框架v4中,如何实现带有评论框和提交按钮的评分卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59929544/

相关文章:

c# - 在 Windows Phone 8.1 上禁用 hub navigationTo 动画

node.js - 带有 node.js 机器人框架的 Skype 语音识别 API

microsoft-teams - MS Teams 的自适应卡 - 图像显示在 Web 界面中,但不显示桌面应用程序

c# - 如何在 BotFramework 上设置 AdaptiveCard 提交按钮操作的文本值

c# - Entity Framework 核心 : Get changes occured in entity and related data

c# - 如何在Y轴上每N个值显示标签?

c# - asp.net母版页执行的顺序

python - Microsoft BotFramework Python 机器人部署

node.js - 将主动消息从 Azure 函数发送到机器人服务 - Node

c# - 自适应卡片能否以模板方式用于自适应对话?