2

I've been trying to build a bot that uses QnA to anser the user based on categories. I've managed to connect to QnA correctly and get the first level prompted to the user, however, the problem appears when I try to send to QnA another response from the user.

Here's the dialog that runs smoothly on it's first request.

private async Task<DialogTurnResult> InicioRRHHDialog(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
    string intentForQna = IntentEnum.DISPATCH_RRHH;
    var castContextForQna = (WaterfallStepContext)stepContext.Parent;
    var contextForNextStep = stepContext.Context;
    await GetQnaConnection(castContextForQna, intentForQna);
    return await stepContext.NextAsync(contextForNextStep, cancellationToken);
}

This is the GetQnaConnection being called.

private async Task GetQnaConnection(WaterfallStepContext stepContext, string intent)
{
    servicioQNA = new QnAMakerService(this._qnaService.Url, _qnaRRHHkbId, this._qnaService.QnaEndPointKey);
    var mensaje = await servicioQNA.QueryQnAServiceAsync(intent, null);
    await ShowResults(stepContext, mensaje);
}

And lastly the ShowResults method that I use to send the activity back to the user.

private static async Task ShowResults(WaterfallStepContext stepContext, QnAResult[] mensaje)
{
    Activity outputActivity = null;
    QnABotState newState = null;
    var qnaAnswer = mensaje[0].Answer;
    var prompts = mensaje[0].Context?.Prompts;

    if (prompts == null || prompts.Length < 1)
        outputActivity = MessageFactory.Text(qnaAnswer);
    else
    {
        newState = new QnABotState
        {
            PreviousQnaId = mensaje[0].Id,
            PreviousUserQuery = stepContext.Result.ToString()
        };

        outputActivity = CardHelper.GetHeroCard(qnaAnswer, prompts);
    }
    var outputs = new Activity[] { outputActivity };
    foreach (var activity in outputs)
        await stepContext.Context.SendActivityAsync(activity).ConfigureAwait(false);
}

Am I handling the Qna connection correctly?

0 Answers0