I have implemented multi turn QnA in our bot and using this class Microsoft.Bot.Builder.AI.QnA.Dialogs.QnAMakerDialog.

Now, I want to extend its functionality so that after mutli turn conversation, bot can ask user if the conversation helped or not? if not then bot will ask to log a ticket with help desk.

I am able to catch the end of multi turn dialog by overriding the Dialog.EndDialogAsync method but not able to start another dialog from there. Please help.

public class QnAMultiTurnBase : QnAMakerDialog
{
    // Dialog Options parameters
    public readonly string DefaultNoAnswer = Configuration.Messages("Troubleshoot", "NoAnswer");//"No QnAMaker answers found.";
    public readonly string DefaultCardTitle = Configuration.Messages("Troubleshoot", "DidYouMean");//"Did you mean:";
    public readonly string DefaultCardNoMatchText = Configuration.Messages("Troubleshoot", "NoneOfTheAbove");//"None of the above.";
    public readonly string DefaultCardNoMatchResponse = Configuration.Messages("Troubleshoot", "Feedback");//"Thanks for the feedback.";

    private readonly BotServices _services;
    private readonly IConfiguration _configuration;
    //private readonly IStatePropertyAccessor<Dictionary<string, string>> troubleshootQuery;
    private readonly Dictionary<string, string> qnaPair = new Dictionary<string, string>();
    private readonly string qnAMakerServiceName;

    /// <summary>
    /// Initializes a new instance of the <see cref="QnAMakerBaseDialog"/> class.
    /// Dialog helper to generate dialogs.
    /// </summary>
    /// <param name="services">Bot Services.</param>
    public QnAMultiTurnBase(BotServices services, IConfiguration configuration, string qnAMakerServiceName) : base()
    {
        this._services = services;
        this._configuration = configuration;
        this.qnAMakerServiceName = qnAMakerServiceName;
    }

    protected async override Task<IQnAMakerClient> GetQnAMakerClientAsync(DialogContext dc)
    {
        return this._services?.QnAServices[qnAMakerServiceName];
    }

    protected override Task<QnAMakerOptions> GetQnAMakerOptionsAsync(DialogContext dc)
    {
        return Task.FromResult(new QnAMakerOptions
        {
            ScoreThreshold = DefaultThreshold,
            Top = DefaultTopN,
            QnAId = 0,
            RankerType = "Default",
            IsTest = false
        });
    }

    protected async override Task<QnADialogResponseOptions> GetQnAResponseOptionsAsync(DialogContext dc)
    {
        var noAnswer = (Activity)Activity.CreateMessageActivity();
        noAnswer.Text = this._configuration["DefaultAnswer"] ?? DefaultNoAnswer;

        var cardNoMatchResponse = MessageFactory.Text(DefaultCardNoMatchResponse);

        var responseOptions = new QnADialogResponseOptions
        {
            ActiveLearningCardTitle = DefaultCardTitle,
            CardNoMatchText = DefaultCardNoMatchText,
            NoAnswer = noAnswer,
            CardNoMatchResponse = cardNoMatchResponse,
        };

        return responseOptions;
    }

    public override Task EndDialogAsync(ITurnContext turnContext, DialogInstance instance, DialogReason reason, CancellationToken cancellationToken = default(CancellationToken))
    {
       try
       {
           // end of multi turn convversation
           // ask if conversation helped the user or not
       }
       catch (Exception)
       {
           turnContext.SendActivityAsync(MessageFactory.Text(Configuration.Messages("UnknownError"))).Wait();
           throw;
       }

       return base.EndDialogAsync(turnContext, instance, reason, cancellationToken);
    }
}
2

There are 2 answers

0
Ram On

You can refer to this documentation where it specifies how to create your own prompts to gather user input. A conversation between a bot and a user often involves asking (prompting) the user for information, parsing the user's response, and then acting on that information.

Dialog actions – ability to control dialogs, BeginDialog, RepeatDialog, GotoDialog, EndDialog, etc.

Please follow the below for multi turn.

https://github.com/microsoft/BotBuilder-Samples/tree/main/samples/csharp_dotnetcore/05.multi-turn-prompt

0
Krishna S On

Add a new dialog and initiate the dialog added using BeginDialogAsync:

AddDialog(new MoreHelp());

return await stepContext.BeginDialogAsync(nameof(MoreHelp), UserInfo, cancellationToken);