@microsoft/teamsfx 0.6.2 → 0.6.3-alpha.27183ce36.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.
@@ -1,13 +1,88 @@
1
+ /// <reference types="node" />
2
+
1
3
  import { AccessToken } from '@azure/identity';
4
+ import { Activity } from 'botbuilder-core';
5
+ import { Activity as Activity_2 } from 'botbuilder';
6
+ import { Attachment } from 'botbuilder';
2
7
  import { AuthenticationProvider } from '@microsoft/microsoft-graph-client';
8
+ import { AxiosInstance } from 'axios';
9
+ import { AxiosRequestConfig } from 'axios';
10
+ import { BotFrameworkAdapter } from 'botbuilder';
11
+ import { CardAction } from 'botbuilder';
12
+ import { CardImage } from 'botbuilder';
13
+ import { ChannelInfo } from 'botbuilder';
3
14
  import { Client } from '@microsoft/microsoft-graph-client';
4
15
  import { ConnectionConfig } from 'tedious';
16
+ import { ConversationReference } from 'botbuilder';
5
17
  import { Dialog } from 'botbuilder-dialogs';
6
18
  import { DialogContext } from 'botbuilder-dialogs';
7
19
  import { DialogTurnResult } from 'botbuilder-dialogs';
8
20
  import { GetTokenOptions } from '@azure/identity';
21
+ import { HeroCard } from 'botbuilder';
22
+ import { O365ConnectorCard } from 'botbuilder';
23
+ import { ReceiptCard } from 'botbuilder';
24
+ import { SecureContextOptions } from 'tls';
25
+ import { TeamsChannelAccount } from 'botbuilder';
26
+ import { ThumbnailCard } from 'botbuilder';
9
27
  import { TokenCredential } from '@azure/identity';
10
28
  import { TokenResponse } from 'botframework-schema';
29
+ import { TurnContext } from 'botbuilder-core';
30
+ import { TurnContext as TurnContext_2 } from 'botbuilder';
31
+ import { WebRequest } from 'botbuilder';
32
+ import { WebResponse } from 'botbuilder';
33
+
34
+ /**
35
+ * Define available location for API Key location
36
+ *
37
+ * @beta
38
+ */
39
+ export declare enum ApiKeyLocation {
40
+ /**
41
+ * The API Key is placed in request header
42
+ */
43
+ Header = 0,
44
+ /**
45
+ * The API Key is placed in query parameter
46
+ */
47
+ QueryParams = 1
48
+ }
49
+
50
+ /**
51
+ * Provider that handles API Key authentication
52
+ *
53
+ * @beta
54
+ */
55
+ export declare class ApiKeyProvider implements AuthProvider {
56
+ private keyName;
57
+ private keyValue;
58
+ private keyLocation;
59
+ /**
60
+ *
61
+ * @param { string } keyName - The name of request header or query parameter that specifies API Key
62
+ * @param { string } keyValue - The value of API Key
63
+ * @param { ApiKeyLocation } keyLocation - The location of API Key: request header or query parameter.
64
+ *
65
+ * @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
66
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
67
+ *
68
+ * @beta
69
+ */
70
+ constructor(keyName: string, keyValue: string, keyLocation: ApiKeyLocation);
71
+ /**
72
+ * Adds authentication info to http requests
73
+ *
74
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
75
+ * Refer https://axios-http.com/docs/req_config for detailed document.
76
+ *
77
+ * @returns Updated axios request config.
78
+ *
79
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
80
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
81
+ *
82
+ * @beta
83
+ */
84
+ AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
85
+ }
11
86
 
