在on_message_activity中收到Microsoft Teams bot自适应卡行动,但无数据

时间:2020-06-06 18:38:01

标签: python botframework microsoft-teams

我的机器人通过与用户1:1的私人聊天返回了一张自适应卡,自适应卡的配置是这样的,

{
            "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
            "type": "AdaptiveCard",
            "version": "1.0",
            "body": [
                {
                    "type": "Container",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": f"{jiradetail.summary}",
                        }
                    ]
                }
            ],
            "actions": [
                {
                    "type": "Action.ShowCard",
                    "title": "Comment",
                    "card": {
                        "type": "AdaptiveCard",
                        "version": "1.0",
                        "body": [
                            {
                                "type": "Input.Text",
                                "id": "comment",
                                "isMultiline": True,
                                "placeholder": "Enter your comment"
                            }
                        ],
                        "actions": [
                            {
                                "type": "Action.Submit",
                                "title": "OK",
                                "data": "**jiraid**"
                            }
                        ]
                    }
                }
            ]
        }

如您所见,有一个“注释”文本框和一个“确定”动作(类型为Action.Submit和hidden data-> jiraid),该卡如下所示,

enter image description here

现在点击此“确定”按钮,我正在中接收活动,

on_message_activity,用户在字段的注释框中输入值

turn_context.activity.value

但是我无法获取映射到操作按钮的隐藏数据,下图显示了'turn_context.activity'的检查值。

如何获取映射数据以执行此操作?

enter image description here

注意:我还希望回调是 on_teams_messaging_extension_submit_action ,但是从不调用此回调,而是仅调用 on_message_activity 。我认为这是因为它是1:1对话,并且未通过messageextensions调用。任何专家都请确认。

2 个答案:

答案 0 :(得分:0)

关于“ on_teams_messaging_extension_submit_action”-不是因为它是1-1,而是因为它不是“消息扩展名”,而是常规的自适应卡操作。

关于主要问题,关于数据不出现,请尝试避免将直接字符串值用作“数据”有效负载,而应尝试使用这样的对象:

... "data": {"value": "**jiraid**"} ...

答案 1 :(得分:0)

在这里得到答案

https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-actions#

为便于参考,这是我们应该做的

自适应卡支持三种操作类型:

  • Action.OpenUrl
  • Action.Submit
  • Action.ShowCard

除了 上面提到的操作,您可以修改自适应卡 Action.Submit负载以支持现有的Bot Framework操作 Action.Submit数据对象中的msteams属性。下面 部分详细介绍了如何将现有Bot Framework操作与 自适应卡。

因此更新后的有效负载将是,请在action-> data下引用有效负载'msteams',

{
            "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
            "type": "AdaptiveCard",
            "version": "1.0",
            "body": [
                {
                    "type": "Container",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": f"{jiradetail.summary}",
                        }
                    ]
                }
            ],
            "actions": [
                {
                    "type": "Action.ShowCard",
                    "title": "Comment",
                    "card": {
                        "type": "AdaptiveCard",
                        "version": "1.0",
                        "body": [
                            {
                                "type": "Input.Text",
                                "id": "comment",
                                "isMultiline": True,
                                "placeholder": "Enter your comment"
                            }
                        ],
                        "actions": [
                            {
                                "type": "Action.Submit",
                                "title": "OK",
                                "data": {
                                "msteams": {
                                    "type": "invoke",
                                    "value": {"jiraid":f"{jiradetail.issueid}"}
                                }
                            }
                        ]
                    }
                }
            ]
        }