Krumelur
Krumelur

Reputation: 33048

QnA Maker Bot working in Teams private chats, but no answers when mentioned in team

I configured a knowledge base at qnamaker.ai, published it, and created a bot using Azure Bot Service.

In Teams, I created a new bot app and associated it with the deployed bot. The bot is allowed for private chats, group chats, and teams.

But to talk to the bot it MUST be mentioned, so where's the problem here?

enter image description here

UPDATE:

Thanks to Hilton's answer below, I noticed that when you download the bot source code (in my case, it's a dotnet core project), the README.MD file states this issue and how to fix it:

Microsoft Teams channel group chat fix

  • Goto Bot/QnABot.cs
  • Add References
    using Microsoft.Bot.Connector;
    using System.Text.RegularExpressions;
    
  • Modify OnTurnAsync function as:
    public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default)
        {
            // Teams group chat
            if (turnContext.Activity.ChannelId.Equals(Channels.Msteams))
            {
                turnContext.Activity.Text = turnContext.Activity.RemoveRecipientMention();
            }
    
            await base.OnTurnAsync(turnContext, cancellationToken);
    
            // Save any state changes that might have occurred during the turn.
            await ConversationState.SaveChangesAsync(turnContext, false, cancellationToken);
            await UserState.SaveChangesAsync(turnContext, false, cancellationToken);
        }
    

Upvotes: 0

Views: 199

Answers (1)

Hilton Giesenow
Hilton Giesenow

Reputation: 10804

If you inspect the text that comes back in the 1st message, it will be "deploy cosmosdb". In the 2nd message though, it will be "CS Bot deploy cosmosdb" which the QnAMaker is struggling to parse. What you want to do, before passing the query text to QnAMaker, is to remove the "@" mention entirely from the text.

This is a common issue, so the Bot Framework already has a method to deal with this. You haven't mentioned what platform you're developing on, but here is a link for dotnet to the RemoveRecipientMention method. I'm pretty sure there's an equivalent on Node, etc.

The final effect would be to convert your Activity's Text to be the same in both cases, which would result in the same response from QnAMaker.

Upvotes: 1

Related Questions