【问题标题】:Action.Submit on Adaptive Cards not working with Input.Text Python SDK自适应卡片上的 Action.Submit 不适用于 Input.Text Python SDK
【发布时间】:2018-11-10 11:53:01
【问题描述】:

我正在尝试使用 Bot Builder v4 Python SDK 的自适应卡。我正在尝试使用 Input.text 字段然后是 Action.submit

从用户那里收集反馈
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [                           
],
"actions": [{
        "type": "Action.ShowCard",
        "title": "Want to provide feedback",
        "card": {
            "type": "AdaptiveCard",
            "actions": [
        {
            "type": "Action.Submit",
            "data": "Yes, it was helpful",
            "title": "Yes"
        },
        {
            "type": "Action.Submit",
            "data": "No, it wasn't helpful",
            "title": "No"
        },
        {
            "type": "Action.Submit",
            "data": "Start Over",
            "title": "Start Over"
        },
        {
            "type": "Action.Submit",
            "data": "Exit",
            "title": "Exit"
        },{
        "type": "Action.ShowCard",
        "title": "Comment",
        "card": {
            "type": "AdaptiveCard",
            "body": [
                {
                    "type": "Input.Text",
                    "id": "comment",
                    "isMultiline": true,
                    "placeholder": "Enter your comment"
                }
            ],
            "actions": [
                {
                    "type": "Action.Submit",
                    "title": "OK"
                }
            ]
        }
    }
        ]
        }
    }
]}

这在visualizer 上运行良好。当我编写一些 cmets 并单击 OK 时,这在可视化器上有效,但在实践中不起作用。它会引发 502 错误。

请看下面的截图

我正在使用适用于 Python 的 Bot Build v4 SDK 并在 Web Chat 上进行测试。似乎在自适应卡方面没有问题,我想这与 Python SDK 有关。关于错误可能在哪里的任何指针?

【问题讨论】:

    标签: botframework azure-bot-service


    【解决方案1】:

    请尝试以下代码 sn-p 进行快速测试:

    def __create_reply_activity(request_activity):
            return Activity(
                type=ActivityTypes.message,
                channel_id=request_activity.channel_id,
                conversation=request_activity.conversation,
                recipient=request_activity.from_property,
                from_property=request_activity.recipient,
                attachments=[Attachment(
                    content_type='application/vnd.microsoft.card.adaptive',
                    content={
                        "type": "AdaptiveCard",
                        "body": [
                        ],
                        "actions": [{
                                "type": "Action.ShowCard",
                                "title": "Want to provide feedback",
                                "card": {
                                    "type": "AdaptiveCard",
                                    "actions": [
                                        {
                                            "type": "Action.Submit",
                                            "data": "Yes, it was helpful",
                                            "title": "Yes"
                                        },
                                        {
                                            "type": "Action.Submit",
                                            "data": "No, it wasn't helpful",
                                            "title": "No"
                                        },
                                        {
                                            "type": "Action.Submit",
                                            "data": "Start Over",
                                            "title": "Start Over"
                                        },
                                        {
                                            "type": "Action.Submit",
                                            "data": "Exit",
                                            "title": "Exit"
                                        },
                                        {
                                            "type": "Action.ShowCard",
                                            "title": "Comment",
                                            "card": {
                                                "type": "AdaptiveCard",
                                                "body": [
                                                    {
                                                        "type": "Input.Text",
                                                        "id": "comment",
                                                        "isMultiline": "true",
                                                        "placeholder": "Enter your comment"
                                                    }
                                                ],
                                                "actions": [
                                                    {
                                                        "type": "Action.Submit",
                                                        "title": "OK"
                                                    }
                                                ]
                                            }
                                        }
                                    ]
                                }
                        }],
                    },
                    )],
                service_url=request_activity.service_url)
    

    Adding an adaptive card to bot framework with python有详细说明

    【讨论】:

    • 感谢@Gary Liu - MSFT 的投入。我发现了这个问题。当我在评论卡上单击“确定”时,消息确实已发送到机器人。发生的事情是,消息内容没有在 Activity 对象的通常“文本”属性中传递。它被传入一个新键,例如 {'value':{'comment':'这些是 cmets''}}。也许我应该写一个明确的答案来解释这一点。
    • 是的,@Vijay,将value设置为输入,您可以参考adaptivecards.io/explorer/Input.Text.html了解更多详情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多