@microsoft/teamsfx 0.6.2-alpha.444739e17.0 → 0.6.2-alpha.52f41e8aa.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/teamsfx",
3
- "version": "0.6.2-alpha.444739e17.0",
3
+ "version": "0.6.2-alpha.52f41e8aa.0",
4
4
  "description": "Microsoft Teams Framework for Node.js and browser.",
5
5
  "main": "dist/index.node.cjs.js",
6
6
  "browser": "dist/index.esm2017.js",
@@ -49,7 +49,7 @@
49
49
  "@azure/identity": "^2.0.1",
50
50
  "@azure/msal-browser": "^2.21.0",
51
51
  "@azure/msal-node": "~1.1.0",
52
- "@microsoft/adaptivecards-tools": "0.1.6-alpha.444739e17.0",
52
+ "@microsoft/adaptivecards-tools": "0.1.6-alpha.52f41e8aa.0",
53
53
  "@microsoft/microsoft-graph-client": "^3.0.1",
54
54
  "axios": "^0.24.0",
55
55
  "botbuilder": ">=4.15.0 <5.0.0",
@@ -85,6 +85,7 @@
85
85
  "@typescript-eslint/eslint-plugin": "^5.0.0",
86
86
  "@typescript-eslint/parser": "^4.13.0",
87
87
  "adm-zip": "^0.5.9",
88
+ "axios-mock-adapter": "^1.20.0",
88
89
  "botbuilder-core": ">=4.15.0 <5.0.0",
89
90
  "chai": "^4.3.4",
90
91
  "chai-as-promised": "^7.1.1",
@@ -127,7 +128,7 @@
127
128
  "webpack": "^5.62.1",
128
129
  "yargs": "^17.2.1"
129
130
  },
130
- "gitHead": "128f6dbe9e01e989cdc717967e0ffe7b0280d8f9",
131
+ "gitHead": "b73c402779226ef96977f0cdfce9dc1df617259c",
131
132
  "publishConfig": {
132
133
  "access": "public"
133
134
  },
@@ -3,6 +3,8 @@ import { Activity } from 'botbuilder-core';
3
3
  import { Activity as Activity_2 } from 'botbuilder';
4
4
  import { Attachment } from 'botbuilder';
5
5
  import { AuthenticationProvider } from '@microsoft/microsoft-graph-client';
6
+ import { AxiosInstance } from 'axios';
7
+ import { AxiosRequestConfig } from 'axios';
6
8
  import { BotFrameworkAdapter } from 'botbuilder';
7
9
  import { CardAction } from 'botbuilder';
8
10
  import { CardImage } from 'botbuilder';
@@ -137,6 +139,47 @@ export declare interface AuthenticationConfiguration {
137
139
  readonly applicationIdUri?: string;
138
140
  }
139
141
 
142
+ /**
143
+ * Defines method that injects authentication info to http requests
144
+ *
145
+ * @beta
146
+ */
147
+ export declare interface AuthProvider {
148
+ /**
149
+ * Adds authentication info to http requests
150
+ *
151
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
152
+ * Refer https://axios-http.com/docs/req_config for detailed document.
153
+ *
154
+ * @beta
155
+ */
156
+ AddAuthenticationInfo: (config: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
157
+ }
158
+
159
+ /**
160
+ * Provider that handles Bearer Token authentication
161
+ *
162
+ * @beta
163
+ */
164
+ export declare class BearerTokenAuthProvider implements AuthProvider {
165
+ private getToken;
166
+ /**
167
+ * @param getToken Function that returns the content of bearer token used in http request
168
+ *
169
+ * @beta
170
+ */
171
+ constructor(getToken: () => Promise<string>);
172
+ /**
173
+ * Adds authentication info to http requests
174
+ *
175
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
176
+ * Refer https://axios-http.com/docs/req_config for detailed document.
177
+ *
178
+ * @beta
179
+ */
180
+ AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
181
+ }
182
+
140
183
  /**
141
184
  * A {@link NotificationTarget} that represents a team channel.
142
185
  *
@@ -206,31 +249,20 @@ export declare class Channel implements NotificationTarget {
206
249
  * @remarks
207
250
  * Ensure each command should ONLY be registered with the command once, otherwise it'll cause unexpected behavior if you register the same command more than once.
208
251
  *
209
- * @example
210
- * You can register your commands through the constructor of the {@link CommandBot}, or use the `registerCommand` and `registerCommands` API to add commands after creating the `CommandBot` instance.
211
- *
212
- * ```typescript
213
- * // register through constructor
214
- * const commandBot = new CommandBot(adapter, [ new HelloWorldCommandHandler() ]);
215
- *
216
- * // register through `register*` API
217
- * commandBot.registerCommand(new HelpCommandHandler());
218
- * ```
219
- *
220
252
  * @beta
221
253
  */
222
254
  export declare class CommandBot {
223
- readonly adapter: BotFrameworkAdapter;
255
+ private readonly adapter;
224
256
  private readonly middleware;
225
257
  /**
226
258
  * Creates a new instance of the `CommandBot`.
227
259
  *
228
260
  * @param adapter The bound `BotFrameworkAdapter`.
229
- * @param commands The commands to registered with the command bot. Each command should implement the interface {@link TeamsFxBotCommandHandler} so that it can be correctly handled by this command bot.
261
+ * @param options - initialize options
230
262
  *
231
263
  * @beta
232
264
  */
233
- constructor(adapter: BotFrameworkAdapter, commands?: TeamsFxBotCommandHandler[]);
265
+ constructor(adapter: BotFrameworkAdapter, options?: CommandOptions);
234
266
  /**
235
267
  * Registers a command into the command bot.
236
268
  *
@@ -249,6 +281,186 @@ export declare class CommandBot {
249
281
  registerCommands(commands: TeamsFxBotCommandHandler[]): void;
250
282
  }
251
283
 
284
+ /**
285
+ * Interface for a command messagge that can handled in a command handler.
286
+ */
287
+ export declare interface CommandMessage {
288
+ /**
289
+ * Text of the message sent by the user.
290
+ */
291
+ text: string;
292
+ /**
293
+ * The capture groups that matched to the {@link triggerPatterns} in a {@link TeamsFxBotCommandHandler} instance.
294
+ */
295
+ matches?: RegExpMatchArray;
296
+ }
297
+
298
+ /**
299
+ * Options to initialize {@link CommandBot}.
300
+ *
301
+ * @beta
302
+ */
303
+ export declare interface CommandOptions {
304
+ /**
305
+ * The commands to registered with the command bot. Each command should implement the interface {@link TeamsFxBotCommandHandler} so that it can be correctly handled by this command bot.
306
+ *
307
+ * @beta
308
+ */
309
+ commands?: TeamsFxBotCommandHandler[];
310
+ }
311
+
312
+ /**
313
+ * Provide utilities for bot conversation, including:
314
+ * - handle command and response.
315
+ * - send notification to varies targets (e.g., member, channel, incoming wehbook).
316
+ *
317
+ * @example
318
+ * For command and response, you can register your commands through the constructor, or use the `registerCommand` and `registerCommands` API to add commands later.
319
+ *
320
+ * ```typescript
321
+ * // register through constructor
322
+ * const conversationBot = new ConversationBot({
323
+ * command: {
324
+ * enabled: true,
325
+ * options: {
326
+ * commands: [ new HelloWorldCommandHandler() ],
327
+ * },
328
+ * },
329
+ * });
330
+ *
331
+ * // register through `register*` API
332
+ * conversationBot.command.registerCommand(new HelpCommandHandler());
333
+ * ```
334
+ *
335
+ * For notification, you can enable notification at initialization, then send notificaations at any time.
336
+ *
337
+ * ```typescript
338
+ * // enable through constructor
339
+ * const conversationBot = new ConversationBot({
340
+ * notification: {
341
+ * enabled: true,
342
+ * },
343
+ * });
344
+ *
345
+ * // get all bot installations and send message
346
+ * for (const target of await conversationBot.notification.installations()) {
347
+ * await target.sendMessage("Hello Notification");
348
+ * }
349
+ *
350
+ * // alternative - send message to all members
351
+ * for (const target of await conversationBot.notification.installations()) {
352
+ * for (const member of await target.members()) {
353
+ * await member.sendMessage("Hello Notification");
354
+ * }
355
+ * }
356
+ * ```
357
+ *
358
+ * @remarks
359
+ * Set `adapter` in {@link ConversationOptions} to use your own bot adapter.
360
+ *
361
+ * For command and response, ensure each command should ONLY be registered with the command once, otherwise it'll cause unexpected behavior if you register the same command more than once.
362
+ *
363
+ * For notification, set `notification.options.storage` in {@link ConversationOptions} to use your own storage implementation.
364
+ *
365
+ * @beta
366
+ */
367
+ export declare class ConversationBot {
368
+ /**
369
+ * The bot adapter.
370
+ *
371
+ * @beta
372
+ */
373
+ readonly adapter: BotFrameworkAdapter;
374
+ /**
375
+ * The entrypoint of command and response.
376
+ *
377
+ * @beta
378
+ */
379
+ readonly command?: CommandBot;
380
+ /**
381
+ * The entrypoint of notification.
382
+ *
383
+ * @beta
384
+ */
385
+ readonly notification?: NotificationBot;
386
+ /**
387
+ * Creates new instance of the `ConversationBot`.
388
+ *
389
+ * @param options - initialize options
390
+ *
391
+ * @beta
392
+ */
393
+ constructor(options: ConversationOptions);
394
+ }
395
+
396
+ /**
397
+ * Options to initialize {@link ConversationBot}
398
+ *
399
+ * @beta
400
+ */
401
+ export declare interface ConversationOptions {
402
+ /**
403
+ * The bot adapter. If not provided, a default adapter will be created with BOT_ID and BOT_PASSWORD from environment variables.
404
+ *
405
+ * @beta
406
+ */
407
+ adapter?: BotFrameworkAdapter;
408
+ /**
409
+ * The command part.
410
+ *
411
+ * @beta
412
+ */
413
+ command: {
414
+ /**
415
+ * Whether to enable command or not.
416
+ *
417
+ * @beta
418
+ */
419
+ enabled: boolean;
420
+ /**
421
+ * The command options if command is enabled.
422
+ *
423
+ * @beta
424
+ */
425
+ options: CommandOptions;
426
+ };
427
+ /**
428
+ * The notification part.
429
+ *
430
+ * @beta
431
+ */
432
+ notification: {
433
+ /**
434
+ * Whether to enable notification or not.
435
+ *
436
+ * @beta
437
+ */
438
+ enabled: boolean;
439
+ /**
440
+ * The notification options if notification is enabled.
441
+ *
442
+ * @beta
443
+ */
444
+ options: NotificationOptions_2;
445
+ };
446
+ }
447
+
448
+ /**
449
+ * Initializes new Axios instance with specific auth provider
450
+ *
451
+ * @param apiEndpoint - Base url of the API
452
+ * @param authProvider - Auth provider that injects authentication info to each request
453
+ * @returns axios instance configured with specfic auth provider
454
+ *
455
+ * @example
456
+ * ```typescript
457
+ * const client = createApiClient("https://my-api-endpoint-base-url", new BasicAuthProvider("xxx","xxx"));
458
+ * ```
459
+ *
460
+ * @beta
461
+ */
462
+ export declare function createApiClient(apiEndpoint: string, authProvider: AuthProvider): AxiosInstance;
463
+
252
464
  /**
253
465
  * Get Microsoft graph client.
254
466
  *
@@ -708,28 +920,7 @@ export declare class MsGraphAuthProvider implements AuthenticationProvider {
708
920
  }
709
921
 
710
922
  /**
711
- * Provide static utilities for bot conversation, including
712
- * - send notification to varies targets (e.g., member, channel, incoming wehbook)
713
- * - handle command and response.
714
- *
715
- * @example
716
- * Here's an example on how to send notification via Teams Bot.
717
- * ```typescript
718
- * // initialize (it's recommended to be called before handling any bot message)
719
- * const notificationBot = new NotificationBot(adapter);
720
- *
721
- * // get all bot installations and send message
722
- * for (const target of await notificationBot.installations()) {
723
- * await target.sendMessage("Hello Notification");
724
- * }
725
- *
726
- * // alternative - send message to all members
727
- * for (const target of await notificationBot.installations()) {
728
- * for (const member of await target.members()) {
729
- * await member.sendMessage("Hello Notification");
730
- * }
731
- * }
732
- * ```
923
+ * Provide utilities to send notification to varies targets (e.g., member, channel, incoming wehbook).
733
924
  *
734
925
  * @beta
735
926
  */
@@ -819,7 +1010,7 @@ export declare interface NotificationTarget {
819
1010
  *
820
1011
  * @beta
821
1012
  */
822
- declare interface NotificationTargetStorage {
1013
+ export declare interface NotificationTargetStorage {
823
1014
  /**
824
1015
  * Read one notification target by its key.
825
1016
  *
@@ -1407,17 +1598,17 @@ export declare class TeamsFx implements TeamsFxConfiguration {
1407
1598
  */
1408
1599
  export declare interface TeamsFxBotCommandHandler {
1409
1600
  /**
1410
- * The command name or RegExp pattern that can trigger this handler.
1601
+ * The string or regular expression patterns that can trigger this handler.
1411
1602
  */
1412
- commandNameOrPattern: string | RegExp;
1603
+ triggerPatterns: TriggerPatterns;
1413
1604
  /**
1414
1605
  * Handles a bot command received activity.
1415
1606
  *
1416
1607
  * @param context The bot context.
1417
- * @param receivedText The command text the user types from Teams.
1608
+ * @param message The command message the user types from Teams.
1418
1609
  * @returns A `Promise` representing an activity or text to send as the command response.
1419
1610
  */
1420
- handleCommandReceived(context: TurnContext, receivedText: string): Promise<string | Partial<Activity>>;
1611
+ handleCommandReceived(context: TurnContext, message: CommandMessage): Promise<string | Partial<Activity>>;
1421
1612
  }
1422
1613
 
1423
1614
  /**
@@ -1540,6 +1731,11 @@ export declare class TeamsUserCredential implements TokenCredential {
1540
1731
  getUserInfo(): Promise<UserInfo>;
1541
1732
  }
1542
1733
 
1734
+ /**
1735
+ * The trigger pattern used to trigger a {@link TeamsFxBotCommandHandler} instance.
1736
+ */
1737
+ export declare type TriggerPatterns = string | RegExp | (string | RegExp)[];
1738
+
1543
1739
  /**
1544
1740
  * UserInfo with user displayName, objectId and preferredUserName.
1545
1741
  *