1

I created a bot using QnA Maker, which depending on the answer I should return the same answer or call another service, which in my case is to assemble a form flow from a JSON.

But when calling this service I start a new Conversation, so it does not return to the emulator.

I'm creating a conversation in another conversation. There must be something missing.

RootDialog.cs:

[Serializable]
public class RootDialog : QnAMakerDialog
{
    public RootDialog() : base(
        new QnAMakerService(
            new QnAMakerAttribute(
                ConfigurationManager.AppSettings["QnaSubscriptionKey"],
                ConfigurationManager.AppSettings["QnaKnowledgebaseId"],
                "Não encontrei sua resposta",
                0.5
                )
            )
        )
    {

    }

    protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
    {
        var primeiraResposta = result.Answers.First().Answer;

        if (primeiraResposta.IndexOf("form") == -1)
        {
            await context.PostAsync(primeiraResposta);
            return;
        }

        await Conversation.SendAsync(message, () => Chain.From(() => FormDialog.FromForm(() => Formulario.JsonForm.BuildJsonForm(), FormOptions.PromptFieldsWithValues)));

        return;

    }
}

MessagesController.cs

public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
    var connector = new ConnectorClient(new Uri(activity.ServiceUrl));

    if (activity.Type == ActivityTypes.ConversationUpdate)
    {
        if (activity.MembersAdded.Any(o => o.Id == activity.Recipient.Id))
        {
            var reply = activity.CreateReply();
            reply.Text = "Hello...";
            await connector.Conversations.ReplyToActivityAsync(reply);
        }

    }
    else if (activity.Type == ActivityTypes.Message)
    {
        // HEREE!!!
        await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());

    }
    else
    {
        HandleSystemMessage(activity);
    }
    var response = Request.CreateResponse(HttpStatusCode.OK);
    return response;
}

The response of emulator:

I could not send, Repeat

Nicolas R
  • 13,812
  • 2
  • 28
  • 57
  • Where in this code do you start a new conversation? – stuartd Mar 09 '18 at 10:48
  • I updated the post with code. – Romário Carvalho Mar 09 '18 at 10:54
  • 1
    Have a look at [Start a conversation](https://learn.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-connector#start-a-conversation) – stuartd Mar 09 '18 at 11:56
  • Could you say that if your chatbot receives "ActivityTypes.ConversationUpdate" or the QnA reply for the message contains "form" than the reply is generated correctly? Else are you able to debug locally: https://blog.botframework.com/2017/10/19/debug-channel-locally-using-ngrok/ or eventually via Cloud explorer: https://blogs.msdn.microsoft.com/benjaminperkins/2016/09/22/remote-debug-your-azure-app-service-web-app/ – rudolf_franek Mar 13 '18 at 17:43
  • I feel you need to explain: What is: "Formulario.JsonForm.BuildJsonForm()". What is the relation of your "QnAMakerService" to "QnAMakerDialog.QnAMakerServiceAttribute". Are you using "QnAMakerDialog" version="3.0.0"? And why is your QnAMakerDialog not generic? – rudolf_franek Mar 13 '18 at 18:18

0 Answers0