user9980132
user9980132

Reputation: 21

How to check the messages posted by the Bot in dialog for Microsoft botbuilder?

I'm creating a chatbot in .NET using Microsoft botbuilder and using the web app bot code as my template. I can't find the variable that contains the text of what is being posted from the bot to the user from the qna maker. I'm currently creating another dialog after each time the bot answers a user's question, but I don't want the bot to do this when the default message is being posted. When I'm debugging I can't seem to find where the answer from the qnamaker is stored.

If anyone know where the answer is being stored and how to access it that would be really helpful, or possibly check the most recent message in the dialog.

Currently my root dialog has this snippet:

await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);

the forwarded method is to:

private async Task AfterAnswerAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
        {
            context.Call(new PostAnswerDialog(), AfterPost);

        }

I want to do check if the bot responds with the default message before the context.Call(new PostAnswerDialog(), AfterPost) and if it has then do something else.

Upvotes: 1

Views: 545

Answers (1)

Nicolas R
Nicolas R

Reputation: 14619

You will have to customize your QnAMakerDialog. The sources are available here to understand how it works.

For example you could override the DefaultWaitNextMessageAsync method which is called at the end of the process (when there is a match or not):

// Dialog for QnAMaker GA service
[Serializable]
public class BasicQnAMakerDialog : QnAMakerDialog
{
    // Go to https://qnamaker.ai and feed data, train & publish your QnA Knowledgebase.
    // Parameters to QnAMakerService are:
    // Required: qnaAuthKey, knowledgebaseId, endpointHostName
    // Optional: defaultMessage, scoreThreshold[Range 0.0 – 1.0]
    public BasicQnAMakerDialog() : base(new QnAMakerService(new QnAMakerAttribute(ConfigurationManager.AppSettings["QnAAuthKey"], ConfigurationManager.AppSettings["QnAKnowledgebaseId"], "No good match in FAQ.", 0.5, 1, ConfigurationManager.AppSettings["QnAEndpointHostName"])))
    {
    }

    protected override async Task DefaultWaitNextMessageAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
    {
        if (result.Answers.Count > 0)
        {
            // DO YOUR LOGIC HERE
            await context.PostAsync("Case where you have matching results");
        }

        await base.DefaultWaitNextMessageAsync(context, message, result);
    }
}

Upvotes: 1

Related Questions