Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2020-11-30 15:09:41

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.

  • If I'm in a private chat and "ask" it "deploy cosmosdb", it comes back with the correct answer.
  • If I'm using the bot in a team, by mentioning it "@CS Bot deploy cosmosdb", it doesn't know the anwer.
  • If I mention the bot in the private chat, I see the same behaviour: no answer.

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);
        }
    
Questioner
Krumelur
Viewed
0
Hilton Giesenow 2020-12-01 01:45:13

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.