12
87
  /**
13
88
  * Represent Microsoft 365 tenant identity, and it is usually used when user is not involved like time-triggered automation job.
@@ -123,6 +198,430 @@ export declare interface AuthenticationConfiguration {
123
198
  readonly applicationIdUri?: string;
124
199
  }
125
200
 
201
+ /**
202
+ * Defines method that injects authentication info to http requests
203
+ *
204
+ * @beta
205
+ */
206
+ export declare interface AuthProvider {
207
+ /**
208
+ * Adds authentication info to http requests
209
+ *
210
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
211
+ * Refer https://axios-http.com/docs/req_config for detailed document.
212
+ *
213
+ * @beta
214
+ */
215
+ AddAuthenticationInfo: (config: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
216
+ }
217
+
218
+ export { AxiosInstance }
219
+
220
+ /**
221
+ * Provider that handles Basic authentication
222
+ *
223
+ * @beta
224
+ */
225
+ export declare class BasicAuthProvider implements AuthProvider {
226
+ private userName;
227
+ private password;
228
+ /**
229
+ *
230
+ * @param { string } userName - Username used in basic auth
231
+ * @param { string } password - Password used in basic auth
232
+ *
233
+ * @throws {@link ErrorCode|InvalidParameter} - when username or password is empty.
234
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
235
+ *
236
+ * @beta
237
+ */
238
+ constructor(userName: string, password: string);
239
+ /**
240
+ * Adds authentication info to http requests
241
+ *
242
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
243
+ * Refer https://axios-http.com/docs/req_config for detailed document.
244
+ *
245
+ * @returns Updated axios request config.
246
+ *
247
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
248
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
249
+ *
250
+ * @beta
251
+ */
252
+ AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
253
+ }
254
+
255
+ /**
256
+ * Provider that handles Bearer Token authentication
257
+ *
258
+ * @beta
259
+ */
260
+ export declare class BearerTokenAuthProvider implements AuthProvider {
261
+ private getToken;
262
+ /**
263
+ * @param { () => Promise<string> } getToken - Function that returns the content of bearer token used in http request
264
+ *
265
+ * @beta
266
+ */
267
+ constructor(getToken: () => Promise<string>);
268
+ /**
269
+ * Adds authentication info to http requests
270
+ *
271
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
272
+ * Refer https://axios-http.com/docs/req_config for detailed document.
273
+ *
274
+ * @returns Updated axios request config.
275
+ *
276
+ * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header already exists in request configuration.
277
+ *
278
+ * @beta
279
+ */
280
+ AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
281
+ }
282
+
283
+ /**
284
+ * Provider that handles Certificate authentication
285
+ *
286
+ * @beta
287
+ */
288
+ export declare class CertificateAuthProvider implements AuthProvider {
289
+ private certOption;
290
+ /**
291
+ *
292
+ * @param { SecureContextOptions } certOption - information about the cert used in http requests
293
+ *
294
+ * @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
295
+ *
296
+ * @beta
297
+ */
298
+ constructor(certOption: SecureContextOptions);
299
+ /**
300
+ * Adds authentication info to http requests.
301
+ *
302
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
303
+ * Refer https://axios-http.com/docs/req_config for detailed document.
304
+ *
305
+ * @returns Updated axios request config.
306
+ *
307
+ * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
308
+ *
309
+ * @beta
310
+ */
311
+ AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
312
+ }
313
+
314
+ /**
315
+ * A {@link NotificationTarget} that represents a team channel.
316
+ *
317
+ * @remarks
318
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
319
+ *
320
+ * @beta
321
+ */
322
+ export declare class Channel implements NotificationTarget {
323
+ /**
324
+ * The parent {@link TeamsBotInstallation} where this channel is created from.
325
+ *
326
+ * @beta
327
+ */
328
+ readonly parent: TeamsBotInstallation;
329
+ /**
330
+ * Detailed channel information.
331
+ *
332
+ * @beta
333
+ */
334
+ readonly info: ChannelInfo;
335
+ /**
336
+ * Notification target type. For channel it's always "Channel".
337
+ *
338
+ * @beta
339
+ */
340
+ readonly type: NotificationTargetType;
341
+ /**
342
+ * Constuctor.
343
+ *
344
+ * @remarks
345
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
346
+ *
347
+ * @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
348
+ * @param info - Detailed channel information.
349
+ *
350
+ * @beta
351
+ */
352
+ constructor(parent: TeamsBotInstallation, info: ChannelInfo);
353
+ /**
354
+ * Send a plain text message.
355
+ *
356
+ * @param text - the plain text message.
357
+ * @returns A `Promise` representing the asynchronous operation.
358
+ *
359
+ * @beta
360
+ */
361
+ sendMessage(text: string): Promise<void>;
362
+ /**
363
+ * Send an adaptive card message.
364
+ *
365
+ * @param card - the adaptive card raw JSON.
366
+ * @returns A `Promise` representing the asynchronous operation.
367
+ *
368
+ * @beta
369
+ */
370
+ sendAdaptiveCard(card: unknown): Promise<void>;
371
+ /**
372
+ * @internal
373
+ */
374
+ private newConversation;
375
+ }
376
+
377
+ /**
378
+ * A command bot for receiving commands and sending responses in Teams.
379
+ *
380
+ * @remarks
381
+ * 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.
382
+ *
383
+ * @beta
384
+ */
385
+ export declare class CommandBot {
386
+ private readonly adapter;
387
+ private readonly middleware;
388
+ /**
389
+ * Creates a new instance of the `CommandBot`.
390
+ *
391
+ * @param adapter The bound `BotFrameworkAdapter`.
392
+ * @param options - initialize options
393
+ *
394
+ * @beta
395
+ */
396
+ constructor(adapter: BotFrameworkAdapter, options?: CommandOptions);
397
+ /**
398
+ * Registers a command into the command bot.
399
+ *
400
+ * @param command The command to registered.
401
+ *
402
+ * @beta
403
+ */
404
+ registerCommand(command: TeamsFxBotCommandHandler): void;
405
+ /**
406
+ * Registers commands into the command bot.
407
+ *
408
+ * @param commands The command to registered.
409
+ *
410
+ * @beta
411
+ */
412
+ registerCommands(commands: TeamsFxBotCommandHandler[]): void;
413
+ }
414
+
415
+ /**
416
+ * Interface for a command messagge that can handled in a command handler.
417
+ */
418
+ export declare interface CommandMessage {
419
+ /**
420
+ * Text of the message sent by the user.
421
+ */
422
+ text: string;
423
+ /**
424
+ * The capture groups that matched to the {@link TriggerPatterns} in a {@link TeamsFxBotCommandHandler} instance.
425
+ */
426
+ matches?: RegExpMatchArray;
427
+ }
428
+
429
+ /**
430
+ * Options to initialize {@link CommandBot}.
431
+ *
432
+ * @beta
433
+ */
434
+ export declare interface CommandOptions {
435
+ /**
436
+ * 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.
437
+ *
438
+ * @beta
439
+ */
440
+ commands?: TeamsFxBotCommandHandler[];
441
+ }
442
+
443
+ /**
444
+ * Provide utilities for bot conversation, including:
445
+ * - handle command and response.
446
+ * - send notification to varies targets (e.g., member, group, channel).
447
+ *
448
+ * @example
449
+ * For command and response, you can register your commands through the constructor, or use the `registerCommand` and `registerCommands` API to add commands later.
450
+ *
451
+ * ```typescript
452
+ * // register through constructor
453
+ * const conversationBot = new ConversationBot({
454
+ * command: {
455
+ * enabled: true,
456
+ * commands: [ new HelloWorldCommandHandler() ],
457
+ * },
458
+ * });
459
+ *
460
+ * // register through `register*` API
461
+ * conversationBot.command.registerCommand(new HelpCommandHandler());
462
+ * ```
463
+ *
464
+ * For notification, you can enable notification at initialization, then send notifications at any time.
465
+ *
466
+ * ```typescript
467
+ * // enable through constructor
468
+ * const conversationBot = new ConversationBot({
469
+ * notification: {
470
+ * enabled: true,
471
+ * },
472
+ * });
473
+ *
474
+ * // get all bot installations and send message
475
+ * for (const target of await conversationBot.notification.installations()) {
476
+ * await target.sendMessage("Hello Notification");
477
+ * }
478
+ *
479
+ * // alternative - send message to all members
480
+ * for (const target of await conversationBot.notification.installations()) {
481
+ * for (const member of await target.members()) {
482
+ * await member.sendMessage("Hello Notification");
483
+ * }
484
+ * }
485
+ * ```
486
+ *
487
+ * @remarks
488
+ * Set `adapter` in {@link ConversationOptions} to use your own bot adapter.
489
+ *
490
+ * 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.
491
+ *
492
+ * For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
493
+ *
494
+ * @beta
495
+ */
496
+ export declare class ConversationBot {
497
+ /**
498
+ * The bot adapter.
499
+ *
500
+ * @beta
501
+ */
502
+ readonly adapter: BotFrameworkAdapter;
503
+ /**
504
+ * The entrypoint of command and response.
505
+ *
506
+ * @beta
507
+ */
508
+ readonly command?: CommandBot;
509
+ /**
510
+ * The entrypoint of notification.
511
+ *
512
+ * @beta
513
+ */
514
+ readonly notification?: NotificationBot;
515
+ /**
516
+ * Creates new instance of the `ConversationBot`.
517
+ *
518
+ * @remarks
519
+ * It's recommended to create your own adapter and storage for production environment instead of the default one.
520
+ *
521
+ * @param options - initialize options
522
+ *
523
+ * @beta
524
+ */
525
+ constructor(options: ConversationOptions);
526
+ private createDefaultAdapter;
527
+ /**
528
+ * The request handler to integrate with web request.
529
+ *
530
+ * @param req - an Express or Restify style request object.
531
+ * @param res - an Express or Restify style response object.
532
+ * @param logic - the additional function to handle bot context.
533
+ *
534
+ * @example
535
+ * For example, to use with Restify:
536
+ * ``` typescript
537
+ * // The default/empty behavior
538
+ * server.post("api/messages", conversationBot.requestHandler);
539
+ *
540
+ * // Or, add your own logic
541
+ * server.post("api/messages", async (req, res) => {
542
+ * await conversationBot.requestHandler(req, res, async (context) => {
543
+ * // your-own-context-logic
544
+ * });
545
+ * });
546
+ * ```
547
+ *
548
+ * @beta
549
+ */
550
+ requestHandler(req: WebRequest, res: WebResponse, logic?: (context: TurnContext_2) => Promise<any>): Promise<void>;
551
+ }
552
+
553
+ /**
554
+ * Options to initialize {@link ConversationBot}
555
+ *
556
+ * @beta
557
+ */
558
+ export declare interface ConversationOptions {
559
+ /**
560
+ * The bot adapter. If not provided, a default adapter will be created:
561
+ * - with `adapterConfig` as constructor parameter.
562
+ * - with a default error handler that logs error to console, sends trace activity, and sends error message to user.
563
+ *
564
+ * @remarks
565
+ * If neither `adapter` nor `adapterConfig` is provided, will use BOT_ID and BOT_PASSWORD from environment variables.
566
+ *
567
+ * @beta
568
+ */
569
+ adapter?: BotFrameworkAdapter;
570
+ /**
571
+ * If `adapter` is not provided, this `adapterConfig` will be passed to the new `BotFrameworkAdapter` when created internally.
572
+ *
573
+ * @remarks
574
+ * If neither `adapter` nor `adapterConfig` is provided, will use BOT_ID and BOT_PASSWORD from environment variables.
575
+ *
576
+ * @beta
577
+ */
578
+ adapterConfig?: {
579
+ [key: string]: unknown;
580
+ };
581
+ /**
582
+ * The command part.
583
+ *
584
+ * @beta
585
+ */
586
+ command?: CommandOptions & {
587
+ /**
588
+ * Whether to enable command or not.
589
+ *
590
+ * @beta
591
+ */
592
+ enabled?: boolean;
593
+ };
594
+ /**
595
+ * The notification part.
596
+ *
597
+ * @beta
598
+ */
599
+ notification?: NotificationOptions_2 & {
600
+ /**
601
+ * Whether to enable notification or not.
602
+ *
603
+ * @beta
604
+ */
605
+ enabled?: boolean;
606
+ };
607
+ }
608
+
609
+ /**
610
+ * Initializes new Axios instance with specific auth provider
611
+ *
612
+ * @param apiEndpoint - Base url of the API
613
+ * @param authProvider - Auth provider that injects authentication info to each request
614
+ * @returns axios instance configured with specfic auth provider
615
+ *
616
+ * @example
617
+ * ```typescript
618
+ * const client = createApiClient("https://my-api-endpoint-base-url", new BasicAuthProvider("xxx","xxx"));
619
+ * ```
620
+ *
621
+ * @beta
622
+ */
623
+ export declare function createApiClient(apiEndpoint: string, authProvider: AuthProvider): AxiosInstance;
624
+
126
625
  /**
127
626
  * Get Microsoft graph client.
128
627
  *
@@ -176,6 +675,38 @@ export declare interface AuthenticationConfiguration {
176
675
  */
177
676
  export declare function createMicrosoftGraphClient(teamsfx: TeamsFxConfiguration, scopes?: string | string[]): Client;
178
677
 
678
+ /**
679
+ * Helper to create SecureContextOptions from PEM format cert
680
+ *
681
+ * @param { string | Buffer } cert - The cert chain in PEM format
682
+ * @param { string | Buffer } key - The private key for the cert chain
683
+ * @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
684
+ *
685
+ * @returns Instance of SecureContextOptions
686
+ *
687
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
688
+ *
689
+ */
690
+ export declare function createPemCertOption(cert: string | Buffer, key: string | Buffer, options?: {
691
+ passphrase?: string;
692
+ ca?: string | Buffer;
693
+ }): SecureContextOptions;
694
+
695
+ /**
696
+ * Helper to create SecureContextOptions from PFX format cert
697
+ *
698
+ * @param { string | Buffer } pfx - The content of .pfx file
699
+ * @param { {passphrase?: string} } options - Optional settings when create the cert options.
700
+ *
701
+ * @returns Instance of SecureContextOptions
702
+ *
703
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
704
+ *
705
+ */
706
+ export declare function createPfxCertOption(pfx: string | Buffer, options?: {
707
+ passphrase?: string;
708
+ }): SecureContextOptions;
709
+
179
710
  /**
180
711
  * Error code to trace the error types.
181
712
  * @beta
@@ -216,179 +747,522 @@ export declare enum ErrorCode {
216
747
  /**
217
748
  * Token is not within its valid time range error.
218
749
  */
219
- TokenExpiredError = "TokenExpiredError",
750
+ TokenExpiredError = "TokenExpiredError",
751
+ /**
752
+ * Call service (AAD or simple authentication server) failed.
753
+ */
754
+ ServiceError = "ServiceError",
755
+ /**
756
+ * Operation failed.
757
+ */
758
+ FailedOperation = "FailedOperation",
759
+ /**
760
+ * Invalid response error.
761
+ */
762
+ InvalidResponse = "InvalidResponse",
763
+ /**
764
+ * Identity type error.
765
+ */
766
+ IdentityTypeNotSupported = "IdentityTypeNotSupported",
767
+ /**
768
+ * Authentication info already exists error.
769
+ */
770
+ AuthorizationInfoAlreadyExists = "AuthorizationInfoAlreadyExists"
771
+ }
772
+
773
+ /**
774
+ * Error class with code and message thrown by the SDK.
775
+ *
776
+ * @beta
777
+ */
778
+ export declare class ErrorWithCode extends Error {
779
+ /**
780
+ * Error code
781
+ *
782
+ * @readonly
783
+ */
784
+ code: string | undefined;
785
+ /**
786
+ * Constructor of ErrorWithCode.
787
+ *
788
+ * @param {string} message - error message.
789
+ * @param {ErrorCode} code - error code.
790
+ *
791
+ * @beta
792
+ */
793
+ constructor(message?: string, code?: ErrorCode);
794
+ }
795
+
796
+ /**
797
+ * Get log level.
798
+ *
799
+ * @returns Log level
800
+ *
801
+ * @beta
802
+ */
803
+ export declare function getLogLevel(): LogLevel | undefined;
804
+
805
+ /**
806
+ * Generate connection configuration consumed by tedious.
807
+ *
808
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth
809
+ * @param { string? } databaseName - specify database name to override default one if there are multiple databases.
810
+ *
811
+ * @returns Connection configuration of tedious for the SQL.
812
+ *
813
+ * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
814
+ * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
815
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
816
+ *
817
+ * @beta
818
+ */
819
+ export declare function getTediousConnectionConfig(teamsfx: TeamsFx, databaseName?: string): Promise<ConnectionConfig>;
820
+
821
+ /**
822
+ * Identity type to use in authentication.
823
+ *
824
+ * @beta
825
+ */
826
+ export declare enum IdentityType {
827
+ /**
828
+ * Represents the current user of Teams.
829
+ */
830
+ User = "User",
831
+ /**
832
+ * Represents the application itself.
833
+ */
834
+ App = "Application"
835
+ }
836
+
837
+ /**
838
+ * Log function for customized logging.
839
+ *
840
+ * @beta
841
+ */
842
+ export declare type LogFunction = (level: LogLevel, message: string) => void;
843
+
844
+ /**
845
+ * Interface for customized logger.
846
+ * @beta
847
+ */
848
+ export declare interface Logger {
849
+ /**
850
+ * Writes to error level logging or lower.
851
+ */
852
+ error(message: string): void;
853
+ /**
854
+ * Writes to warning level logging or lower.
855
+ */
856
+ warn(message: string): void;
857
+ /**
858
+ * Writes to info level logging or lower.
859
+ */
860
+ info(message: string): void;
861
+ /**
862
+ * Writes to verbose level logging.
863
+ */
864
+ verbose(message: string): void;
865
+ }
866
+
867
+ /**
868
+ * Log level.
869
+ *
870
+ * @beta
871
+ */
872
+ export declare enum LogLevel {
873
+ /**
874
+ * Show verbose, information, warning and error message.
875
+ */
876
+ Verbose = 0,
877
+ /**
878
+ * Show information, warning and error message.
879
+ */
880
+ Info = 1,
881
+ /**
882
+ * Show warning and error message.
883
+ */
884
+ Warn = 2,
885
+ /**
886
+ * Show error message.
887
+ */
888
+ Error = 3
889
+ }
890
+
891
+ /**
892
+ * A {@link NotificationTarget} that represents a team member.
893
+ *
894
+ * @remarks
895
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}.
896
+ *
897
+ * @beta
898
+ */
899
+ export declare class Member implements NotificationTarget {
900
+ /**
901
+ * The parent {@link TeamsBotInstallation} where this member is created from.
902
+ *
903
+ * @beta
904
+ */
905
+ readonly parent: TeamsBotInstallation;
906
+ /**
907
+ * Detailed member account information.
908
+ *
909
+ * @beta
910
+ */
911
+ readonly account: TeamsChannelAccount;
912
+ /**
913
+ * Notification target type. For member it's always "Person".
914
+ *
915
+ * @beta
916
+ */
917
+ readonly type: NotificationTargetType;
918
+ /**
919
+ * Constuctor.
920
+ *
921
+ * @remarks
922
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
923
+ *
924
+ * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
925
+ * @param account - Detailed member account information.
926
+ *
927
+ * @beta
928
+ */
929
+ constructor(parent: TeamsBotInstallation, account: TeamsChannelAccount);
930
+ /**
931
+ * Send a plain text message.
932
+ *
933
+ * @param text - the plain text message.
934
+ * @returns A `Promise` representing the asynchronous operation.
935
+ *
936
+ * @beta
937
+ */
938
+ sendMessage(text: string): Promise<void>;
939
+ /**
940
+ * Send an adaptive card message.
941
+ *
942
+ * @param card - the adaptive card raw JSON.
943
+ * @returns A `Promise` representing the asynchronous operation.
944
+ *
945
+ * @beta
946
+ */
947
+ sendAdaptiveCard(card: unknown): Promise<void>;
948
+ /**
949
+ * @internal
950
+ */
951
+ private newConversation;
952
+ }
953
+
954
+ /**
955
+ * Provides utility method to build bot message with cards that supported in Teams.
956
+ */
957
+ export declare class MessageBuilder {
958
+ /**
959
+ * Build a bot message activity attached with adaptive card.
960
+ *
961
+ * @param cardTemplate The adaptive card template.
962
+ * @param data card data used to render the template.
963
+ * @returns A bot message activity attached with an adaptive card.
964
+ *
965
+ * @example
966
+ * ```javascript
967
+ * const cardTemplate = {
968
+ * type: "AdaptiveCard",
969
+ * body: [
970
+ * {
971
+ * "type": "TextBlock",
972
+ * "text": "${title}",
973
+ * "size": "Large"
974
+ * },
975
+ * {
976
+ * "type": "TextBlock",
977
+ * "text": "${description}"
978
+ * }],
979
+ * $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
980
+ * version: "1.4"
981
+ * };
982
+ *
983
+ * type CardData = {
984
+ * title: string,
985
+ * description: string
986
+ * };
987
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(
988
+ * cardTemplate, {
989
+ * title: "sample card title",
990
+ * description: "sample card description"
991
+ * });
992
+ * ```
993
+ *
994
+ * @beta
995
+ */
996
+ static attachAdaptiveCard<TData>(cardTemplate: any, data: TData): Partial<Activity_2>;
997
+ /**
998
+ * Build a bot message activity attached with an adaptive card.
999
+ *
1000
+ * @param card The adaptive card content.
1001
+ * @returns A bot message activity attached with an adaptive card.
1002
+ *
1003
+ * @beta
1004
+ */
1005
+ static attachAdaptiveCardWithoutData(card: any): Partial<Activity_2>;
1006
+ /**
1007
+ * Build a bot message activity attached with an hero card.
1008
+ *
1009
+ * @param title The card title.
1010
+ * @param images Optional. The array of images to include on the card.
1011
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
1012
+ * is converted to an `imBack` button with a title and value set to the value of the string.
1013
+ * @param other Optional. Any additional properties to include on the card.
1014
+ *
1015
+ * @returns A bot message activity attached with a hero card.
1016
+ *
1017
+ * @example
1018
+ * ```javascript
1019
+ * const message = MessageBuilder.attachHeroCard(
1020
+ * 'sample title',
1021
+ * ['https://example.com/sample.jpg'],
1022
+ * ['action']
1023
+ * );
1024
+ * ```
1025
+ *
1026
+ * @beta
1027
+ */
1028
+ static attachHeroCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<HeroCard>): Partial<Activity_2>;
1029
+ /**
1030
+ * Returns an attachment for a sign-in card.
1031
+ *
1032
+ * @param title The title for the card's sign-in button.
1033
+ * @param url The URL of the sign-in page to use.
1034
+ * @param text Optional. Additional text to include on the card.
1035
+ *
1036
+ * @returns A bot message activity attached with a sign-in card.
1037
+ *
1038
+ * @remarks
1039
+ * For channels that don't natively support sign-in cards, an alternative message is rendered.
1040
+ *
1041
+ * @beta
1042
+ */
1043
+ static attachSigninCard(title: string, url: string, text?: string): Partial<Activity_2>;
220
1044
  /**
221
- * Call service (AAD or simple authentication server) failed.
1045
+ * Build a bot message activity attached with an Office 365 connector card.
1046
+ *
1047
+ * @param card A description of the Office 365 connector card.
1048
+ * @returns A bot message activity attached with an Office 365 connector card.
1049
+ *
1050
+ * @beta
222
1051
  */
