0

I am making a bot that communicates with QnaMaker, and depending on the answer, a guided conversation through FormFlow should be opened using Json. My problem is exactly at this point in order to open the form. I'm using SDK V3 and QnAMakerDialog of the garypretty

I've tried several things like calling context.Forward or context.Call, but not right, maybe I'm calling the wrong way.

Always returns the message saying there is a problem in the source code.

public override async Task DefaultMatchHandler(IDialogContext context, 
string originalQueryText, QnAMakerResult result)
{
    QnaAnswer a = result.Answers.First();
    var messageActivity = ProcessResultAndCreateMessageActivity(context, ref result);

    if (a.Answer == "form")
    {
       // OPEN FORM HERE
    }

    await context.PostAsync(messageActivity);
   context.Wait(MessageReceived);
}
Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
  • Can you be more specific about what problem is being encountered in the source code? Try running it in debug mode and setting breakpoints. I suspect the problem is that you're calling context.Forward() and then context.Wait(). You're only allowed to call one of these per turn, and any additional calls will throw an "invalid need" exception. – Kyle Delaney Jan 07 '19 at 20:04
  • Also, please do post the code you've been using to open the form dialog – Kyle Delaney Jan 07 '19 at 20:04
  • Hi, you're right, I was calling the calling context.Forward() and then context.Wait(). I corrected this and the problem was solved. Thank you very much. – Romário Carvalho Jan 08 '19 at 16:37
  • Would you like to post your own answer or would you like me to post it as an answer? – Kyle Delaney Jan 08 '19 at 19:00
  • ok.. @KyleDelaney – Romário Carvalho Jan 09 '19 at 13:14

1 Answers1

1

Solution:

public static bool IsForm = false;

 public override async Task DefaultMatchHandler(IDialogContext context, 
 string originalQueryText, QnAMakerResult result)
 {
     QnaAnswer a = result.Answers.First();
     var messageActivity = ProcessResultAndCreateMessageActivity(context, ref result);

     if (a.Answer == "form")
     {
         IsForm = true;
         var form = new FormDialog<JObject>(new JObject(), JsonForm.BuildJsonForm, FormOptions.PromptInStart);
         context.Call(form, FormCallback);
     }
     else
     {
          IsForm = false;
          messageActivity.Text = $"{result.Answers.First().Answer}";
     }

     if (IsForm == false)
     {
         await context.PostAsync(messageActivity);
         context.Wait(MessageReceived);
     }
 }

Thanks Kyle.