1 | ;
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | const botworker_1 = require("./botworker");
|
13 | const botbuilder_1 = require("botbuilder");
|
14 | /**
|
15 | * This is a specialized version of [Botkit's core BotWorker class](core.md#BotWorker) that includes additional methods for interacting with Microsoft Teams.
|
16 | * It includes all functionality from the base class, as well as the extension methods below.
|
17 | * This BotWorker is used with the built-in Bot Framework adapter.
|
18 | * @noInheritDoc
|
19 | */
|
20 | class TeamsBotWorker extends botworker_1.BotWorker {
|
21 | constructor() {
|
22 | super(...arguments);
|
23 | /**
|
24 | * Grants access to the TeamsInfo helper class
|
25 | * See: https://docs.microsoft.com/en-us/javascript/api/botbuilder/teamsinfo?view=botbuilder-ts-latest
|
26 | */
|
27 | this.teams = botbuilder_1.TeamsInfo;
|
28 | }
|
29 | /**
|
30 | * Reply to a Teams task module task/fetch or task/submit with a task module response.
|
31 | * See https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/task-modules/task-modules-bots
|
32 | * @param message
|
33 | * @param taskInfo an object in the form {type, value}
|
34 | */
|
35 | replyWithTaskInfo(message, taskInfo) {
|
36 | return __awaiter(this, void 0, void 0, function* () {
|
37 | if (!taskInfo || taskInfo === {}) {
|
38 | // send a null response back
|
39 | taskInfo = {
|
40 | type: 'message',
|
41 | value: ''
|
42 | };
|
43 | }
|
44 | return new Promise((resolve, reject) => {
|
45 | this.controller.middleware.send.run(this, taskInfo, (err, bot, taskInfo) => __awaiter(this, void 0, void 0, function* () {
|
46 | if (err) {
|
47 | return reject(err);
|
48 | }
|
49 | resolve(yield this.getConfig('context').sendActivity({
|
50 | type: 'invokeResponse',
|
51 | value: {
|
52 | status: 200,
|
53 | body: {
|
54 | task: taskInfo
|
55 | }
|
56 | }
|
57 | }));
|
58 | }));
|
59 | });
|
60 | });
|
61 | }
|
62 | }
|
63 | exports.TeamsBotWorker = TeamsBotWorker;
|
64 | /**
|
65 | * When used, causes Botkit to emit special events for teams "invokes"
|
66 | * Based on https://github.com/microsoft/botbuilder-js/blob/master/libraries/botbuilder/src/teamsActivityHandler.ts
|
67 | * This allows Botkit bots to respond directly to task/fetch or task/submit events, as an example.
|
68 | * To use this, bind it to the adapter before creating the Botkit controller:
|
69 | * ```javascript
|
70 | * const Botkit = new Botkit({...});
|
71 | * botkit.adapter.use(new TeamsInvokeMiddleware());
|
72 | *
|
73 | * // can bind directly to task/fetch, task/submit and other invoke types used by teams
|
74 | * controller.on('task/fetch', async(bot, message) => {
|
75 | * await bot.replyWithTaskInfo(message, taskInfo);
|
76 | * });
|
77 | * ```
|
78 | */
|
79 | class TeamsInvokeMiddleware extends botbuilder_1.MiddlewareSet {
|
80 | /**
|
81 | * Not for direct use - implements the MiddlewareSet's required onTurn function used to process the event
|
82 | * @param context
|
83 | * @param next
|
84 | */
|
85 | onTurn(context, next) {
|
86 | return __awaiter(this, void 0, void 0, function* () {
|
87 | if (context.activity.type === 'invoke') {
|
88 | if (!context.activity.name && context.activity.channelId === 'msteams') {
|
89 | context.activity.channelData.botkitEventType = 'cardAction';
|
90 | }
|
91 | else {
|
92 | switch (context.activity.name) {
|
93 | case 'fileConsent/invoke':
|
94 | case 'actionableMessage/executeAction':
|
95 | case 'composeExtension/queryLink':
|
96 | case 'composeExtension/query':
|
97 | case 'composeExtension/selectItem':
|
98 | case 'composeExtension/submitAction':
|
99 | case 'composeExtension/fetchTask':
|
100 | case 'composeExtension/querySettingUrl':
|
101 | case 'composeExtension/setting':
|
102 | case 'composeExtension/onCardButtonClicked':
|
103 | case 'task/fetch':
|
104 | case 'task/submit':
|
105 | context.activity.channelData.botkitEventType = context.activity.name;
|
106 | break;
|
107 | }
|
108 | }
|
109 | }
|
110 | yield next();
|
111 | });
|
112 | }
|
113 | }
|
114 | exports.TeamsInvokeMiddleware = TeamsInvokeMiddleware;
|
115 | //# sourceMappingURL=teamsHelpers.js.map |
\ | No newline at end of file |