223
- ServiceError = "ServiceError",
1052
+ static attachO365ConnectorCard(card: O365ConnectorCard): Partial<Activity_2>;
224
1053
  /**
225
- * Operation failed.
1054
+ * Build a message activity attached with a receipt card.
1055
+ * @param card A description of the receipt card.
1056
+ * @returns A message activity attached with a receipt card.
1057
+ *
1058
+ * @beta
226
1059
  */
227
- FailedOperation = "FailedOperation",
1060
+ static AttachReceiptCard(card: ReceiptCard): Partial<Activity_2>;
228
1061
  /**
229
- * Invalid response error.
1062
+ *
1063
+ * @param title The card title.
1064
+ * @param images Optional. The array of images to include on the card.
1065
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
1066
+ * is converted to an `imBack` button with a title and value set to the value of the string.
1067
+ * @param other Optional. Any additional properties to include on the card.
1068
+ * @returns A message activity attached with a thumbnail card
1069
+ *
1070
+ * @beta
230
1071
  */
231
- InvalidResponse = "InvalidResponse",
1072
+ static attachThumbnailCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<ThumbnailCard>): Partial<Activity_2>;
232
1073
  /**
233
- * Identity type error.
1074
+ * Add an attachement to a bot activity.
1075
+ * @param attachement The attachment object to attach.
1076
+ * @returns A message activity with an attachment.
1077
+ *
1078
+ * @beta
234
1079
  */
