Bot Framework with QnaMaker and FormFlow

80 Views Asked by At

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);
}
1

There are 1 best solutions below

0
Romário Carvalho On

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.