OfficeDev/teams-toolkit

commandMiddleware converting all inputs to lowerCase, breaking some command scenarios

Opened this issue · 3 comments

const text = this.getActivityText(turnContext.activity);

I have a command bot. Using these libraries

"dependencies": {
        ...
        "@microsoft/teamsfx": "^2.3.1",
        "botbuilder": "^4.20.0",
        "botbuilder-dialogs": "^4.22.2",
        ...
    }

I am building a sso command which accepts Teams meeting "JoinWebUrl" and get meeting details and responds to the user. In handleCommandReceived method it receives the user entered "JoinWebUrl" in all lower case which does not work for Teams meeting API as the URL contains "case sensitive" encoded meeting identifier. So if everything is converted to lower case API fails.

This is happening for me in TeamsFxBotSsoCommandHandler not sure about other handler

I tried getting original text entered from the "context" object, but it is coming "undefined"

  async handleCommandReceived(
    context: TurnContext,
    message: CommandMessage,
    tokenResponse: TeamsBotSsoPromptTokenResponse
  ): Promise<string | Partial<Activity> | void> {
    console.log(`App received message: ${message.text}`);
    console.log(message); 
    console.log(message.text); //all lower case
    console.log(context.activity.text); //undefined
 
    /*
    const joinWebUrl: string = message.matches[1];
    const graphService = new GraphService(tokenResponse.ssoToken);

    const meetingId: string = await graphService.getMeetingId(joinWebUrl);
    }
    */
  }

Question 1: Is there any way I can retrieve original entered text?
Question 2: Can the SDK be updated to return original text entered by user in "CommandMessage" object OR more appropriate way?

Hi, @NWH-SAmin5 ,

Question 1: Is there any way I can retrieve original entered text?

for command bot, the message user entered will be trimmed, and convert to lower cases to match the command TriggerPatterns.

Due to SSO command bot would run into multiple turns to get the SSO token, so the context.activity.text will be lost, there is no easy way to get the original text directly.

Question 2: Can the SDK be updated to return original text entered by user in "CommandMessage" object OR more appropriate way?

To get original text, you can rewrite defaultBotSsoExecutionActivityHandler, in this handler, you can implement your own BotSsoExecutionActivityHandler to save the context value.

Here are the steps:

  • Copy defaultBotSsoExecutionActivityHandler.ts to your code, and update it to save context value

  • In the internal/initilize.ts file, put the custom bot sso execution activity handler to bot sso config

  • In the profileSsoCommandHandler.ts file, get saved context value

There is a sample project with above steps for your reference:

https://github.com/SLdragon/sso-command-bot-get-message-context

@SLdragon I have implemented as you have suggested. It does let me access original context. If there is an update to defaultBotSsoExecutionActivityHandler.ts from Teams Toolkit SDK on this file, it will have to be included in my custom file manually. correct?

Is it true, when we define custom BotSsoExecutionActivityHandler it will ignore Default BotSsoExecutionActivityHandler?

@SLdragon I have implemented as you have suggested. It does let me access original context. If there is an update to defaultBotSsoExecutionActivityHandler.ts from Teams Toolkit SDK on this file, it will have to be included in my custom file manually. correct?

Is it true, when we define custom BotSsoExecutionActivityHandler it will ignore Default BotSsoExecutionActivityHandler?

Yes, that's true, your custom BotSsoExecutionActivityHandler will override the defaultBotSsoExecutionActivityHandler file inside the SDK.