2
votes

enter image description here we are facing an issue while developing a chat bot using Microsoft Botframework V4 hosted on Azure. The Chat has issues when published in a MS Teams Channel but, the same Chatbot works fine on MS Teams Private Chat and even Web Chat i.e. All pointing to the same Microsoft APP ID on Azure.

From Within MS Teams Channel:

The ChatBot gets an incorrect User utterance when user chats to ChatBot from within a MS Teams Channel.

Bug:###

 As visible in the screenshot, User types “hi” and the Chat Bot returns the text “VA Check ID Bothi” from the Chat Step Context (stepContext.Context.Activity.Text) . This is incorrect as, the Bot Name "VA Check ID Bot" is getting included in the user utterance. • Therefore the Incorrect Intent is getting recognized by LUIS i.e. the “Help” Intent.

 A simple echo Bot also has the same issue when published in a Teams Channel, but work fine in a MS Teams Private Chat.

From Within Teams Private Chat

o The Chat Bot gets a correct User utterance, when user chats to the same chat bot from within a private chat on MS Teams. o As you can see in the screen shot,the User types “hi” and the Chat Bot returns the same text “hi” from the Chat Step Context (stepContext.Context.Activity.Text). This is correct.

 Therefore the correct Intent is getting recognized by LUIS i.e. the “Greeting” Intent.

Since its the same chatbot with the same MS APP ID hosted on MS Azure, the Chatbot should behave the same when used from within MS Teams Private Chat or MS teams Channel.

The Chatbot also works perfectly fine in Web Chat on Azure Portal

2

2 Answers

4
votes

Yes this is the working behavior for a long time in Microsoft Teams.

What we did was adding a MicrosoftTeamsMiddleware that basically checks the activity.ChannelId and if it is msteams replace the bot name in the activity.Text.

You can access the activity since the middleware receives the ITurnContext. Modifications to this activity are seen by the rest of the pipeline so everything works smoothly and the rest of the bot is unaware of this problem.

I recommend that you inspect/log the activity text because in our case it would be something like <at>Bot Name</at>. So you need to replace all of that with an empty string.

If you also use a middleware for querying LUIS, make sure this new middleware is registered before the LUIS middleware so that the activity.Text is fine before the LUIS middleware acts.

0
votes

You could use a middleware like Andre suggested, but I just straight up did a regex replace on activity.text for every activity. You are going to see the tags from teams, but I also covered @ just in case. Here are the scenarios I covered:

  • Mention starts with @ or <at> (and optional check for trailing </at>)
  • Mention uses bot short name (e.g. YourBot)
  • Mention uses bot long name (e.g. Your Bot Long Name)
  • Mention may be followed by a space (it's possible it will not be)

Here is my code. I am using nodejs and this bot used an older 4.3 template for core_bot but similar method should work for C# and other SDK versions.

async onTurn(context) {
    if (context.activity.type === ActivityTypes.Message) {
        context._activity.text = context._activity.text.replace(/(@|<at>)((YourBot)|(Your Bot Long Name))(<\/at>)? ?/g, '');

        const results = await this.luisRecognizer.recognize(context);

That covers all the scenarios above. Since I do this at the beginning of the turn before I call the LUIS recognizer and/or QnA Maker, the text sent to those services does not contain the mention.