UNPKG

43.7 kBJavaScriptView Raw
1"use strict";
2/**
3 * @module botbuilder
4 */
5/**
6 * Copyright (c) Microsoft Corporation. All rights reserved.
7 * Licensed under the MIT License.
8 */
9var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
10 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11 return new (P || (P = Promise))(function (resolve, reject) {
12 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
14 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
15 step((generator = generator.apply(thisArg, _arguments || [])).next());
16 });
17};
18Object.defineProperty(exports, "__esModule", { value: true });
19exports.TeamsActivityHandler = void 0;
20const botbuilder_core_1 = require("botbuilder-core");
21const teamsInfo_1 = require("./teamsInfo");
22const z = require("zod");
23const TeamsMeetingStartT = z
24 .object({
25 Id: z.string(),
26 JoinUrl: z.string(),
27 MeetingType: z.string(),
28 Title: z.string(),
29 StartTime: z.string(),
30})
31 .nonstrict();
32const TeamsMeetingEndT = z
33 .object({
34 Id: z.string(),
35 JoinUrl: z.string(),
36 MeetingType: z.string(),
37 Title: z.string(),
38 EndTime: z.string(),
39})
40 .nonstrict();
41/**
42 * Adds support for Microsoft Teams specific events and interactions.
43 * @remarks
44 * Developers may handle Conversation Update activities sent from Microsoft Teams via two methods:
45 * 1. Overriding methods starting with `on..` and *not* ending in `..Event()` (e.g. `onTeamsMembersAdded()`), or instead
46 * 2. Passing callbacks to methods starting with `on..` *and* ending in `...Event()` (e.g. `onTeamsMembersAddedEvent()`),
47 * to stay in line with older {@see ActivityHandler} implementation.
48 *
49 * Developers should use either #1 or #2, above for all Conversation Update activities and not *both* #2 and #3 for the same activity. Meaning,
50 * developers should override `onTeamsMembersAdded()` and not use both `onTeamsMembersAdded()` and `onTeamsMembersAddedEvent()`.
51 *
52 * Developers wanting to handle Invoke activities *must* override methods starting with `handle...()` (e.g. `handleTeamsTaskModuleFetch()`).
53 */
54class TeamsActivityHandler extends botbuilder_core_1.ActivityHandler {
55 /**
56 * Invoked when an invoke activity is received from the connector.
57 * Invoke activities can be used to communicate many different things.
58 * @param context A context object for this turn.
59 * @returns An Invoke Response for the activity.
60 */
61 onInvokeActivity(context) {
62 const _super = Object.create(null, {
63 onInvokeActivity: { get: () => super.onInvokeActivity }
64 });
65 return __awaiter(this, void 0, void 0, function* () {
66 let runEvents = true;
67 try {
68 if (!context.activity.name && context.activity.channelId === 'msteams') {
69 return yield this.handleTeamsCardActionInvoke(context);
70 }
71 else {
72 switch (context.activity.name) {
73 case 'fileConsent/invoke':
74 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsFileConsent(context, context.activity.value));
75 case 'actionableMessage/executeAction':
76 yield this.handleTeamsO365ConnectorCardAction(context, context.activity.value);
77 return botbuilder_core_1.ActivityHandler.createInvokeResponse();
78 case 'composeExtension/queryLink':
79 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsAppBasedLinkQuery(context, context.activity.value));
80 case 'composeExtension/query':
81 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionQuery(context, context.activity.value));
82 case 'composeExtension/selectItem':
83 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionSelectItem(context, context.activity.value));
84 case 'composeExtension/submitAction':
85 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionSubmitActionDispatch(context, context.activity.value));
86 case 'composeExtension/fetchTask':
87 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionFetchTask(context, context.activity.value));
88 case 'composeExtension/querySettingUrl':
89 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsMessagingExtensionConfigurationQuerySettingUrl(context, context.activity.value));
90 case 'composeExtension/setting':
91 yield this.handleTeamsMessagingExtensionConfigurationSetting(context, context.activity.value);
92 return botbuilder_core_1.ActivityHandler.createInvokeResponse();
93 case 'composeExtension/onCardButtonClicked':
94 yield this.handleTeamsMessagingExtensionCardButtonClicked(context, context.activity.value);
95 return botbuilder_core_1.ActivityHandler.createInvokeResponse();
96 case 'task/fetch':
97 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsTaskModuleFetch(context, context.activity.value));
98 case 'task/submit':
99 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsTaskModuleSubmit(context, context.activity.value));
100 case 'tab/fetch':
101 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsTabFetch(context, context.activity.value));
102 case 'tab/submit':
103 return botbuilder_core_1.ActivityHandler.createInvokeResponse(yield this.handleTeamsTabSubmit(context, context.activity.value));
104 default:
105 runEvents = false;
106 return _super.onInvokeActivity.call(this, context);
107 }
108 }
109 }
110 catch (err) {
111 if (err.message === 'NotImplemented') {
112 return { status: 501 };
113 }
114 else if (err.message === 'BadRequest') {
115 return { status: 400 };
116 }
117 throw err;
118 }
119 finally {
120 if (runEvents) {
121 this.defaultNextEvent(context)();
122 }
123 }
124 });
125 }
126 /**
127 * Handles a Teams Card Action Invoke activity.
128 * @param context A context object for this turn.
129 * @returns An Invoke Response for the activity.
130 */
131 handleTeamsCardActionInvoke(context) {
132 return __awaiter(this, void 0, void 0, function* () {
133 throw new Error('NotImplemented');
134 });
135 }
136 /**
137 * Receives invoke activities with Activity name of 'fileConsent/invoke'. Handlers registered here run before
138 * `handleTeamsFileConsentAccept` and `handleTeamsFileConsentDecline`.
139 * Developers are not passed a pointer to the next `handleTeamsFileConsent` handler because the _wrapper_ around
140 * the handler will call `onDialogs` handlers after delegating to `handleTeamsFileConsentAccept` or `handleTeamsFileConsentDecline`.
141 * @param context A context object for this turn.
142 * @param fileConsentCardResponse Represents the value of the invoke activity sent when the user acts on a file consent card.
143 * @returns A promise that represents the work queued.
144 */
145 handleTeamsFileConsent(context, fileConsentCardResponse) {
146 return __awaiter(this, void 0, void 0, function* () {
147 switch (fileConsentCardResponse.action) {
148 case 'accept':
149 return yield this.handleTeamsFileConsentAccept(context, fileConsentCardResponse);
150 case 'decline':
151 return yield this.handleTeamsFileConsentDecline(context, fileConsentCardResponse);
152 default:
153 throw new Error('BadRequest');
154 }
155 });
156 }
157 /**
158 * Receives invoke activities with Activity name of 'fileConsent/invoke' with confirmation from user
159 * @remarks
160 * This type of invoke activity occur during the File Consent flow.
161 * @param context A context object for this turn.
162 * @param fileConsentCardResponse Represents the value of the invoke activity sent when the user acts on a file consent card.
163 * @returns A promise that represents the work queued.
164 */
165 handleTeamsFileConsentAccept(context, fileConsentCardResponse) {
166 return __awaiter(this, void 0, void 0, function* () {
167 throw new Error('NotImplemented');
168 });
169 }
170 /**
171 * Receives invoke activities with Activity name of 'fileConsent/invoke' with decline from user
172 * @remarks
173 * This type of invoke activity occur during the File Consent flow.
174 * @param context A context object for this turn.
175 * @param fileConsentCardResponse Represents the value of the invoke activity sent when the user acts on a file consent card.
176 * @returns A promise that represents the work queued.
177 */
178 handleTeamsFileConsentDecline(context, fileConsentCardResponse) {
179 return __awaiter(this, void 0, void 0, function* () {
180 throw new Error('NotImplemented');
181 });
182 }
183 /**
184 * Receives invoke activities with Activity name of 'actionableMessage/executeAction'.
185 * @param context A context object for this turn.
186 * @param query The O365 connector card HttpPOST invoke query.
187 * @returnsa A promise that represents the work queued.
188 */
189 handleTeamsO365ConnectorCardAction(context, query) {
190 return __awaiter(this, void 0, void 0, function* () {
191 throw new Error('NotImplemented');
192 });
193 }
194 /**
195 * Invoked when a signIn invoke activity is received from the connector.
196 * @param context A context object for this turn.
197 * @returns A promise that represents the work queued.
198 */
199 onSignInInvoke(context) {
200 return __awaiter(this, void 0, void 0, function* () {
201 switch (context.activity.name) {
202 case botbuilder_core_1.verifyStateOperationName:
203 return yield this.handleTeamsSigninVerifyState(context, context.activity.value);
204 case botbuilder_core_1.tokenExchangeOperationName:
205 return yield this.handleTeamsSigninTokenExchange(context, context.activity.value);
206 }
207 });
208 }
209 /**
210 * Receives invoke activities with Activity name of 'signin/verifyState'.
211 * @param context A context object for this turn.
212 * @param query Signin state (part of signin action auth flow) verification invoke query.
213 * @returns A promise that represents the work queued.
214 */
215 handleTeamsSigninVerifyState(context, query) {
216 return __awaiter(this, void 0, void 0, function* () {
217 throw new Error('NotImplemented');
218 });
219 }
220 /**
221 * Receives invoke activities with Activity name of 'signin/tokenExchange'
222 * @param context A context object for this turn.
223 * @param query Signin state (part of signin action auth flow) verification invoke query
224 * @returns A promise that represents the work queued.
225 */
226 handleTeamsSigninTokenExchange(context, query) {
227 return __awaiter(this, void 0, void 0, function* () {
228 throw new Error('NotImplemented');
229 });
230 }
231 /**
232 * Receives invoke activities with Activity name of 'composeExtension/onCardButtonClicked'
233 * @param context A context object for this turn.
234 * @param cardData Object representing the card data.
235 * @returns A promise that represents the work queued.
236 */
237 handleTeamsMessagingExtensionCardButtonClicked(context, cardData) {
238 return __awaiter(this, void 0, void 0, function* () {
239 throw new Error('NotImplemented');
240 });
241 }
242 /**
243 * Receives invoke activities with Activity name of 'task/fetch'
244 * @param context A context object for this turn.
245 * @param taskModuleRequest The task module invoke request value payload.
246 * @returns A Task Module Response for the request.
247 */
248 handleTeamsTaskModuleFetch(context, taskModuleRequest) {
249 return __awaiter(this, void 0, void 0, function* () {
250 throw new Error('NotImplemented');
251 });
252 }
253 /**
254 * Receives invoke activities with Activity name of 'task/submit'
255 * @param context A context object for this turn.
256 * @param taskModuleRequest The task module invoke request value payload.
257 * @returns A Task Module Response for the request.
258 */
259 handleTeamsTaskModuleSubmit(context, taskModuleRequest) {
260 return __awaiter(this, void 0, void 0, function* () {
261 throw new Error('NotImplemented');
262 });
263 }
264 /**
265 * Receives invoke activities with Activity name of 'tab/fetch'
266 * @param context A context object for this turn.
267 * @param tabRequest The tab invoke request value payload.
268 * @returns A Tab Response for the request.
269 */
270 handleTeamsTabFetch(context, tabRequest) {
271 return __awaiter(this, void 0, void 0, function* () {
272 throw new Error('NotImplemented');
273 });
274 }
275 /**
276 * Receives invoke activities with Activity name of 'tab/submit'
277 * @param context A context object for this turn.
278 * @param tabSubmit The tab submit invoke request value payload.
279 * @returns A Tab Response for the request.
280 */
281 handleTeamsTabSubmit(context, tabSubmit) {
282 return __awaiter(this, void 0, void 0, function* () {
283 throw new Error('NotImplemented');
284 });
285 }
286 /**
287 * Receives invoke activities with Activity name of 'composeExtension/queryLink'
288 * @remarks
289 * Used in creating a Search-based Message Extension.
290 * @param context A context object for this turn.
291 * @param query he invoke request body type for app-based link query.
292 * @returns The Messaging Extension Response for the query.
293 */
294 handleTeamsAppBasedLinkQuery(context, query) {
295 return __awaiter(this, void 0, void 0, function* () {
296 throw new Error('NotImplemented');
297 });
298 }
299 /**
300 * Receives invoke activities with the name 'composeExtension/query'.
301 * @remarks
302 * Used in creating a Search-based Message Extension.
303 * @param context A context object for this turn.
304 * @param query The query for the search command.
305 * @returns The Messaging Extension Response for the query.
306 */
307 handleTeamsMessagingExtensionQuery(context, query) {
308 return __awaiter(this, void 0, void 0, function* () {
309 throw new Error('NotImplemented');
310 });
311 }
312 /**
313 * Receives invoke activities with the name 'composeExtension/selectItem'.
314 * @remarks
315 * Used in creating a Search-based Message Extension.
316 * @param context A context object for this turn.
317 * @param query he object representing the query.
318 * @returns The Messaging Extension Response for the query.
319 */
320 handleTeamsMessagingExtensionSelectItem(context, query) {
321 return __awaiter(this, void 0, void 0, function* () {
322 throw new Error('NotImplemented');
323 });
324 }
325 /**
326 * Receives invoke activities with the name 'composeExtension/submitAction' and dispatches to botMessagePreview-flows as applicable.
327 * @remarks
328 * A handler registered through this method does not dispatch to the next handler (either `handleTeamsMessagingExtensionSubmitAction`, `handleTeamsMessagingExtensionBotMessagePreviewEdit`, or `handleTeamsMessagingExtensionBotMessagePreviewSend`).
329 * This method exists for developers to optionally add more logic before the TeamsActivityHandler routes the activity to one of the
330 * previously mentioned handlers.
331 * @param context A context object for this turn.
332 * @param action The messaging extension action.
333 * @returns The Messaging Extension Action Response for the action.
334 */
335 handleTeamsMessagingExtensionSubmitActionDispatch(context, action) {
336 return __awaiter(this, void 0, void 0, function* () {
337 if (action.botMessagePreviewAction) {
338 switch (action.botMessagePreviewAction) {
339 case 'edit':
340 return yield this.handleTeamsMessagingExtensionBotMessagePreviewEdit(context, action);
341 case 'send':
342 return yield this.handleTeamsMessagingExtensionBotMessagePreviewSend(context, action);
343 default:
344 throw new Error('BadRequest');
345 }
346 }
347 else {
348 return yield this.handleTeamsMessagingExtensionSubmitAction(context, action);
349 }
350 });
351 }
352 /**
353 * Receives invoke activities with the name 'composeExtension/submitAction'.
354 * @param context A context object for this turn.
355 * @param action The messaging extension action.
356 * @returns The Messaging Extension Action Response for the action.
357 */
358 handleTeamsMessagingExtensionSubmitAction(context, action) {
359 return __awaiter(this, void 0, void 0, function* () {
360 throw new Error('NotImplemented');
361 });
362 }
363 /**
364 * Receives invoke activities with the name 'composeExtension/submitAction' with the 'botMessagePreview' property present on activity.value.
365 * The value for 'botMessagePreview' is 'edit'.
366 * @param context A context object for this turn.
367 * @param action The messaging extension action.
368 * @returns The Messaging Extension Action Response for the action.
369 */
370 handleTeamsMessagingExtensionBotMessagePreviewEdit(context, action) {
371 return __awaiter(this, void 0, void 0, function* () {
372 throw new Error('NotImplemented');
373 });
374 }
375 /**
376 * Receives invoke activities with the name 'composeExtension/submitAction' with the 'botMessagePreview' property present on activity.value.
377 * The value for 'botMessagePreview' is 'send'.
378 * @param context A context object for this turn.
379 * @param action The messaging extension action.
380 * @returns The Messaging Extension Action Response for the action.
381 */
382 handleTeamsMessagingExtensionBotMessagePreviewSend(context, action) {
383 return __awaiter(this, void 0, void 0, function* () {
384 throw new Error('NotImplemented');
385 });
386 }
387 /**
388 * Receives invoke activities with the name 'composeExtension/fetchTask'
389 * @param context A context object for this turn.
390 * @param action The messaging extension action.
391 * @returns The Messaging Extension Action Response for the action.
392 */
393 handleTeamsMessagingExtensionFetchTask(context, action) {
394 return __awaiter(this, void 0, void 0, function* () {
395 throw new Error('NotImplemented');
396 });
397 }
398 /**
399 * Receives invoke activities with the name 'composeExtension/querySettingUrl'
400 * @param context A context object for this turn.
401 * @param query The Messaging extension query.
402 * @returns The Messaging Extension Action Response for the query.
403 */
404 handleTeamsMessagingExtensionConfigurationQuerySettingUrl(context, query) {
405 return __awaiter(this, void 0, void 0, function* () {
406 throw new Error('NotImplemented');
407 });
408 }
409 /**
410 * Receives invoke activities with the name 'adaptiveCard/action'
411 * @param context A context object for this turn.
412 * @returns The Messaging Extension Action Response for the query.
413 */
414 handleAdaptiveCardAction(context) {
415 return __awaiter(this, void 0, void 0, function* () {
416 throw new Error('NotImplemented');
417 });
418 }
419 /**
420 * Receives invoke activities with the name 'composeExtension/setting'
421 * @param context A context object for this turn.
422 * @param settings Object representing the configuration settings.
423 * @returns A promise that represents the work queued.
424 */
425 handleTeamsMessagingExtensionConfigurationSetting(context, settings) {
426 throw new Error('NotImplemented');
427 }
428 /**
429 * Override this method to change the dispatching of ConversationUpdate activities.
430 * @param context A context object for this turn.
431 * @returns A promise that represents the work queued.
432 */
433 dispatchConversationUpdateActivity(context) {
434 const _super = Object.create(null, {
435 dispatchConversationUpdateActivity: { get: () => super.dispatchConversationUpdateActivity }
436 });
437 return __awaiter(this, void 0, void 0, function* () {
438 yield this.handle(context, 'ConversationUpdate', () => __awaiter(this, void 0, void 0, function* () {
439 if (context.activity.channelId == 'msteams') {
440 const channelData = context.activity.channelData;
441 if (context.activity.membersAdded && context.activity.membersAdded.length > 0) {
442 return yield this.onTeamsMembersAdded(context);
443 }
444 if (context.activity.membersRemoved && context.activity.membersRemoved.length > 0) {
445 return yield this.onTeamsMembersRemoved(context);
446 }
447 if (!channelData || !channelData.eventType) {
448 return yield _super.dispatchConversationUpdateActivity.call(this, context);
449 }
450 switch (channelData.eventType) {
451 case 'channelCreated':
452 return yield this.onTeamsChannelCreated(context);
453 case 'channelDeleted':
454 return yield this.onTeamsChannelDeleted(context);
455 case 'channelRenamed':
456 return yield this.onTeamsChannelRenamed(context);
457 case 'teamArchived':
458 return yield this.onTeamsTeamArchived(context);
459 case 'teamDeleted':
460 return yield this.onTeamsTeamDeleted(context);
461 case 'teamHardDeleted':
462 return yield this.onTeamsTeamHardDeleted(context);
463 case 'channelRestored':
464 return yield this.onTeamsChannelRestored(context);
465 case 'teamRenamed':
466 return yield this.onTeamsTeamRenamed(context);
467 case 'teamRestored':
468 return yield this.onTeamsTeamRestored(context);
469 case 'teamUnarchived':
470 return yield this.onTeamsTeamUnarchived(context);
471 default:
472 return yield _super.dispatchConversationUpdateActivity.call(this, context);
473 }
474 }
475 else {
476 return yield _super.dispatchConversationUpdateActivity.call(this, context);
477 }
478 }));
479 });
480 }
481 /**
482 * Called in `dispatchConversationUpdateActivity()` to trigger the `'TeamsMembersAdded'` handlers.
483 * Override this in a derived class to provide logic for when members other than the bot
484 * join the channel, such as your bot's welcome logic.
485 * @remarks
486 * If no handlers are registered for the `'TeamsMembersAdded'` event, the `'MembersAdded'` handlers will run instead.
487 * @param context A context object for this turn.
488 * @returns A promise that represents the work queued.
489 */
490 onTeamsMembersAdded(context) {
491 return __awaiter(this, void 0, void 0, function* () {
492 if ('TeamsMembersAdded' in this.handlers && this.handlers['TeamsMembersAdded'].length > 0) {
493 for (let i = 0; i < context.activity.membersAdded.length; i++) {
494 const channelAccount = context.activity.membersAdded[i];
495 // check whether we have a TeamChannelAccount, or the member is the bot
496 if ('givenName' in channelAccount ||
497 'surname' in channelAccount ||
498 'email' in channelAccount ||
499 'userPrincipalName' in channelAccount ||
500 context.activity.recipient.id === channelAccount.id) {
501 // we must have a TeamsChannelAccount, or a bot so skip to the next one
502 continue;
503 }
504 try {
505 context.activity.membersAdded[i] = yield teamsInfo_1.TeamsInfo.getMember(context, channelAccount.id);
506 }
507 catch (err) {
508 const errCode = err.body && err.body.error && err.body.error.code;
509 if (errCode === 'ConversationNotFound') {
510 // unable to find the member added in ConversationUpdate Activity in the response from the getMember call
511 const teamsChannelAccount = {
512 id: channelAccount.id,
513 name: channelAccount.name,
514 aadObjectId: channelAccount.aadObjectId,
515 role: channelAccount.role,
516 };
517 context.activity.membersAdded[i] = teamsChannelAccount;
518 }
519 else {
520 throw err;
521 }
522 }
523 }
524 yield this.handle(context, 'TeamsMembersAdded', this.defaultNextEvent(context));
525 }
526 else {
527 yield this.handle(context, 'MembersAdded', this.defaultNextEvent(context));
528 }
529 });
530 }
531 /**
532 * Called in `dispatchConversationUpdateActivity()` to trigger the `'TeamsMembersRemoved'` handlers.
533 * Override this in a derived class to provide logic for when members other than the bot
534 * leave the channel, such as your bot's good-bye logic.
535 * @remarks
536 * If no handlers are registered for the `'TeamsMembersRemoved'` event, the `'MembersRemoved'` handlers will run instead.
537 * @param context A context object for this turn.
538 * @returns A promise that represents the work queued.
539 */
540 onTeamsMembersRemoved(context) {
541 return __awaiter(this, void 0, void 0, function* () {
542 if ('TeamsMembersRemoved' in this.handlers && this.handlers['TeamsMembersRemoved'].length > 0) {
543 yield this.handle(context, 'TeamsMembersRemoved', this.defaultNextEvent(context));
544 }
545 else {
546 yield this.handle(context, 'MembersRemoved', this.defaultNextEvent(context));
547 }
548 });
549 }
550 /**
551 * Invoked when a Channel Created event activity is received from the connector.
552 * Channel Created corresponds to the user creating a new channel.
553 * Override this in a derived class to provide logic for when a channel is created.
554 * @param context A context object for this turn.
555 * @returns A promise that represents the work queued.
556 */
557 onTeamsChannelCreated(context) {
558 return __awaiter(this, void 0, void 0, function* () {
559 yield this.handle(context, 'TeamsChannelCreated', this.defaultNextEvent(context));
560 });
561 }
562 /**
563 * Invoked when a Channel Deleted event activity is received from the connector.
564 * Channel Deleted corresponds to the user deleting a channel.
565 * Override this in a derived class to provide logic for when a channel is deleted.
566 * @param context A context object for this turn.
567 * @returns A promise that represents the work queued.
568 */
569 onTeamsChannelDeleted(context) {
570 return __awaiter(this, void 0, void 0, function* () {
571 yield this.handle(context, 'TeamsChannelDeleted', this.defaultNextEvent(context));
572 });
573 }
574 /**
575 * Invoked when a Channel Renamed event activity is received from the connector.
576 * Channel Renamed corresponds to the user renaming a new channel.
577 * Override this in a derived class to provide logic for when a channel is renamed.
578 * @param context A context object for this turn.
579 * @returns A promise that represents the work queued.
580 */
581 onTeamsChannelRenamed(context) {
582 return __awaiter(this, void 0, void 0, function* () {
583 yield this.handle(context, 'TeamsChannelRenamed', this.defaultNextEvent(context));
584 });
585 }
586 /**
587 * Invoked when a Team Archived event activity is received from the connector.
588 * Team Archived corresponds to the user archiving a team.
589 * Override this in a derived class to provide logic for when a team is archived.
590 * @param context The context for this turn.
591 * @returns A promise that represents the work queued.
592 */
593 onTeamsTeamArchived(context) {
594 return __awaiter(this, void 0, void 0, function* () {
595 yield this.handle(context, 'TeamsTeamArchived', this.defaultNextEvent(context));
596 });
597 }
598 /**
599 * Invoked when a Team Deleted event activity is received from the connector.
600 * Team Deleted corresponds to the user deleting a team.
601 * Override this in a derived class to provide logic for when a team is deleted.
602 * @param context The context for this turn.
603 * @returns A promise that represents the work queued.
604 */
605 onTeamsTeamDeleted(context) {
606 return __awaiter(this, void 0, void 0, function* () {
607 yield this.handle(context, 'TeamsTeamDeleted', this.defaultNextEvent(context));
608 });
609 }
610 /**
611 * Invoked when a Team Hard Deleted event activity is received from the connector.
612 * Team Hard Deleted corresponds to the user hard-deleting a team.
613 * Override this in a derived class to provide logic for when a team is hard-deleted.
614 * @param context The context for this turn.
615 * @returns A promise that represents the work queued.
616 */
617 onTeamsTeamHardDeleted(context) {
618 return __awaiter(this, void 0, void 0, function* () {
619 yield this.handle(context, 'TeamsTeamHardDeleted', this.defaultNextEvent(context));
620 });
621 }
622 /**
623 *
624 * @param context
625 * Invoked when a Channel Restored event activity is received from the connector.
626 * Channel Restored corresponds to the user restoring a previously deleted channel.
627 * Override this in a derived class to provide logic for when a channel is restored.
628 * @param context The context for this turn.
629 * @returns A promise that represents the work queued.
630 */
631 onTeamsChannelRestored(context) {
632 return __awaiter(this, void 0, void 0, function* () {
633 yield this.handle(context, 'TeamsChannelRestored', this.defaultNextEvent(context));
634 });
635 }
636 /**
637 * Invoked when a Team Renamed event activity is received from the connector.
638 * Team Renamed corresponds to the user renaming a team.
639 * Override this in a derived class to provide logic for when a team is renamed.
640 * @param context The context for this turn.
641 * @returns A promise that represents the work queued.
642 */
643 onTeamsTeamRenamed(context) {
644 return __awaiter(this, void 0, void 0, function* () {
645 yield this.handle(context, 'TeamsTeamRenamed', this.defaultNextEvent(context));
646 });
647 }
648 /**
649 * Invoked when a Team Restored event activity is received from the connector.
650 * Team Restored corresponds to the user restoring a team.
651 * Override this in a derived class to provide logic for when a team is restored.
652 * @param context The context for this turn.
653 * @returns A promise that represents the work queued.
654 */
655 onTeamsTeamRestored(context) {
656 return __awaiter(this, void 0, void 0, function* () {
657 yield this.handle(context, 'TeamsTeamRestored', this.defaultNextEvent(context));
658 });
659 }
660 /**
661 * Invoked when a Team Unarchived event activity is received from the connector.
662 * Team Unarchived corresponds to the user unarchiving a team.
663 * Override this in a derived class to provide logic for when a team is unarchived.
664 * @param context The context for this turn.
665 * @returns A promise that represents the work queued.
666 */
667 onTeamsTeamUnarchived(context) {
668 return __awaiter(this, void 0, void 0, function* () {
669 yield this.handle(context, 'TeamsTeamUnarchived', this.defaultNextEvent(context));
670 });
671 }
672 /**
673 * Registers a handler for TeamsMembersAdded events, such as for when members other than the bot
674 * join the channel, such as your bot's welcome logic.
675 * @param handler
676 * @returns A promise that represents the work queued.
677 */
678 onTeamsMembersAddedEvent(handler) {
679 return this.on('TeamsMembersAdded', (context, next) => __awaiter(this, void 0, void 0, function* () {
680 const teamsChannelData = context.activity.channelData;
681 yield handler(context.activity.membersAdded, teamsChannelData.team, context, next);
682 }));
683 }
684 /**
685 * Registers a handler for TeamsMembersRemoved events, such as for when members other than the bot
686 * leave the channel, such as your bot's good-bye logic.
687 * @param handler
688 * @returns A promise that represents the work queued.
689 */
690 onTeamsMembersRemovedEvent(handler) {
691 return this.on('TeamsMembersRemoved', (context, next) => __awaiter(this, void 0, void 0, function* () {
692 const teamsChannelData = context.activity.channelData;
693 yield handler(context.activity.membersRemoved, teamsChannelData.team, context, next);
694 }));
695 }
696 /**
697 * Registers a handler for TeamsChannelCreated events, such as for when a channel is created.
698 * @param handler
699 * @returns A promise that represents the work queued.
700 */
701 onTeamsChannelCreatedEvent(handler) {
702 return this.on('TeamsChannelCreated', (context, next) => __awaiter(this, void 0, void 0, function* () {
703 const teamsChannelData = context.activity.channelData;
704 yield handler(teamsChannelData.channel, teamsChannelData.team, context, next);
705 }));
706 }
707 /**
708 * Registers a handler for TeamsChannelDeleted events, such as for when a channel is deleted.
709 * @param handler
710 * @returns A promise that represents the work queued.
711 */
712 onTeamsChannelDeletedEvent(handler) {
713 return this.on('TeamsChannelDeleted', (context, next) => __awaiter(this, void 0, void 0, function* () {
714 const teamsChannelData = context.activity.channelData;
715 yield handler(teamsChannelData.channel, teamsChannelData.team, context, next);
716 }));
717 }
718 /**
719 * Registers a handler for TeamsChannelRenamed events, such as for when a channel is renamed.
720 * @param handler
721 * @returns A promise that represents the work queued.
722 */
723 onTeamsChannelRenamedEvent(handler) {
724 return this.on('TeamsChannelRenamed', (context, next) => __awaiter(this, void 0, void 0, function* () {
725 const teamsChannelData = context.activity.channelData;
726 yield handler(teamsChannelData.channel, teamsChannelData.team, context, next);
727 }));
728 }
729 /**
730 * Registers a handler for TeamsTeamArchived events, such as for when a team is archived.
731 * @param handler
732 * @returns A promise that represents the work queued.
733 */
734 onTeamsTeamArchivedEvent(handler) {
735 return this.on('TeamsTeamArchived', (context, next) => __awaiter(this, void 0, void 0, function* () {
736 const teamsChannelData = context.activity.channelData;
737 yield handler(teamsChannelData.team, context, next);
738 }));
739 }
740 /**
741 * Registers a handler for TeamsTeamDeleted events, such as for when a team is deleted.
742 * @param handler
743 * @returns A promise that represents the work queued.
744 */
745 onTeamsTeamDeletedEvent(handler) {
746 return this.on('TeamsTeamDeleted', (context, next) => __awaiter(this, void 0, void 0, function* () {
747 const teamsChannelData = context.activity.channelData;
748 yield handler(teamsChannelData.team, context, next);
749 }));
750 }
751 /**
752 * Registers a handler for TeamsTeamHardDeleted events, such as for when a team is hard-deleted.
753 * @param handler
754 * @returns A promise that represents the work queued.
755 */
756 onTeamsTeamHardDeletedEvent(handler) {
757 return this.on('TeamsTeamHardDeleted', (context, next) => __awaiter(this, void 0, void 0, function* () {
758 const teamsChannelData = context.activity.channelData;
759 yield handler(teamsChannelData.team, context, next);
760 }));
761 }
762 /**
763 * Registers a handler for TeamsChannelRestored events, such as for when a channel is restored.
764 * @param handler
765 * @returns A promise that represents the work queued.
766 */
767 onTeamsChannelRestoredEvent(handler) {
768 return this.on('TeamsChannelRestored', (context, next) => __awaiter(this, void 0, void 0, function* () {
769 const teamsChannelData = context.activity.channelData;
770 yield handler(teamsChannelData.channel, teamsChannelData.team, context, next);
771 }));
772 }
773 /**
774 * Registers a handler for TeamsTeamRenamed events, such as for when a team is renamed.
775 * @param handler
776 * @returns A promise that represents the work queued.
777 */
778 onTeamsTeamRenamedEvent(handler) {
779 return this.on('TeamsTeamRenamed', (context, next) => __awaiter(this, void 0, void 0, function* () {
780 const teamsChannelData = context.activity.channelData;
781 yield handler(teamsChannelData.team, context, next);
782 }));
783 }
784 /**
785 * Registers a handler for TeamsTeamRestored events, such as for when a team is restored.
786 * @param handler
787 * @returns A promise that represents the work queued.
788 */
789 onTeamsTeamRestoredEvent(handler) {
790 return this.on('TeamsTeamRestored', (context, next) => __awaiter(this, void 0, void 0, function* () {
791 const teamsChannelData = context.activity.channelData;
792 yield handler(teamsChannelData.team, context, next);
793 }));
794 }
795 /**
796 * Registers a handler for TeamsTeamUnarchived events, such as for when a team is unarchived.
797 * @param handler
798 * @returns A promise that represents the work queued.
799 */
800 onTeamsTeamUnarchivedEvent(handler) {
801 return this.on('TeamsTeamUnarchived', (context, next) => __awaiter(this, void 0, void 0, function* () {
802 const teamsChannelData = context.activity.channelData;
803 yield handler(teamsChannelData.team, context, next);
804 }));
805 }
806 /**
807 * Runs the _event_ sub-type handlers, as appropriate, and then continues the event emission process.
808 *
809 * @param context The context object for the current turn.
810 * @returns A promise that represents the work queued.
811 *
812 * @remarks
813 * Override this method to support channel-specific behavior across multiple channels or to add
814 * custom event sub-type events.
815 */
816 dispatchEventActivity(context) {
817 const _super = Object.create(null, {
818 dispatchEventActivity: { get: () => super.dispatchEventActivity }
819 });
820 return __awaiter(this, void 0, void 0, function* () {
821 yield this.handle(context, 'Event', () => __awaiter(this, void 0, void 0, function* () {
822 if (context.activity.channelId === botbuilder_core_1.Channels.Msteams) {
823 switch (context.activity.name) {
824 case 'application/vnd.microsoft.meetingStart':
825 return this.onTeamsMeetingStart(context);
826 case 'application/vnd.microsoft.meetingEnd':
827 return this.onTeamsMeetingEnd(context);
828 }
829 }
830 return _super.dispatchEventActivity.call(this, context);
831 }));
832 });
833 }
834 /**
835 * Invoked when a Meeting Started event activity is received from the connector.
836 * Override this in a derived class to provide logic for when a meeting is started.
837 *
838 * @param context The context for this turn.
839 * @returns A promise that represents the work queued.
840 */
841 onTeamsMeetingStart(context) {
842 return __awaiter(this, void 0, void 0, function* () {
843 yield this.handle(context, 'TeamsMeetingStart', this.defaultNextEvent(context));
844 });
845 }
846 /**
847 * Invoked when a Meeting End event activity is received from the connector.
848 * Override this in a derived class to provide logic for when a meeting is ended.
849 *
850 * @param context The context for this turn.
851 * @returns A promise that represents the work queued.
852 */
853 onTeamsMeetingEnd(context) {
854 return __awaiter(this, void 0, void 0, function* () {
855 yield this.handle(context, 'TeamsMeetingEnd', this.defaultNextEvent(context));
856 });
857 }
858 /**
859 * Registers a handler for when a Teams meeting starts.
860 *
861 * @param handler A callback that handles Meeting Start events.
862 * @returns A promise that represents the work queued.
863 */
864 onTeamsMeetingStartEvent(handler) {
865 return this.on('TeamsMeetingStart', (context, next) => __awaiter(this, void 0, void 0, function* () {
866 const meeting = TeamsMeetingStartT.parse(context.activity.value);
867 yield handler({
868 id: meeting.Id,
869 joinUrl: meeting.JoinUrl,
870 meetingType: meeting.MeetingType,
871 startTime: new Date(meeting.StartTime),
872 title: meeting.Title,
873 }, context, next);
874 }));
875 }
876 /**
877 * Registers a handler for when a Teams meeting ends.
878 *
879 * @param handler A callback that handles Meeting End events.
880 * @returns A promise that represents the work queued.
881 */
882 onTeamsMeetingEndEvent(handler) {
883 return this.on('TeamsMeetingEnd', (context, next) => __awaiter(this, void 0, void 0, function* () {
884 const meeting = TeamsMeetingEndT.parse(context.activity.value);
885 yield handler({
886 id: meeting.Id,
887 joinUrl: meeting.JoinUrl,
888 meetingType: meeting.MeetingType,
889 endTime: new Date(meeting.EndTime),
890 title: meeting.Title,
891 }, context, next);
892 }));
893 }
894}
895exports.TeamsActivityHandler = TeamsActivityHandler;
896//# sourceMappingURL=teamsActivityHandler.js.map
\No newline at end of file