自适应卡片提交操作

Shu*_*hta 5 c# adaptive-cards

我使用 JSON 格式生成了一张自适应卡片,其中有两个按钮提交和取消,它们分别返回“messageBack”消息作为提交和取消。我正在使用 C# 访问回复,但我无法弄清楚如何从自适应卡访问回复。

我的 json 是

    {
      "type": "AdaptiveCard",
      "selectAction": {        
        "type": "Action.Submit"
      },
      "body": [
        {
          "type": "TextBlock",
          "horizontalAlignment": "Center",
          "size": "Large",
          "weight": "Bolder",
          "color": "Accent",
          "text": "Meeting Composer Create"
        },
        {
          "type": "ColumnSet",
          "columns": [
            {
              "type": "Column",
              "items": [
                {
                  "type": "TextBlock",
                  "horizontalAlignment": "Left",
                  "spacing": "Medium",
                  "size": "Medium",
                  "weight": "Bolder",
                  "color": "Accent",
                  "text": "Attendees:"
                 }
              ],
              "width": "stretch"
            },
            {
              "type": "Column",
              "items": [
                {
                  "type": "TextBlock",
                  "id": "attendeeVal",
                  "text": "a"
                }
              ],
              "width": "stretch"
            }
          ]
        },
        {
          "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "size": "Medium",
              "weight": "Bolder",
              "color": "Accent",
              "text": "Subject:"
            }
          ],
          "width": "stretch"
        },
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "id": "subVal",
              "text": "meeting"
            }
          ],
          "width": "stretch"
        }
      ]
    },
    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "size": "Medium",
              "weight": "Bolder",
              "color": "Accent",
              "text": "Date:"
            }
          ],
          "width": "stretch"
        },
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "id": "dateVal",
              "text": "17/11/2018 10.30 AM"
            }
          ],
          "width": "stretch"
        }
      ]
    },
    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "size": "Medium",
              "weight": "Bolder",
              "color": "Accent",
              "text": "Document Name:"
            }
          ],
          "width": "stretch"
        },
        {
          "type": "Column",
          "items": [
            {
              "type": "TextBlock",
              "id": "docVal",
              "text": "Document1"
            }
          ],
          "width": "stretch"
        }
      ]
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "Submit",
      "data": {
        "msteams": {
          "type": "messageBack",
          "displayText": "I clicked this button",
          "text": "text to bots",
          "value": "Submit"
        }
      }
    },
    {
      "type": "Action.Submit",
      "title": "Cancel",
      "data": {
        "msteams": {
          "type": "messageBack",
          "displayText": "I clicked this button",
          "text": "text to bots",
          "value": "Cancel"
        }
      }
    }
  ],
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "version": "1.0"
}
Run Code Online (Sandbox Code Playgroud)

我的 C# 是

 var response = getCard(stepContext, "Aditya Rao, Vishal Subramaniam" , "Scrum Meeting" , "17/11/1028, 10:30AM" , "Scrum Sprint.pptx");
 await stepContext.Context.SendActivityAsync(response).ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)

我要支持的附加功能是

private static Attachment CreateAdaptiveCardAttachment(string filePath, string names, string subj , string datee, string docs)
    {
        var adaptiveCardJson = File.ReadAllText(filePath);
        dynamic obj = JsonConvert.DeserializeObject(adaptiveCardJson);
        obj["body"][1]["columns"][1]["items"][0]["text"] = names;
        obj["body"][2]["columns"][1]["items"][0]["text"] = subj;
        obj["body"][3]["columns"][1]["items"][0]["text"] = datee;
        obj["body"][4]["columns"][1]["items"][0]["text"] = docs;
        var adaptiveCardAttachment = new Attachment()
        {
            ContentType = "application/vnd.microsoft.card.adaptive",
            Content = obj,
        };
        return adaptiveCardAttachment;
    }


    // Create an attachment message response.
    private Activity CreateResponse(Activity activity, Attachment attachment)
    {
        var response = activity.CreateReply();
        response.Attachments = new List<Attachment>() { attachment };
        return response;
    }


    private Activity getCard(WaterfallStepContext stepContext, string names, string subj , string datee, string docs)
    {
        var jsonFilePath = @".\Dialogs\CardTemplates\MeetingComposerCreate.json";
        var activity = stepContext.Context.Activity;
        var adCard = CreateAdaptiveCardAttachment(jsonFilePath,names,subj,datee,docs);
        var response = CreateResponse(activity, adCard);
        return response;
    }
Run Code Online (Sandbox Code Playgroud)

单击提交或取消后,如何访问值响应?

另外,如果有人可以帮助我找到如何从 input.choice 获得回复以获取所选卡片的复选框数据。

Fei*_*Han 2

单击“提交”或“取消”后如何访问值响应?

我们可以通过属性获取用户从自适应卡提交的值Activity.Value

if(turnContext.Activity.Value!= null)
{

    reply.Text = $"submit data: {turnContext.Activity.Value}";

}
Run Code Online (Sandbox Code Playgroud)

测试结果:

在此输入图像描述

模拟器中的输出:

在此输入图像描述

另外,如果有人可以帮助我找到如何从 input.choice 获取回复以获取所选卡片的复选框数据。

要显示选项供用户选择并获取所选选项,可以参考以下代码片段。

在 json 文件中:

{
  "type": "Input.ChoiceSet",
  "id": "optionSelection",
  "isMultiSelect": true,
  "style": "compact",
  "choices": [
    {
      "title": "option1",
      "value": "option1"
    },
    {
      "title": "option2",
      "value": "option2"
    },
    {
      "title": "option3",
      "value": "option3"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

使用相同的代码来获取用户的选择:

reply.Text = $"submit data: {turnContext.Activity.Value}";
Run Code Online (Sandbox Code Playgroud)

测试结果:

在此输入图像描述