【问题标题】:Passing submit action in adaptive cards on c#在 c# 的自适应卡片中传递提交操作
【发布时间】:2019-12-14 14:11:11
【问题描述】:

如何解析自适应卡片中的提交操作值?我知道在附近但无法解决它。如果我手动输入文本,我会前进到瀑布模型中的新对话框

卡片.json

{  
    "type": "AdaptiveCard",
  "body": [
    {
      "type": "TextBlock",
      "id": "textBlock",
      "text": "CREATE AN INCIDENT. "
    },
    {
      "type": "Input.Text",
      "id": "username",
      "placeholder": "Enter your email address"

    },
    {
      "type": "Input.Text",
      "id": "shortdescription",
      "placeholder": "Enter a short description"

    },
    {
      "type": "Input.Number",
      "id": "phonenumber",
      "placeholder": "Enter your phonenumber"

    }

  ],  
    "actions": [  
        {  
            "type": "Action.Submit",  
            "id": "submit",  
            "title": "Submit",  
            "data":{  
                        "action": "mychoices"  

            }  
        }  
    ],  
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",  
    "version": "1.0"  
}  

RequestDialog.cs

var askforSelectionSteps = new WaterfallStep[]
            {
                askForSelection,
                askForSelectionResult,
                CreateTicketFor_InstallSoftware
            };



public async Task<DialogTurnResult> askForSelection(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            _state = new GenericRequestState();
            await _accessor.SetAsync(sc.Context, _state);
            //return await sc.PromptAsync(choiceprompt, new PromptOptions()
            //{
            //    Prompt = MessageFactory.Text("Can you please let me know if the request is for you or someone else?"),
            //    Choices = new List<Choice> { new Choice("MySelf"), new Choice("Someone Else") },
            //    RetryPrompt = MessageFactory.Text("Please enter MySelf or Someone Else."),
            //});
            return await sc.PromptAsync(TextPrompt, new PromptOptions()
            {
                Prompt = CardHelper.GenericRequestIncidentChoices(sc, cancellationToken),
            });
        }
        public async Task<DialogTurnResult> askForSelectionResult(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var isSuccess = sc.Result.ToString().ToLower();
            if (isSuccess == "incident" || isSuccess == "inc")
            {
                //return await sc.BeginDialogAsync(GenericRequestationStep_OneId);
                return await sc.PromptAsync(TextPrompt, new PromptOptions()
                {
                    Prompt = CardHelper.GenericCreateIncident(sc, cancellationToken),
                });


            }}

我查看了一些示例和 stackoverflow 本身,但无法将提交操作传递回对话框。任何帮助将不胜感激!

【问题讨论】:

    标签: c# botframework azure-bot-service adaptive-cards


    【解决方案1】:
    protected override async Task OnEventAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var value = dc.Context.Activity.Value;
    
            if (value.GetType() == typeof(JObject))
            {
                var result = await dc.ContinueDialogAsync();
                return;
            }
        }
    

    你有没有像上面那样在 OnEventAsync 中编写 JObject 处理?

    请看链接

    How to retrieve Adaptive Card's form submission in subsequent waterfall step

    ContinueDialogAsync does not work when I use the input form of adaptive-cards in the waterfall dialog

    【讨论】:

      【解决方案2】:

      想知道如何处理JToken?如果是这样,请参阅下面的代码。

                      var token = JToken.Parse(turnContext.Activity.ChannelData.ToString());
                      if (token["postBack"].Value<bool>())
                      {
                          JToken commandToken = JToken.Parse(turnContext.Activity.Value.ToString());
                          var data = commandToken["Your_Data_ID"].Value<Your_Data_Type>();
                      }
      

      “Your_Data_ID”是电话号码、简短描述等... Your_Data_Type 是 int、string 等...

      【讨论】:

        猜你喜欢
        • 2019-04-22
        • 2019-11-21
        • 2020-11-07
        • 2020-12-31
        • 2021-03-24
        • 2021-04-12
        • 1970-01-01
        • 2020-08-14
        • 1970-01-01
        相关资源
        最近更新 更多