1

I have been using the EchoBot Template and have recently used the VirtualAssistant Template. In the previous template, there was no problem in submitting the input form data, but this template does not work with ContinueDialogAsync just by submitting the input form data. How can we solve this? Please help me.

input form of WaterfallStep

       card.Body.Add(new AdaptiveTextBlock()
            {
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                Spacing = AdaptiveSpacing.None,
                Size = AdaptiveTextSize.Small,
                Weight = AdaptiveTextWeight.Bolder,
                Color = AdaptiveTextColor.Accent,
                Text = Common.PurchaseDialog_DepartureDate
            });

        card.Body.Add(new AdaptiveDateInput()
        {
            Id = "GoDateVal",
            Value = DateTime.Now.AddDays(4).ToString("yyyy-MM-dd"),
            Spacing = AdaptiveSpacing.None
        });

        if (lowestPriceQuery.tripType == "RT")
        {
            card.Body.Add(new AdaptiveTextBlock()
            {
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                Spacing = AdaptiveSpacing.None,
                Size = AdaptiveTextSize.Small,
                Weight = AdaptiveTextWeight.Bolder,
                Color = AdaptiveTextColor.Accent,
                Text = Common.PurchaseDialog_CommingDate
            });

            card.Body.Add(new AdaptiveDateInput()
            {
                Id = "ComeDateVal",
                Value = DateTime.Now.AddDays(8).ToString("yyyy-MM-dd"),
                Spacing = AdaptiveSpacing.None,
            });
        }

if (lowestPriceQuery.tripType == "DS")
        {
            card.Body.Add(new AdaptiveTextBlock()
            {
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                Spacing = AdaptiveSpacing.None,
                Size = AdaptiveTextSize.Small,
                Weight = AdaptiveTextWeight.Bolder,
                Color = AdaptiveTextColor.Accent,
                Text = "ReturnDate"
            });

            card.Body.Add(new AdaptiveDateInput()
            {
                Id = "ComeDateVal",
                Value = DateTime.Now.AddDays(8).ToString("yyyy-MM-dd"),
                Spacing = AdaptiveSpacing.None,
            });
        }

        card.Actions.Add(new AdaptiveSubmitAction()
        {
            Type = AdaptiveSubmitAction.TypeName,
            Title = "submit",
            Id = "submit",
        });

        reply.Attachments = new List<Attachment>
        {
            new Attachment()
            {
                ContentType = "application/vnd.microsoft.card.adaptive",
                Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card))
            }
        };
        await turnContext.SendActivityAsync(reply, cancellationToken: cancellationToken);

DilaogBot,

When debugging, nothing happens in var result = await dc.ContinueDialogAsync (); when submitting from input form.

var dc = await _dialogs.CreateContextAsync(turnContext);

                if (turnContext.Activity.Type == ActivityTypes.Message)
                {
                    // Ensure that message is a postBack (like a submission from Adaptive Cards)
                    var channelData = JObject.Parse(dc.Context.Activity.ChannelData.ToString());
                    if (channelData.ContainsKey("postback"))
                    {
                        var postbackActivity = dc.Context.Activity;
                        // Convert the user's Adaptive Card input into the input of a Text Prompt
                        // Must be sent as a string
                        postbackActivity.Text = postbackActivity.Value.ToString();
                        await dc.Context.SendActivityAsync(postbackActivity);
                    }
                }

                if (dc.ActiveDialog != null)
                {
                    var result = await dc.ContinueDialogAsync();
                }
                else
                {
                    await dc.BeginDialogAsync(typeof(T).Name);
                }
SLock
  • 29
  • 11
  • how about `await dc.context.ContinueDialogAsync();`? – jazb Jul 31 '19 at 06:55
  • I continue after begin the waterfallstep in Maindialog. – SLock Jul 31 '19 at 07:06
  • @SLock I submitted an answer. I'm fairly certain you got that code from me at some point (before I knew better). Can you link me to it? I thought I had corrected all of my previous answers, but perhaps not. – mdrichardson Jul 31 '19 at 18:01

1 Answers1

2

You need to remove:

await dc.Context.SendActivityAsync(postbackActivity);

When the bot sends a message, it marks the dialog as having been responded to and doesn't continue appropriately.

Additionally, your "//Ensure message is a PostBack" code should be more like this:

var activity = turnContext.Activity;

if (activity.Type == ActivityTypes.Message)
{
    if (string.IsNullOrWhiteSpace(activity.Text) && activity.Value != null)
    {
        activity.Text = JsonConvert.SerializeObject(activity.Value);
    }
}

I believe you got that code from an old answer of mine, which I have since improved.

mdrichardson
  • 7,141
  • 1
  • 7
  • 21
  • Thanks @mdrichardson - MSFT, I solved the problem by referring to your current and previous answers.Thank you very much for your reply. – SLock Aug 01 '19 at 06:06