235
- IdentityTypeNotSupported = "IdentityTypeNotSupported"
1080
+ static attachContent(attachement: Attachment): Partial<Activity_2>;
236
1081
  }
237
1082
 
238
1083
  /**
239
- * Error class with code and message thrown by the SDK.
1084
+ * Microsoft Graph auth provider for Teams Framework
240
1085
  *
241
1086
  * @beta
242
1087
  */
243
- export declare class ErrorWithCode extends Error {
1088
+ export declare class MsGraphAuthProvider implements AuthenticationProvider {
1089
+ private teamsfx;
1090
+ private scopes;
244
1091
  /**
245
- * Error code
1092
+ * Constructor of MsGraphAuthProvider.
246
1093
  *
247
- * @readonly
1094
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
1095
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1096
+ *
1097
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1098
+ *
1099
+ * @returns An instance of MsGraphAuthProvider.
1100
+ *
1101
+ * @beta
248
1102
  */
249
- code: string | undefined;
1103
+ constructor(teamsfx: TeamsFxConfiguration, scopes?: string | string[]);
250
1104
  /**
251
- * Constructor of ErrorWithCode.
1105
+ * Get access token for Microsoft Graph API requests.
252
1106
  *
253
- * @param {string} message - error message.
254
- * @param {ErrorCode} code - error code.
1107
+ * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
1108
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1109
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1110
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
1111
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1112
+ *
1113
+ * @returns Access token from the credential.
255
1114
  *
256
- * @beta
257
1115
  */
258
- constructor(message?: string, code?: ErrorCode);
1116
+ getAccessToken(): Promise<string>;
259
1117
  }
260
1118
 
261
1119
  /**
262
- * Get log level.
263
- *
264
- * @returns Log level
265
- *
266
- * @beta
267
- */
268
- export declare function getLogLevel(): LogLevel | undefined;
269
-
270
- /**
271
- * Generate connection configuration consumed by tedious.
272
- *
273
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth
274
- * @param { string? } databaseName - specify database name to override default one if there are multiple databases.
275
- *
276
- * @returns Connection configuration of tedious for the SQL.
277
- *
278
- * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
279
- * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
280
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
281
- *
282
- * @beta
283
- */
284
- export declare function getTediousConnectionConfig(teamsfx: TeamsFx, databaseName?: string): Promise<ConnectionConfig>;
285
-
286
- /**
287
- * Identity type to use in authentication.
1120
+ * Provide utilities to send notification to varies targets (e.g., member, group, channel).
288
1121
  *
289
1122
  * @beta
290
1123
  */
291
- export declare enum IdentityType {
1124
+ export declare class NotificationBot {
1125
+ private readonly conversationReferenceStore;
1126
+ private readonly adapter;
292
1127
  /**
293
- * Represents the current user of Teams.
1128
+ * constructor of the notification bot.
1129
+ *
1130
+ * @remarks
1131
+ * To ensure accuracy, it's recommended to initialize before handling any message.
1132
+ *
1133
+ * @param adapter - the bound `BotFrameworkAdapter`
1134
+ * @param options - initialize options
1135
+ *
1136
+ * @beta
294
1137
  */
295
- User = "User",
1138
+ constructor(adapter: BotFrameworkAdapter, options?: NotificationOptions_2);
296
1139
  /**
297
- * Represents the application itself.
1140
+ * Get all targets where the bot is installed.
1141
+ *
1142
+ * @remarks
1143
+ * The result is retrieving from the persisted storage.
1144
+ *
1145
+ * @returns - an array of {@link TeamsBotInstallation}.
1146
+ *
1147
+ * @beta
298
1148
  */
299
- App = "Application"
1149
+ installations(): Promise<TeamsBotInstallation[]>;
300
1150
  }
301
1151
 
302
1152
  /**
303
- * Log function for customized logging.
1153
+ * Options to initialize {@link NotificationBot}.
304
1154
  *
305
1155
  * @beta
306
1156
  */
307
- export declare type LogFunction = (level: LogLevel, message: string) => void;
308
-
309
- /**
310
- * Interface for customized logger.
311
- * @beta
312
- */
313
- export declare interface Logger {
314
- /**
315
- * Writes to error level logging or lower.
316
- */
317
- error(message: string): void;
318
- /**
319
- * Writes to warning level logging or lower.
320
- */
321
- warn(message: string): void;
322
- /**
323
- * Writes to info level logging or lower.
324
- */
325
- info(message: string): void;
1157
+ declare interface NotificationOptions_2 {
326
1158
  /**
327
- * Writes to verbose level logging.
1159
+ * An optional storage to persist bot notification connections.
1160
+ *
1161
+ * @remarks
1162
+ * If `storage` is not provided, a default local file storage will be used,
1163
+ * which stores notification connections into:
1164
+ * - ".notification.localstore.json" if running locally
1165
+ * - "${process.env.TEMP}/.notification.localstore.json" if `process.env.RUNNING_ON_AZURE` is set to "1"
1166
+ *
1167
+ * It's recommended to use your own shared storage for production environment.
1168
+ *
1169
+ * @beta
328
1170
  */
329
- verbose(message: string): void;
1171
+ storage?: NotificationTargetStorage;
330
1172
  }
1173
+ export { NotificationOptions_2 as NotificationOptions }
331
1174
 
332
1175
  /**
333
- * Log level.
1176
+ * Represent a notification target.
334
1177
  *
335
1178
  * @beta
336
1179
  */
337
- export declare enum LogLevel {
338
- /**
339
- * Show verbose, information, warning and error message.
340
- */
341
- Verbose = 0,
1180
+ export declare interface NotificationTarget {
342
1181
  /**
343
- * Show information, warning and error message.
1182
+ * The type of target, could be "Channel" or "Group" or "Person".
1183
+ *
1184
+ * @beta
344
1185
  */
345
- Info = 1,
1186
+ readonly type?: NotificationTargetType;
346
1187
  /**
347
- * Show warning and error message.
1188
+ * Send a plain text message.
1189
+ *
1190
+ * @param text - the plain text message.
1191
+ *
1192
+ * @beta
348
1193
  */
349
- Warn = 2,
1194
+ sendMessage(text: string): Promise<void>;
350
1195
  /**
351
- * Show error message.
1196
+ * Send an adaptive card message.
1197
+ *
1198
+ * @param card - the adaptive card raw JSON.
1199
+ *
1200
+ * @beta
352
1201
  */
353
- Error = 3
1202
+ sendAdaptiveCard(card: unknown): Promise<void>;
354
1203
  }
355
1204
 
356
1205
  /**
357
- * Microsoft Graph auth provider for Teams Framework
1206
+ * Interface for a storage provider that stores and retrieves notification target references.
358
1207
  *
359
1208
  * @beta
360
1209
  */
361
- export declare class MsGraphAuthProvider implements AuthenticationProvider {
362
- private teamsfx;
363
- private scopes;
1210
+ export declare interface NotificationTargetStorage {
364
1211
  /**
365
- * Constructor of MsGraphAuthProvider.
1212
+ * Read one notification target by its key.
366
1213
  *
367
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
368
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1214
+ * @param key - the key of a notification target.
369
1215
  *
370
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1216
+ * @returns - the notification target. Or undefined if not found.
371
1217
  *
372
- * @returns An instance of MsGraphAuthProvider.
1218
+ * @beta
1219
+ */
1220
+ read(key: string): Promise<{
1221
+ [key: string]: unknown;
1222
+ } | undefined>;
1223
+ /**
1224
+ * List all stored notification targets.
1225
+ *
1226
+ * @returns - an array of notification target. Or an empty array if nothing is stored.
373
1227
  *
374
1228
  * @beta
375
1229
  */
376
- constructor(teamsfx: TeamsFxConfiguration, scopes?: string | string[]);
1230
+ list(): Promise<{
1231
+ [key: string]: unknown;
1232
+ }[]>;
377
1233
  /**
378
- * Get access token for Microsoft Graph API requests.
1234
+ * Write one notification target by its key.
379
1235
  *
380
- * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
381
- * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
382
- * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
383
- * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
384
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1236
+ * @param key - the key of a notification target.
1237
+ * @param object - the notification target.
385
1238
  *
386
- * @returns Access token from the credential.
1239
+ * @beta
1240
+ */
1241
+ write(key: string, object: {
1242
+ [key: string]: unknown;
1243
+ }): Promise<void>;
1244
+ /**
1245
+ * Delete one notificaton target by its key.
1246
+ *
1247
+ * @param key - the key of a notification target.
387
1248
  *
1249
+ * @beta
388
1250
  */
389
- getAccessToken(): Promise<string>;
1251
+ delete(key: string): Promise<void>;
390
1252
  }
391
1253
 
1254
+ /**
1255
+ * The target type where the notification will be sent to.
1256
+ *
1257
+ * @remarks
1258
+ * - "Channel" means to a team channel. (By default, notification to a team will be sent to its "General" channel.)
1259
+ * - "Group" means to a group chat.
1260
+ * - "Person" means to a personal chat.
1261
+ *
1262
+ * @beta
1263
+ */
1264
+ export declare type NotificationTargetType = "Channel" | "Group" | "Person";
1265
+
392
1266
  /**
393
1267
  * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
394
1268
  *
@@ -476,6 +1350,28 @@ export declare class OnBehalfOfUserCredential implements TokenCredential {
476
1350
  private generateAuthServerError;
477
1351
  }
478
1352
 
1353
+ /**
1354
+ * Send an adaptive card message to a notification target.
1355
+ *
1356
+ * @param target - the notification target.
1357
+ * @param card - the adaptive card raw JSON.
1358
+ * @returns A `Promise` representing the asynchronous operation.
1359
+ *
1360
+ * @beta
1361
+ */
1362
+ export declare function sendAdaptiveCard(target: NotificationTarget, card: unknown): Promise<void>;
1363
+
1364
+ /**
1365
+ * Send a plain text message to a notification target.
1366
+ *
1367
+ * @param target - the notification target.
1368
+ * @param text - the plain text message.
1369
+ * @returns A `Promise` representing the asynchronous operation.
1370
+ *
1371
+ * @beta
1372
+ */
1373
+ export declare function sendMessage(target: NotificationTarget, text: string): Promise<void>;
1374
+
479
1375
  /**
480
1376
  * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
481
1377
  *
@@ -522,6 +1418,89 @@ export declare function setLogger(logger?: Logger): void;
522
1418
  */
523
1419
  export declare function setLogLevel(level: LogLevel): void;
524
1420
 
1421
+ /**
1422
+ * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1423
+ * - Personal chat
1424
+ * - Group chat
1425
+ * - Team (by default the `General` channel)
1426
+ *
1427
+ * @remarks
1428
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1429
+ *
1430
+ * @beta
1431
+ */
1432
+ export declare class TeamsBotInstallation implements NotificationTarget {
1433
+ /**
1434
+ * The bound `BotFrameworkAdapter`.
1435
+ *
1436
+ * @beta
1437
+ */
1438
+ readonly adapter: BotFrameworkAdapter;
1439
+ /**
1440
+ * The bound `ConversationReference`.
1441
+ *
1442
+ * @beta
1443
+ */
1444
+ readonly conversationReference: Partial<ConversationReference>;
1445
+ /**
1446
+ * Notification target type.
1447
+ *
1448
+ * @remarks
1449
+ * - "Channel" means bot is installed into a team and notification will be sent to its "General" channel.
1450
+ * - "Group" means bot is installed into a group chat.
1451
+ * - "Person" means bot is installed into a personal scope and notification will be sent to personal chat.
1452
+ *
1453
+ * @beta
1454
+ */
1455
+ readonly type?: NotificationTargetType;
1456
+ /**
1457
+ * Constructor
1458
+ *
1459
+ * @remarks
1460
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1461
+ *
1462
+ * @param adapter - the bound `BotFrameworkAdapter`.
1463
+ * @param conversationReference - the bound `ConversationReference`.
1464
+ *
1465
+ * @beta
1466
+ */
1467
+ constructor(adapter: BotFrameworkAdapter, conversationReference: Partial<ConversationReference>);
1468
+ /**
1469
+ * Send a plain text message.
1470
+ *
1471
+ * @param text - the plain text message.
1472
+ * @returns A `Promise` representing the asynchronous operation.
1473
+ *
1474
+ * @beta
1475
+ */
1476
+ sendMessage(text: string): Promise<void>;
1477
+ /**
1478
+ * Send an adaptive card message.
1479
+ *
1480
+ * @param card - the adaptive card raw JSON.
1481
+ * @returns A `Promise` representing the asynchronous operation.
1482
+ *
1483
+ * @beta
1484
+ */
1485
+ sendAdaptiveCard(card: unknown): Promise<void>;
1486
+ /**
1487
+ * Get channels from this bot installation.
1488
+ *
1489
+ * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1490
+ *
1491
+ * @beta
1492
+ */
1493
+ channels(): Promise<Channel[]>;
1494
+ /**
1495
+ * Get members from this bot installation.
1496
+ *
1497
+ * @returns an array of members from where the bot is installed.
1498
+ *
1499
+ * @beta
1500
+ */
1501
+ members(): Promise<Member[]>;
1502
+ }
1503
+
525
1504
  /**
526
1505
  * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
527
1506
  * help receive oauth token, asks the user to consent if needed.
@@ -809,6 +1788,26 @@ export declare class TeamsFx implements TeamsFxConfiguration {
809
1788
  private loadFromEnv;
810
1789
  }
811
1790
 
1791
+ /**
1792
+ * Interface for a command handler that can process command to a TeamsFx bot and return a response.
1793
+ *
1794
+ * @beta
1795
+ */
1796
+ export declare interface TeamsFxBotCommandHandler {
1797
+ /**
1798
+ * The string or regular expression patterns that can trigger this handler.
1799
+ */
1800
+ triggerPatterns: TriggerPatterns;
1801
+ /**
1802
+ * Handles a bot command received activity.
1803
+ *
1804
+ * @param context The bot context.
1805
+ * @param message The command message the user types from Teams.
1806
+ * @returns A `Promise` representing an activity or text to send as the command response.
1807
+ */
1808
+ handleCommandReceived(context: TurnContext, message: CommandMessage): Promise<string | Partial<Activity>>;
1809
+ }
1810
+
812
1811
  /**
813
1812
  * TeamsFx interface that provides credential and configuration.
814
1813
  * @beta
@@ -929,6 +1928,11 @@ export declare class TeamsUserCredential implements TokenCredential {
929
1928
  getUserInfo(): Promise<UserInfo>;
930
1929
  }
931
1930
 
1931
+ /**
1932
+ * The trigger pattern used to trigger a {@link TeamsFxBotCommandHandler} instance.
1933
+ */
1934
+ export declare type TriggerPatterns = string | RegExp | (string | RegExp)[];
1935
+
932
1936
  /**
933
1937
  * UserInfo with user displayName, objectId and preferredUserName.
934
1938
  *