1

I have a developed a chat bot using v4 and C#. first it was deployed to web, now we added bot into MS teams. In teams, chat bot is not responding with accurate answers from QnA service, however the same question gets answered with correct one in Web. We've found the reason, that the chat bot name (@ChatBot) gets appended in front of the question, that in turn changes the question structure.

I tried the methods RemoveMentionText(turnContext.Activity.Id); and RemoveRecipientMention, but no luck so far.

Is there a way i can remove the chat bot name from the question before calling the QnA or Luis service. ? Please help

Tried the below code, but didnt work out.

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
    if (turnContext.Activity.Type == ActivityTypes.Message)
    {
        query = turnContext.Activity.Text;

        if (turnContext.Activity.ChannelId == "msteams")
        {
            // I WANT TO ADD CODE HERE TO REMOVE THE @MENTIONS FROM QUESTION, BEFORE CALLING THE QNA Service.
            // incoming query ->  turnContext.Activity.Text value "<at> chat bot name </a> what is sharepoint? "
            // modified query -> turnContext.Activity.Text value "what is sharepoint? "       
        }
        var qnaResponse = await _services.QnAServices[QnAMakerKey].GetAnswersAsync(turnContext);

        if (qnaResponse[0].Score < .70)
        {
            await turnContext.SendActivityAsync("I'm having some trouble understanding what you mean. Could you please rephrase your question?", cancellationToken: cancellationToken);
        }
        else
        {
            await turnContext.SendActivityAsync(qnaResponse[0].Answer, cancellationToken: cancellationToken);
        }

    }
}  

1 Answers1

1

Your problem is here:

query = turnContext.Activity.Text;

You're defining query and then when/if you call turnContext.Activity.RemoveRecipientMention(), it changes turnContext.Activity.Text, but not query.

All you need to do is remove the mention before defining query:

public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
    if (turnContext.Activity.Type == ActivityTypes.Message)
    {
        turnContext.Activity.RemoveRecipientMention();

        query = turnContext.Activity.Text;

        if (turnContext.Activity.ChannelId == "msteams")
        {
            // I WANT TO ADD CODE HERE TO REMOVE THE @MENTIONS FROM QUESTION, BEFORE CALLING THE QNA Service.
            // incoming query ->  turnContext.Activity.Text value "<at> chat bot name </a> what is sharepoint? "
            // modified query -> turnContext.Activity.Text value "what is sharepoint? "       
        }
        var qnaResponse = await _services.QnAServices[QnAMakerKey].GetAnswersAsync(turnContext);

        if (qnaResponse[0].Score < .70)
        {
            await turnContext.SendActivityAsync("I'm having some trouble understanding what you mean. Could you please rephrase your question?", cancellationToken: cancellationToken);
        }
        else
        {
            await turnContext.SendActivityAsync(qnaResponse[0].Answer, cancellationToken: cancellationToken);
        }

    }
}  
mdrichardson
  • 7,141
  • 1
  • 7
  • 21