OfficeDev / teams-toolkit

Developer tools for building Teams apps
Other
442 stars 174 forks source link

commandMiddleware converting all inputs to lowerCase, breaking some command scenarios #11793

Closed NWH-SAmin5 closed 2 days ago

NWH-SAmin5 commented 1 month ago

https://github.com/OfficeDev/teams-toolkit/blob/6e69e41c02faffa613d93c2f63f091cdfdf1fd6d/packages/sdk/src/conversation/sso/botSsoExecutionDialog.ts#L223

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?

SLdragon commented 1 month ago

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:

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

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

NWH-SAmin5 commented 1 month ago

@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 commented 1 month ago

@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.

adashen commented 2 days ago

Close as questions are answered and no further discussion