可行的消息消息卡输入值替代在Microsoft Teams中不起作用

问题描述

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

我的Microsoft Card实施的简要概述。我必须使用MessageCard,因为我正在使用连接器(传入的Webhook)将卡发送给Microsoft Teams。因此,从Message Card Reference- {{ .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}}"
                                }
                            ]
                        }
                    ]
}

注意:您可以看到摘要”:“ {{ctx.monitor.name}}” ,它是Kibana(数据可视化工具)的属性。此值有效,但此处并非我们关注的重点。我的问题是我无法从{{comment.value}}获取任何值,它是一个空字符串。

我的问题是:

  1. 这是MSFT团队本身的限制吗?

解决方法

@csamleong,请您替换“ body”:“ comment = {{{comment.value}}””,以便您收到评论值: 卡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;
        }

您将在注释变量中获得价值。