Skip to content

Commit

Permalink
[JS] fix: ME Auth card title is a fixed string (#1444)
Browse files Browse the repository at this point in the history
## Linked issues

closes: #1445  (issue number)

## Details

Provide a list of your changes here. If you are fixing a bug, please
provide steps to reproduce the bug.

#### Change details
* Updating `MessageExtensionAuthenticationBase` class to take in "title"
and "text" paramters in it's constructor which it then uses to populate
the auth invoke response. If not provided, it uses default hardcoded
strings.
* I've only updated this for `OAuthMessageExtensionAuthentication` as
the `TeamsSsoMessageExtensionAuthentication` settings (TeamsSsoSetting)
does not currently support `title` and `text` properties.

**screenshots**:

I tested it in the ME OAuth bot and the title updated correctly. The
text however did not, it is most likely a frontend issue. I've reached
out to them about it.

![image](https://github.com/microsoft/teams-ai/assets/115390646/aafa8753-80bb-4348-a95d-a87d9d29fc12)


## Attestation Checklist

- [x] My code follows the style guidelines of this project

- I have checked for/fixed spelling, linting, and other errors
- I have commented my code for clarity
- I have made corresponding changes to the documentation (updating the
doc strings in the code is sufficient)
- My changes generate no new warnings
- I have added tests that validates my changes, and provides sufficient
test coverage. I have tested with:
  - Local testing
  - E2E testing in Teams
- New and existing unit tests pass locally with my changes

### Additional information

> Feel free to add other relevant information below
  • Loading branch information
singhk97 committed Mar 25, 2024
1 parent 4be701b commit b3ebaf3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { ActivityTypes, InvokeResponse, TokenResponse, TurnContext } from 'botbuilder';
import { ActivityTypes, CardAction, InvokeResponse, TokenResponse, TurnContext } from 'botbuilder';
import { MessageExtensionsInvokeNames } from '../MessageExtensions';

/**
* @internal
* Base class to handle authentication for Teams Message Extension.
*/
export abstract class MessageExtensionAuthenticationBase {
private readonly title: string;
private readonly text: string;

public constructor(title?: string, text?: string) {
this.title = title ?? 'Bot Service OAuth';
this.text = text ?? "You'll need to signin to use this app.";
}

/**
* Authenticates the user.
* @param {TurnContext} context - The turn context.
Expand Down Expand Up @@ -65,8 +73,10 @@ export abstract class MessageExtensionAuthenticationBase {
{
type: 'openUrl',
value: signInLink,
title: 'Bot Service OAuth'
}
title: this.title,
text: this.text,
displayText: this.text
} as CardAction
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import assert from 'assert';
import * as UserTokenAccess from './UserTokenAccess';
import { OAuthPromptMessageExtensionAuthentication } from './OAuthMessageExtensionAuthentication';

describe('OAuthPromptMessageExtensionAuthentication', () => {
describe('OAuthMessageExtensionAuthentication', () => {
const adapter = new TestAdapter();

const createTurnContextAndState = async (activity: Partial<Activity>): Promise<[TurnContext, TurnState]> => {
Expand Down Expand Up @@ -238,6 +238,7 @@ describe('OAuthPromptMessageExtensionAuthentication', () => {
const settings = {
connectionName: 'connectionName',
title: 'title',
text: 'text',
enableSso: true
};

Expand All @@ -258,9 +259,14 @@ describe('OAuthPromptMessageExtensionAuthentication', () => {
assert(sentActivity.value.body.composeExtension.suggestedActions.actions[0].type == 'openUrl');
assert(sentActivity.value.body.composeExtension.suggestedActions.actions[0].value == 'signInLink');
assert(
sentActivity.value.body.composeExtension.suggestedActions.actions[0].title ==
'Bot Service OAuth'
sentActivity.value.body.composeExtension.suggestedActions.actions[0].title == settings.title
);
assert(sentActivity.value.body.composeExtension.suggestedActions.actions[0].text == settings.text);
assert(
sentActivity.value.body.composeExtension.suggestedActions.actions[0].displayText ==
settings.text
);

// Only one activity should be sent
assert(adapter.getNextReply() == undefined);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class OAuthPromptMessageExtensionAuthentication extends MessageExtensionA
* @param {OAuthSettings} settings The OAuthPromptSettings.
*/
public constructor(private readonly settings: OAuthSettings) {
super();
super(settings.title, settings.text);
}

/**
Expand Down

0 comments on commit b3ebaf3

Please sign in to comment.