0

我有一个问题,我无法从 Microsoft Teams 中的消息卡文本输入中检索值,但相同的 JSON 模板实际上适用于Message Card Playground

我的 Microsoft Card 实现的简要概述。我必须使用 MessageCard,因为我正在使用连接器(传入 webhook)将卡片发送到 Microsoft Teams。因此,输入值替换语法参考消息卡参考- {{<id of input>.value}}。当我在 TEAMS 中时,在我的消息卡中使用此语法没有得到任何价值。例如,用户填写了一个文本框,并且该值未被捕获或无法使用此语法检索。

我使用的卡如下:

{
"@type":  "MessageCard",
"@context":  "http://schema.org/extensions",
"themeColor":  "0076D7",
"summary":  "{{ctx.monitor.name}}",
"sections":  [
                 {
                     "activityTitle":  "![TestImage](https://47a92947.ngrok.io/Content/Images/default.png){{ctx.monitor.name}}",
                     "activitySubtitle":  "Alert",
                     "activityImage":  "https://teamsnodesample.azurewebsites.net/static/img/image5.png",
                     "facts":  [
                                   {
                                       "name":  "Assigned to",
                                       "value":  "Sam"
                                   }
                               ],
                     "markdown":  true
                 }
             ],
"potentialAction":  [
                        {
                            "@type": "ActionCard",
                            "name": "Add a comment",
                            "inputs": [
                                {
                                    "@type": "TextInput",
                                    "id": "comment",
                                    "title": "Enter your comment",
                                    "isMultiline": true
                                }
                            ],
                            "actions": [
                                {
                                    "@type": "HttpPOST",
                                    "name": "OK",
                                    "target": "https://webhook.site/ab592c11-4590-438d-90c2-57bc4bb4aa8a?serviceToken=d2l0cy1zYW06MXFhekBXU1g%3D",
                                    "body": "{{comment.value}}"
                                }
                            ]
                        }
                    ]
}

注意:你可以看到有"summary": "{{ctx.monitor.name}}",它是来自 Kibana(一个数据可视化工具)的一个属性。这个值是有效的,但这不是我们的重点。我的问题是我无法从 {{comment.value}} 获得任何值,它是一个空字符串。

我的问题是:

  1. 这是来自 MSFT Teams 本身的限制吗?
4

1 回答 1

0

@csamleong 您能否替换“body”:“comment ={{comment.value}}”,这样您将收到评论值:card json:

{
"summary": "Card \"Test card\"",
"themeColor": "0078D7",
"@type":  "MessageCard",
"@context":  "http://schema.org/extensions",
"themeColor":  "0076D7",
"summary":  "{{ctx.monitor.name}}",
"sections":  [
                 {
                     "activityTitle":  "![TestImage](https://47a92947.ngrok.io/Content/Images/default.png){{ctx.monitor.name}}",
                     "activitySubtitle":  "Alert",
                     "activityImage":  "https://teamsnodesample.azurewebsites.net/static/img/image5.png",
                     "facts":  [
                                   {
                                       "name":  "Assigned to",
                                       "value":  "Sam"
                                   }
                               ],
                     "markdown":  true
                 }
             ],
"potentialAction":  [
                        {
                            "@type": "ActionCard",
                            "name": "Add a comment",
                            "inputs": [
                                {
                                    "@type": "TextInput",
                                    "id": "comment",
                                    "title": "Enter your comment",
                                    "isMultiline": true
                                }
                            ],
                            "actions": [
                                {
                                    "@type": "HttpPOST",
                                    "name": "OK",
                                    "target": "https://daf47bb241c6.ngrok.io//weatherforecast/Configure/Comment",
                                    "body": "comment={{comment.value}}"
                                }
                            ]
                        }
                    ]
}

邮寄方式:

[HttpPost]
        [Route("Configure/Comment")]
        public async Task<ActionResult> Comment()
        {
            string bodyStr;
            using (var reader = new StreamReader(this.Request.Body, Encoding.UTF8, true, 1024, true))
            {
                bodyStr = await reader.ReadToEndAsync();
            }
            string comment = string.IsNullOrWhiteSpace(bodyStr) ? string.Empty : bodyStr.Split('=')[1];
            Response.Headers.Add("CARD-UPDATE-IN-BODY", "true");
            return null;
        }

您将在评论变量中收到值。

于 2020-09-23T07:18:52.413 回答