UNPKG

botbuilder

Version:

Bot Builder is a framework for building rich bots on virtually any platform.

957 lines • 45.1 kB
"use strict"; /** * @module botbuilder */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TeamsActivityHandler = void 0; const botbuilder_core_1 = require("botbuilder-core"); const botframework_connector_1 = require("botframework-connector"); const teamsInfo_1 = require("./teamsInfo"); const z = require("zod"); const TeamsMeetingStartT = z .object({ Id: z.string(), JoinUrl: z.string(), MeetingType: z.string(), Title: z.string(), StartTime: z.string(), }) .nonstrict(); const TeamsMeetingEndT = z .object({ Id: z.string(), JoinUrl: z.string(), MeetingType: z.string(), Title: z.string(), EndTime: z.string(), }) .nonstrict(); /** * Adds support for Microsoft Teams specific events and interactions. * * @remarks * Developers may handle Conversation Update activities sent from Microsoft Teams via two methods: * 1. Overriding methods starting with `on..` and *not* ending in `..Event()` (e.g. `onTeamsMembersAdded()`), or instead * 2. Passing callbacks to methods starting with `on..` *and* ending in `...Event()` (e.g. `onTeamsMembersAddedEvent()`), * to stay in line with older {@see ActivityHandler} implementation. * * Developers should use either #1 or #2, above for all Conversation Update activities and not *both* #2 and #3 for the same activity. Meaning, * developers should override `onTeamsMembersAdded()` and not use both `onTeamsMembersAdded()` and `onTeamsMembersAddedEvent()`. * * Developers wanting to handle Invoke activities *must* override methods starting with `handle...()` (e.g. `handleTeamsTaskModuleFetch()`). */ class TeamsActivityHandler extends botbuilder_core_1.ActivityHandler { /** * Invoked when an invoke activity is received from the connector. * Invoke activities can be used to communicate many different things. * * @param context A context object for this turn. * @returns An Invoke Response for the activity. */ onInvokeActivity(context) { const _super = Object.create(null, { onInvokeActivity: { get: () => super.onInvokeActivity } }); return __awaiter(this, void 0, void 0, function* () { let runEvents = true; try { if (!context.activity.name && context.activity.channelId === 'msteams') { return yield this.handleTeamsCardActionInvoke(context); } else { switch (context.activity.name) { case 'fileConsent/invoke': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsFileConsent(context, context.activity.value)); case 'actionableMessage/executeAction': yield this.handleTeamsO365ConnectorCardAction(context, context.activity.value); return botbuilder_core_1.ActivityHandler.createInvokeResponse(); case 'composeExtension/queryLink': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsAppBasedLinkQuery(context, context.activity.value)); case 'composeExtension/query': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionQuery(context, context.activity.value)); case 'composeExtension/selectItem': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionSelectItem(context, context.activity.value)); case 'composeExtension/submitAction': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionSubmitActionDispatch(context, context.activity.value)); case 'composeExtension/fetchTask': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionFetchTask(context, context.activity.value)); case 'composeExtension/querySettingUrl': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionConfigurationQuerySettingUrl(context, context.activity.value)); case 'composeExtension/setting': yield this.handleTeamsMessagingExtensionConfigurationSetting(context, context.activity.value); return botbuilder_core_1.ActivityHandler.createInvokeResponse(); case 'composeExtension/onCardButtonClicked': yield this.handleTeamsMessagingExtensionCardButtonClicked(context, context.activity.value); return botbuilder_core_1.ActivityHandler.createInvokeResponse(); case 'task/fetch': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsTaskModuleFetch(context, context.activity.value)); case 'task/submit': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsTaskModuleSubmit(context, context.activity.value)); case 'tab/fetch': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsTabFetch(context, context.activity.value)); case 'tab/submit': return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsTabSubmit(context, context.activity.value)); default: runEvents = false; return _super.onInvokeActivity.call(this, context); } } } catch (err) { if (err.message === 'NotImplemented') { return { status: 501 }; } else if (err.message === 'BadRequest') { return { status: 400 }; } throw err; } finally { if (runEvents) { this.defaultNextEvent(context)(); } } }); } /** * Handles a Teams Card Action Invoke activity. * * @param _context A context object for this turn. * @returns An Invoke Response for the activity. */ handleTeamsCardActionInvoke(_context) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'fileConsent/invoke'. Handlers registered here run before * `handleTeamsFileConsentAccept` and `handleTeamsFileConsentDecline`. * Developers are not passed a pointer to the next `handleTeamsFileConsent` handler because the _wrapper_ around * the handler will call `onDialogs` handlers after delegating to `handleTeamsFileConsentAccept` or `handleTeamsFileConsentDecline`. * * @param context A context object for this turn. * @param fileConsentCardResponse Represents the value of the invoke activity sent when the user acts on a file consent card. * @returns A promise that represents the work queued. */ handleTeamsFileConsent(context, fileConsentCardResponse) { return __awaiter(this, void 0, void 0, function* () { switch (fileConsentCardResponse.action) { case 'accept': return yield this.handleTeamsFileConsentAccept(context, fileConsentCardResponse); case 'decline': return yield this.handleTeamsFileConsentDecline(context, fileConsentCardResponse); default: throw new Error('BadRequest'); } }); } /** * Receives invoke activities with Activity name of 'fileConsent/invoke' with confirmation from user * * @remarks * This type of invoke activity occur during the File Consent flow. * @param _context A context object for this turn. * @param _fileConsentCardResponse Represents the value of the invoke activity sent when the user acts on a file consent card. * @returns A promise that represents the work queued. */ handleTeamsFileConsentAccept(_context, _fileConsentCardResponse) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'fileConsent/invoke' with decline from user * * @remarks * This type of invoke activity occur during the File Consent flow. * @param _context A context object for this turn. * @param _fileConsentCardResponse Represents the value of the invoke activity sent when the user acts on a file consent card. * @returns A promise that represents the work queued. */ handleTeamsFileConsentDecline(_context, _fileConsentCardResponse) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'actionableMessage/executeAction'. * * @param _context A context object for this turn. * @param _query The O365 connector card HttpPOST invoke query. * @returns A promise that represents the work queued. */ handleTeamsO365ConnectorCardAction(_context, _query) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Invoked when a signIn invoke activity is received from the connector. * * @param context A context object for this turn. * @returns A promise that represents the work queued. */ onSignInInvoke(context) { return __awaiter(this, void 0, void 0, function* () { switch (context.activity.name) { case botbuilder_core_1.verifyStateOperationName: return yield this.handleTeamsSigninVerifyState(context, context.activity.value); case botbuilder_core_1.tokenExchangeOperationName: return yield this.handleTeamsSigninTokenExchange(context, context.activity.value); } }); } /** * Receives invoke activities with Activity name of 'signin/verifyState'. * * @param _context A context object for this turn. * @param _query Signin state (part of signin action auth flow) verification invoke query. * @returns A promise that represents the work queued. */ handleTeamsSigninVerifyState(_context, _query) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'signin/tokenExchange' * * @param _context A context object for this turn. * @param _query Signin state (part of signin action auth flow) verification invoke query * @returns A promise that represents the work queued. */ handleTeamsSigninTokenExchange(_context, _query) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'composeExtension/onCardButtonClicked' * * @param _context A context object for this turn. * @param _cardData Object representing the card data. * @returns A promise that represents the work queued. */ handleTeamsMessagingExtensionCardButtonClicked(_context, _cardData) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'task/fetch' * * @param _context A context object for this turn. * @param _taskModuleRequest The task module invoke request value payload. * @returns A Task Module Response for the request. */ handleTeamsTaskModuleFetch(_context, _taskModuleRequest) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'task/submit' * * @param _context A context object for this turn. * @param _taskModuleRequest The task module invoke request value payload. * @returns A Task Module Response for the request. */ handleTeamsTaskModuleSubmit(_context, _taskModuleRequest) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'tab/fetch' * * @param _context A context object for this turn. * @param _tabRequest The tab invoke request value payload. * @returns A Tab Response for the request. */ handleTeamsTabFetch(_context, _tabRequest) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'tab/submit' * * @param _context A context object for this turn. * @param _tabSubmit The tab submit invoke request value payload. * @returns A Tab Response for the request. */ handleTeamsTabSubmit(_context, _tabSubmit) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with Activity name of 'composeExtension/queryLink' * * @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. */ handleTeamsAppBasedLinkQuery(_context, _query) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with the name 'composeExtension/query'. * * @remarks * Used in creating a Search-based Message Extension. * @param _context A context object for this turn. * @param _query The query for the search command. * @returns The Messaging Extension Response for the query. */ handleTeamsMessagingExtensionQuery(_context, _query) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with the name 'composeExtension/selectItem'. * * @remarks * Used in creating a Search-based Message Extension. * @param _context A context object for this turn. * @param _query he object representing the query. * @returns The Messaging Extension Response for the query. */ handleTeamsMessagingExtensionSelectItem(_context, _query) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with the name 'composeExtension/submitAction' and dispatches to botMessagePreview-flows as applicable. * * @remarks * A handler registered through this method does not dispatch to the next handler (either `handleTeamsMessagingExtensionSubmitAction`, `handleTeamsMessagingExtensionBotMessagePreviewEdit`, or `handleTeamsMessagingExtensionBotMessagePreviewSend`). * This method exists for developers to optionally add more logic before the TeamsActivityHandler routes the activity to one of the * previously mentioned handlers. * @param context A context object for this turn. * @param action The messaging extension action. * @returns The Messaging Extension Action Response for the action. */ handleTeamsMessagingExtensionSubmitActionDispatch(context, action) { return __awaiter(this, void 0, void 0, function* () { if (action.botMessagePreviewAction) { switch (action.botMessagePreviewAction) { case 'edit': return yield this.handleTeamsMessagingExtensionBotMessagePreviewEdit(context, action); case 'send': return yield this.handleTeamsMessagingExtensionBotMessagePreviewSend(context, action); default: throw new Error('BadRequest'); } } else { return yield this.handleTeamsMessagingExtensionSubmitAction(context, action); } }); } /** * Receives invoke activities with the name 'composeExtension/submitAction'. * * @param _context A context object for this turn. * @param _action The messaging extension action. * @returns The Messaging Extension Action Response for the action. */ handleTeamsMessagingExtensionSubmitAction(_context, _action) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with the name 'composeExtension/submitAction' with the 'botMessagePreview' property present on activity.value. * The value for 'botMessagePreview' is 'edit'. * * @param _context A context object for this turn. * @param _action The messaging extension action. * @returns The Messaging Extension Action Response for the action. */ handleTeamsMessagingExtensionBotMessagePreviewEdit(_context, _action) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with the name 'composeExtension/submitAction' with the 'botMessagePreview' property present on activity.value. * The value for 'botMessagePreview' is 'send'. * * @param _context A context object for this turn. * @param _action The messaging extension action. * @returns The Messaging Extension Action Response for the action. */ handleTeamsMessagingExtensionBotMessagePreviewSend(_context, _action) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with the name 'composeExtension/fetchTask' * * @param _context A context object for this turn. * @param _action The messaging extension action. * @returns The Messaging Extension Action Response for the action. */ handleTeamsMessagingExtensionFetchTask(_context, _action) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with the name 'composeExtension/querySettingUrl' * * @param _context A context object for this turn. * @param _query The Messaging extension query. * @returns The Messaging Extension Action Response for the query. */ handleTeamsMessagingExtensionConfigurationQuerySettingUrl(_context, _query) { return __awaiter(this, void 0, void 0, function* () { throw new Error('NotImplemented'); }); } /** * Receives invoke activities with the name 'composeExtension/setting' * * @param _context A context object for this turn. * @param _settings Object representing the configuration settings. */ handleTeamsMessagingExtensionConfigurationSetting(_context, _settings) { throw new Error('NotImplemented'); } /** * Override this method to change the dispatching of ConversationUpdate activities. * * @param context A context object for this turn. * @returns A promise that represents the work queued. */ dispatchConversationUpdateActivity(context) { const _super = Object.create(null, { dispatchConversationUpdateActivity: { get: () => super.dispatchConversationUpdateActivity } }); return __awaiter(this, void 0, void 0, function* () { if (context.activity.channelId == 'msteams') { const channelData = context.activity.channelData; if (context.activity.membersAdded && context.activity.membersAdded.length > 0) { return yield this.onTeamsMembersAdded(context); } if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) { return yield this.onTeamsMembersRemoved(context); } if (!channelData || !channelData.eventType) { return yield _super.dispatchConversationUpdateActivity.call(this, context); } switch (channelData.eventType) { case 'channelCreated': return yield this.onTeamsChannelCreated(context); case 'channelDeleted': return yield this.onTeamsChannelDeleted(context); case 'channelRenamed': return yield this.onTeamsChannelRenamed(context); case 'teamArchived': return yield this.onTeamsTeamArchived(context); case 'teamDeleted': return yield this.onTeamsTeamDeleted(context); case 'teamHardDeleted': return yield this.onTeamsTeamHardDeleted(context); case 'channelRestored': return yield this.onTeamsChannelRestored(context); case 'teamRenamed': return yield this.onTeamsTeamRenamed(context); case 'teamRestored': return yield this.onTeamsTeamRestored(context); case 'teamUnarchived': return yield this.onTeamsTeamUnarchived(context); default: return yield _super.dispatchConversationUpdateActivity.call(this, context); } } else { return yield _super.dispatchConversationUpdateActivity.call(this, context); } }); } /** * Called in `dispatchConversationUpdateActivity()` to trigger the `'TeamsMembersAdded'` handlers. * Override this in a derived class to provide logic for when members other than the bot * join the channel, such as your bot's welcome logic. * * @remarks * If no handlers are registered for the `'TeamsMembersAdded'` event, the `'MembersAdded'` handlers will run instead. * @param context A context object for this turn. * @returns A promise that represents the work queued. */ onTeamsMembersAdded(context) { return __awaiter(this, void 0, void 0, function* () { if ('TeamsMembersAdded' in this.handlers && this.handlers['TeamsMembersAdded'].length > 0) { for (let i = 0; i < context.activity.membersAdded.length; i++) { const channelAccount = context.activity.membersAdded[i]; // check whether we have a TeamChannelAccount, or the member is the bot if ('givenName' in channelAccount || 'surname' in channelAccount || 'email' in channelAccount || 'userPrincipalName' in channelAccount || context.activity.recipient.id === channelAccount.id) { // we must have a TeamsChannelAccount, or a bot so skip to the next one continue; } try { context.activity.membersAdded[i] = yield teamsInfo_1.TeamsInfo.getMember(context, channelAccount.id); } catch (err) { const errCode = err.body && err.body.error && err.body.error.code; if (errCode === 'ConversationNotFound') { // unable to find the member added in ConversationUpdate Activity in the response from the getMember call const teamsChannelAccount = { id: channelAccount.id, name: channelAccount.name, aadObjectId: channelAccount.aadObjectId, role: channelAccount.role, }; context.activity.membersAdded[i] = teamsChannelAccount; } else { throw err; } } } yield this.handle(context, 'TeamsMembersAdded', this.defaultNextEvent(context)); } else { yield this.handle(context, 'MembersAdded', this.defaultNextEvent(context)); } }); } /** * Called in `dispatchConversationUpdateActivity()` to trigger the `'TeamsMembersRemoved'` handlers. * Override this in a derived class to provide logic for when members other than the bot * leave the channel, such as your bot's good-bye logic. * * @remarks * If no handlers are registered for the `'TeamsMembersRemoved'` event, the `'MembersRemoved'` handlers will run instead. * @param context A context object for this turn. * @returns A promise that represents the work queued. */ onTeamsMembersRemoved(context) { return __awaiter(this, void 0, void 0, function* () { if ('TeamsMembersRemoved' in this.handlers && this.handlers['TeamsMembersRemoved'].length > 0) { yield this.handle(context, 'TeamsMembersRemoved', this.defaultNextEvent(context)); } else { yield this.handle(context, 'MembersRemoved', this.defaultNextEvent(context)); } }); } /** * Invoked when a Channel Created event activity is received from the connector. * Channel Created corresponds to the user creating a new channel. * Override this in a derived class to provide logic for when a channel is created. * * @param context A context object for this turn. * @returns A promise that represents the work queued. */ onTeamsChannelCreated(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsChannelCreated', this.defaultNextEvent(context)); }); } /** * Invoked when a Channel Deleted event activity is received from the connector. * Channel Deleted corresponds to the user deleting a channel. * Override this in a derived class to provide logic for when a channel is deleted. * * @param context A context object for this turn. * @returns A promise that represents the work queued. */ onTeamsChannelDeleted(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsChannelDeleted', this.defaultNextEvent(context)); }); } /** * Invoked when a Channel Renamed event activity is received from the connector. * Channel Renamed corresponds to the user renaming a new channel. * Override this in a derived class to provide logic for when a channel is renamed. * * @param context A context object for this turn. * @returns A promise that represents the work queued. */ onTeamsChannelRenamed(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsChannelRenamed', this.defaultNextEvent(context)); }); } /** * Invoked when a Team Archived event activity is received from the connector. * Team Archived corresponds to the user archiving a team. * Override this in a derived class to provide logic for when a team is archived. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsTeamArchived(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsTeamArchived', this.defaultNextEvent(context)); }); } /** * Invoked when a Team Deleted event activity is received from the connector. * Team Deleted corresponds to the user deleting a team. * Override this in a derived class to provide logic for when a team is deleted. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsTeamDeleted(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsTeamDeleted', this.defaultNextEvent(context)); }); } /** * Invoked when a Team Hard Deleted event activity is received from the connector. * Team Hard Deleted corresponds to the user hard-deleting a team. * Override this in a derived class to provide logic for when a team is hard-deleted. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsTeamHardDeleted(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsTeamHardDeleted', this.defaultNextEvent(context)); }); } /** * * Invoked when a Channel Restored event activity is received from the connector. * Channel Restored corresponds to the user restoring a previously deleted channel. * Override this in a derived class to provide logic for when a channel is restored. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsChannelRestored(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsChannelRestored', this.defaultNextEvent(context)); }); } /** * Invoked when a Team Renamed event activity is received from the connector. * Team Renamed corresponds to the user renaming a team. * Override this in a derived class to provide logic for when a team is renamed. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsTeamRenamed(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsTeamRenamed', this.defaultNextEvent(context)); }); } /** * Invoked when a Team Restored event activity is received from the connector. * Team Restored corresponds to the user restoring a team. * Override this in a derived class to provide logic for when a team is restored. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsTeamRestored(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsTeamRestored', this.defaultNextEvent(context)); }); } /** * Invoked when a Team Unarchived event activity is received from the connector. * Team Unarchived corresponds to the user unarchiving a team. * Override this in a derived class to provide logic for when a team is unarchived. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsTeamUnarchived(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsTeamUnarchived', this.defaultNextEvent(context)); }); } /** * Registers a handler for TeamsMembersAdded events, such as for when members other than the bot * join the channel, such as your bot's welcome logic. * * @param handler A callback to handle the teams members added event. * @returns A promise that represents the work queued. */ onTeamsMembersAddedEvent(handler) { return this.on('TeamsMembersAdded', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(context.activity.membersAdded, teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsMembersRemoved events, such as for when members other than the bot * leave the channel, such as your bot's good-bye logic. * * @param handler A callback to handle the teams members removed event. * @returns A promise that represents the work queued. */ onTeamsMembersRemovedEvent(handler) { return this.on('TeamsMembersRemoved', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(context.activity.membersRemoved, teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsChannelCreated events, such as for when a channel is created. * * @param handler A callback to handle the teams channel created event. * @returns A promise that represents the work queued. */ onTeamsChannelCreatedEvent(handler) { return this.on('TeamsChannelCreated', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.channel, teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsChannelDeleted events, such as for when a channel is deleted. * * @param handler A callback to handle the teams channel deleted event. * @returns A promise that represents the work queued. */ onTeamsChannelDeletedEvent(handler) { return this.on('TeamsChannelDeleted', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.channel, teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsChannelRenamed events, such as for when a channel is renamed. * * @param handler A callback to handle the teams channel renamed event. * @returns A promise that represents the work queued. */ onTeamsChannelRenamedEvent(handler) { return this.on('TeamsChannelRenamed', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.channel, teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsTeamArchived events, such as for when a team is archived. * * @param handler A callback to handle the teams team archived event. * @returns A promise that represents the work queued. */ onTeamsTeamArchivedEvent(handler) { return this.on('TeamsTeamArchived', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsTeamDeleted events, such as for when a team is deleted. * * @param handler A callback to handle the teams team deleted event. * @returns A promise that represents the work queued. */ onTeamsTeamDeletedEvent(handler) { return this.on('TeamsTeamDeleted', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsTeamHardDeleted events, such as for when a team is hard-deleted. * * @param handler A callback to handle the teams team hard deleted event. * @returns A promise that represents the work queued. */ onTeamsTeamHardDeletedEvent(handler) { return this.on('TeamsTeamHardDeleted', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsChannelRestored events, such as for when a channel is restored. * * @param handler A callback to handle the teams channel restored event. * @returns A promise that represents the work queued. */ onTeamsChannelRestoredEvent(handler) { return this.on('TeamsChannelRestored', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.channel, teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsTeamRenamed events, such as for when a team is renamed. * * @param handler A callback to handle the teams team renamed event. * @returns A promise that represents the work queued. */ onTeamsTeamRenamedEvent(handler) { return this.on('TeamsTeamRenamed', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsTeamRestored events, such as for when a team is restored. * * @param handler A callback to handle the teams team restored event. * @returns A promise that represents the work queued. */ onTeamsTeamRestoredEvent(handler) { return this.on('TeamsTeamRestored', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.team, context, next); })); } /** * Registers a handler for TeamsTeamUnarchived events, such as for when a team is unarchived. * * @param handler A callback to handle the teams team unarchived event. * @returns A promise that represents the work queued. */ onTeamsTeamUnarchivedEvent(handler) { return this.on('TeamsTeamUnarchived', (context, next) => __awaiter(this, void 0, void 0, function* () { const teamsChannelData = context.activity.channelData; yield handler(teamsChannelData.team, context, next); })); } /** * Runs the _event_ sub-type handlers, as appropriate, and then continues the event emission process. * * @param context The context object for the current turn. * @returns A promise that represents the work queued. * * @remarks * Override this method to support channel-specific behavior across multiple channels or to add * custom event sub-type events. */ dispatchEventActivity(context) { const _super = Object.create(null, { dispatchEventActivity: { get: () => super.dispatchEventActivity } }); return __awaiter(this, void 0, void 0, function* () { if (context.activity.channelId === botbuilder_core_1.Channels.Msteams) { switch (context.activity.name) { case 'application/vnd.microsoft.readReceipt': return this.onTeamsReadReceipt(context); case 'application/vnd.microsoft.meetingStart': return this.onTeamsMeetingStart(context); case 'application/vnd.microsoft.meetingEnd': return this.onTeamsMeetingEnd(context); } } return _super.dispatchEventActivity.call(this, context); }); } /** * Invoked when a Meeting Started event activity is received from the connector. * Override this in a derived class to provide logic for when a meeting is started. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsMeetingStart(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsMeetingStart', this.defaultNextEvent(context)); }); } /** * Invoked when a Meeting End event activity is received from the connector. * Override this in a derived class to provide logic for when a meeting is ended. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsMeetingEnd(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsMeetingEnd', this.defaultNextEvent(context)); }); } /** * Invoked when a read receipt for a previously sent message is received from the connector. * Override this in a derived class to provide logic for when the bot receives a read receipt event. * * @param context The context for this turn. * @returns A promise that represents the work queued. */ onTeamsReadReceipt(context) { return __awaiter(this, void 0, void 0, function* () { yield this.handle(context, 'TeamsReadReceipt', this.defaultNextEvent(context)); }); } /** * Registers a handler for when a Teams meeting starts. * * @param handler A callback that handles Meeting Start events. * @returns A promise that represents the work queued. */ onTeamsMeetingStartEvent(handler) { return this.on('TeamsMeetingStart', (context, next) => __awaiter(this, void 0, void 0, function* () { const meeting = TeamsMeetingStartT.parse(context.activity.value); yield handler({ id: meeting.Id, joinUrl: meeting.JoinUrl, meetingType: meeting.MeetingType, startTime: new Date(meeting.StartTime), title: meeting.Title, }, context, next); })); } /** * Registers a handler for when a Teams meeting ends. * * @param handler A callback that handles Meeting End events. * @returns A promise that represents the work queued. */ onTeamsMeetingEndEvent(handler) { return this.on('TeamsMeetingEnd', (context, next) => __awaiter(this, void 0, void 0, function* () { const meeting = TeamsMeetingEndT.parse(context.activity.value); yield handler({ id: meeting.Id, joinUrl: meeting.JoinUrl, meetingType: meeting.MeetingType, endTime: new Date(meeting.EndTime), title: meeting.Title, }, context, next); })); } /** * Registers a handler for when a Read Receipt is sent. * * @param handler A callback that handles Read Receipt events. * @returns A promise that represents the work queued. */ onTeamsReadReceiptEvent(handler) { return this.on('TeamsReadReceipt', (context, next) => __awaiter(this, void 0, void 0, function* () { const receiptInfo = context.activity.value; yield handler(new botframework_connector_1.ReadReceiptInfo(receiptInfo.lastReadMessageId), context, next); })); } } exports.TeamsActivityHandler = TeamsActivityHandler; //# sourceMappingURL=teamsActivityHandler.js.map