Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
NWH-SAmin5 opened this issue Jun 10, 2024 · 4 comments
Assignees
Labels

Comments

@NWH-SAmin5
Copy link

NWH-SAmin5 commented Jun 10, 2024

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?

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs attention This issue needs the attention of a contributor. label Jun 10, 2024
@adashen adashen added TA:Infra Team Area: Infra investigating labels Jun 11, 2024
@qinezh qinezh assigned SLdragon and unassigned qinezh Jun 11, 2024
@SLdragon
Copy link
Contributor

SLdragon commented Jun 12, 2024

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

@adashen adashen removed the needs attention This issue needs the attention of a contributor. label Jun 12, 2024
@NWH-SAmin5
Copy link
Author

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

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs attention This issue needs the attention of a contributor. label Jun 14, 2024
@SLdragon
Copy link
Contributor

@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 adashen added TA:Auth Team Area: Auth and removed TA:Infra Team Area: Infra needs attention This issue needs the attention of a contributor. labels Jun 18, 2024
@adashen
Copy link
Contributor

adashen commented Aug 2, 2024

Close as questions are answered and no further discussion

@adashen adashen closed this as completed Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants