How can i use QnAMaker to provide random answers to same query
Asked Answered
S

1

5

I was thinking as bots have some generic questions like how are you ? may be i have around 10 answers which i would like Q&A maker to choose randomly not every time same answer.

or also questions like tell me a story

Sedge answered 21/6, 2018 at 15:6 Comment(0)
S
7

some generic questions like how are you ? may be i have around 10 answers which i would like Q&A maker to choose randomly not every time same answer.

To achieve this requirement, you can try this approach:

1) Add a QnA pair and use a special character (such as |) to split answers for question how are you?

enter image description here

2) Override the RespondFromQnAMakerResultAsync method, and split response and retrieve answer randomly in this method

protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result)
{
    // This will only be called if Answers isn't empty

    var response = result.Answers.First().Answer;
    var answersforhowareyou = response.Split('|');

    if (answersforhowareyou.Count() > 1)
    {
        Random rnd = new Random();
        int index = rnd.Next(answersforhowareyou.Count());

        response = answersforhowareyou[index];
    }

    await context.PostAsync(response);
}

Test result:

enter image description here

Sobriety answered 22/6, 2018 at 5:22 Comment(1)
Thank you , for this custom solution ideaSedge

© 2022 - 2024 — McMap. All rights reserved.