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

feat: Add new handler for anonymous query link invoke #4348

Merged
merged 4 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libraries/botbuilder/etc/botbuilder.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export class StreamingHttpClient implements HttpClient {
export class TeamsActivityHandler extends ActivityHandler {
protected dispatchConversationUpdateActivity(context: TurnContext): Promise<void>;
protected dispatchEventActivity(context: TurnContext): Promise<void>;
protected handleTeamsAnonymousAppBasedLinkQuery(_context: TurnContext, _query: AppBasedLinkQuery): Promise<MessagingExtensionResponse>;
protected handleTeamsAppBasedLinkQuery(_context: TurnContext, _query: AppBasedLinkQuery): Promise<MessagingExtensionResponse>;
protected handleTeamsCardActionInvoke(_context: TurnContext): Promise<InvokeResponse>;
protected handleTeamsFileConsent(context: TurnContext, fileConsentCardResponse: FileConsentCardResponse): Promise<void>;
Expand Down
21 changes: 21 additions & 0 deletions libraries/botbuilder/src/teamsActivityHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export class TeamsActivityHandler extends ActivityHandler {
await this.handleTeamsAppBasedLinkQuery(context, context.activity.value)
);

case 'composeExtension/anonymousQueryLink':
return ActivityHandler.createInvokeResponse(
await this.handleTeamsAnonymousAppBasedLinkQuery(context, context.activity.value)
);

case 'composeExtension/query':
return ActivityHandler.createInvokeResponse(
await this.handleTeamsMessagingExtensionQuery(context, context.activity.value)
Expand Down Expand Up @@ -381,6 +386,22 @@ export class TeamsActivityHandler extends ActivityHandler {
throw new Error('NotImplemented');
}

/**
* Receives invoke activities with Activity name of 'composeExtension/anonymousQueryLink'
*
* @remarks
* Used in creating a Search-based Message Extension.
* @param _context A context object for this turn.
* @param _query he invoke request body type for app-based link query.
* @returns The Messaging Extension Response for the query.
*/
protected async handleTeamsAnonymousAppBasedLinkQuery(
_context: TurnContext,
_query: AppBasedLinkQuery
): Promise<MessagingExtensionResponse> {
throw new Error('NotImplemented');
}

/**
* Receives invoke activities with the name 'composeExtension/query'.
*
Expand Down
21 changes: 20 additions & 1 deletion libraries/botbuilder/tests/teamsActivityHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ describe('TeamsActivityHandler', function () {

handleTeamsAppBasedLinkQuery() {}

handleTeamsAnonymousAppBasedLinkQuery() {}

handleTeamsMessagingExtensionQuery() {}

handleTeamsMessagingExtensionSelectItem() {}
Expand Down Expand Up @@ -120,7 +122,24 @@ describe('TeamsActivityHandler', function () {
.startTest();
});

it('activity.name is "composeExtension/queryLink". should return status code [200] when handleTeamsAppBasedLinkQuery method is overridden.', async function () {
it('activity.name is "composeExtension/anonymousQueryLink". should return status code [200] when handleTeamsAppBasedLinkQuery method is overridden.', async function () {
const bot = new InvokeActivityEmptyHandlers();

const adapter = new TestAdapter(async (context) => {
await bot.run(context);
});

const activity = createInvokeActivity('composeExtension/anonymousQueryLink');

await adapter
.send(activity)
.assertReply((activity) => {
assert.strictEqual(activity.value.status, 200, 'should be status code 200.');
})
.startTest();
});

it('activity.name is "composeExtension/queryLink". should return status code [200] when handleTeamsAnonymousAppBasedLinkQuery method is overridden.', async function () {
const bot = new InvokeActivityEmptyHandlers();

const adapter = new TestAdapter(async (context) => {
Expand Down