@microsoft/teamsfx 0.6.2-alpha.67e38d838.0 → 0.6.2-alpha.6de687a73.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.67e38d838.0",
3
+ "version": "0.6.2-alpha.6de687a73.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,6 +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.6de687a73.0",
52
53
  "@microsoft/microsoft-graph-client": "^3.0.1",
53
54
  "axios": "^0.24.0",
54
55
  "botbuilder": ">=4.15.0 <5.0.0",
@@ -126,7 +127,7 @@
126
127
  "webpack": "^5.62.1",
127
128
  "yargs": "^17.2.1"
128
129
  },
129
- "gitHead": "52be3a239d021b643b404c9794aa028149f88175",
130
+ "gitHead": "f808c823a5ef1e4165bf382ee66975a3c16cedc5",
130
131
  "publishConfig": {
131
132
  "access": "public"
132
133
  },
@@ -1,13 +1,27 @@
1
1
  import { AccessToken } from '@azure/identity';
2
+ import { Activity } from 'botbuilder-core';
3
+ import { Activity as Activity_2 } from 'botbuilder';
4
+ import { Attachment } from 'botbuilder';
2
5
  import { AuthenticationProvider } from '@microsoft/microsoft-graph-client';
6
+ import { BotFrameworkAdapter } from 'botbuilder';
7
+ import { CardAction } from 'botbuilder';
8
+ import { CardImage } from 'botbuilder';
9
+ import { ChannelInfo } from 'botbuilder';
3
10
  import { Client } from '@microsoft/microsoft-graph-client';
4
11
  import { ConnectionConfig } from 'tedious';
12
+ import { ConversationReference } from 'botbuilder';
5
13
  import { Dialog } from 'botbuilder-dialogs';
6
14
  import { DialogContext } from 'botbuilder-dialogs';
7
15
  import { DialogTurnResult } from 'botbuilder-dialogs';
8
16
  import { GetTokenOptions } from '@azure/identity';
17
+ import { HeroCard } from 'botbuilder';
18
+ import { O365ConnectorCard } from 'botbuilder';
19
+ import { ReceiptCard } from 'botbuilder';
20
+ import { TeamsChannelAccount } from 'botbuilder';
21
+ import { ThumbnailCard } from 'botbuilder';
9
22
  import { TokenCredential } from '@azure/identity';
10
23
  import { TokenResponse } from 'botframework-schema';
24
+ import { TurnContext } from 'botbuilder-core';
11
25
 
12
26
  /**
13
27
  * Represent Microsoft 365 tenant identity, and it is usually used when user is not involved like time-triggered automation job.
@@ -123,6 +137,162 @@ export declare interface AuthenticationConfiguration {
123
137
  readonly applicationIdUri?: string;
124
138
  }
125
139
 
140
+ /**
141
+ * A {@link NotificationTarget} that represents a team channel.
142
+ *
143
+ * @remarks
144
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
145
+ *
146
+ * @beta
147
+ */
148
+ export declare class Channel implements NotificationTarget {
149
+ /**
150
+ * The parent {@link TeamsBotInstallation} where this channel is created from.
151
+ *
152
+ * @beta
153
+ */
154
+ readonly parent: TeamsBotInstallation;
155
+ /**
156
+ * Detailed channel information.
157
+ *
158
+ * @beta
159
+ */
160
+ readonly info: ChannelInfo;
161
+ /**
162
+ * Notification target type. For channel it's always "Channel".
163
+ *
164
+ * @beta
165
+ */
166
+ readonly type: NotificationTargetType;
167
+ /**
168
+ * Constuctor.
169
+ *
170
+ * @remarks
171
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
172
+ *
173
+ * @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
174
+ * @param info - Detailed channel information.
175
+ *
176
+ * @beta
177
+ */
178
+ constructor(parent: TeamsBotInstallation, info: ChannelInfo);
179
+ /**
180
+ * Send a plain text message.
181
+ *
182
+ * @param text - the plain text message.
183
+ * @returns A `Promise` representing the asynchronous operation.
184
+ *
185
+ * @beta
186
+ */
187
+ sendMessage(text: string): Promise<void>;
188
+ /**
189
+ * Send an adaptive card message.
190
+ *
191
+ * @param card - the adaptive card raw JSON.
192
+ * @returns A `Promise` representing the asynchronous operation.
193
+ *
194
+ * @beta
195
+ */
196
+ sendAdaptiveCard(card: unknown): Promise<void>;
197
+ /**
198
+ * @internal
199
+ */
200
+ private newConversation;
201
+ }
202
+
203
+ /**
204
+ * Provide static utilities for bot conversation, including
205
+ * - send notification to varies targets (e.g., member, channel, incoming wehbook)
206
+ * - handle command and response.
207
+ *
208
+ * @example
209
+ * Here's an example on how to send notification via Teams Bot.
210
+ * ```typescript
211
+ * // initialize (it's recommended to be called before handling any bot message)
212
+ * ConversationBot.initialize(adapter, {
213
+ * enableNotification: true
214
+ * });
215
+ *
216
+ * // get all bot installations and send message
217
+ * for (const target of await ConversationBot.installations()) {
218
+ * await target.sendMessage("Hello Notification");
219
+ * }
220
+ *
221
+ * // alternative - send message to all members
222
+ * for (const target of await ConversationBot.installations()) {
223
+ * for (const member of await target.members()) {
224
+ * await member.sendMessage("Hello Notification");
225
+ * }
226
+ * }
227
+ * ```
228
+ *
229
+ * @beta
230
+ */
231
+ export declare class ConversationBot {
232
+ private static conversationReferenceStore;
233
+ private static adapter;
234
+ /**
235
+ * Initialize bot notification.
236
+ *
237
+ * @remarks
238
+ * To ensure accuracy, it's recommended to initialize before handling any message.
239
+ *
240
+ * @param adapter - the bound `BotFrameworkAdapter`
241
+ * @param options - initialize options
242
+ *
243
+ * @beta
244
+ */
245
+ static initialize(adapter: BotFrameworkAdapter, options?: ConversationOptions): void;
246
+ /**
247
+ * Get all targets where the bot is installed.
248
+ *
249
+ * @remarks
250
+ * The result is retrieving from the persisted storage.
251
+ *
252
+ * @returns - an array of {@link TeamsBotInstallation}.
253
+ *
254
+ * @beta
255
+ */
256
+ static installations(): Promise<TeamsBotInstallation[]>;
257
+ }
258
+
259
+ /**
260
+ * Options to initialize {@link ConversationBot}.
261
+ *
262
+ * @beta
263
+ */
264
+ export declare interface ConversationOptions {
265
+ /**
266
+ * A boolean, controlling whether to include the notification feature.
267
+ * @defaultValue false
268
+ * (default: `false`).
269
+ */
270
+ enableNotification?: boolean;
271
+ /**
272
+ * An optional storage to persist bot notification connections.
273
+ *
274
+ * @remarks
275
+ * If `storage` is not provided, a default local file storage will be used,
276
+ * which stores notification connections into:
277
+ * - ".notification.localstore.json" if running locally
278
+ * - "${process.env.TEMP}/.notification.localstore.json" if `process.env.RUNNING_ON_AZURE` is set to "1"
279
+ *
280
+ * It's recommended to use your own shared storage for production environment.
281
+ *
282
+ * @beta
283
+ */
284
+ storage?: NotificationTargetStorage;
285
+ /**
286
+ * The command handlers to register with the underlying conversation bot that
287
+ * can process a command and return a response.
288
+ *
289
+ * @remarks
290
+ * If provided, the corresponding handler will be invoked if the bot received a message
291
+ * that matches the command pattern (`string` or `RegExp`) defined in the handler.
292
+ */
293
+ commandHandlers?: TeamsFxBotCommandHandler[];
294
+ }
295
+
126
296
  /**
127
297
  * Get Microsoft graph client.
128
298
  *
@@ -353,6 +523,198 @@ export declare enum LogLevel {
353
523
  Error = 3
354
524
  }
355
525
 
526
+ /**
527
+ * A {@link NotificationTarget} that represents a team member.
528
+ *
529
+ * @remarks
530
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}.
531
+ *
532
+ * @beta
533
+ */
534
+ export declare class Member implements NotificationTarget {
535
+ /**
536
+ * The parent {@link TeamsBotInstallation} where this member is created from.
537
+ *
538
+ * @beta
539
+ */
540
+ readonly parent: TeamsBotInstallation;
541
+ /**
542
+ * Detailed member account information.
543
+ *
544
+ * @beta
545
+ */
546
+ readonly account: TeamsChannelAccount;
547
+ /**
548
+ * Notification target type. For member it's always "Person".
549
+ *
550
+ * @beta
551
+ */
552
+ readonly type: NotificationTargetType;
553
+ /**
554
+ * Constuctor.
555
+ *
556
+ * @remarks
557
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
558
+ *
559
+ * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
560
+ * @param account - Detailed member account information.
561
+ *
562
+ * @beta
563
+ */
564
+ constructor(parent: TeamsBotInstallation, account: TeamsChannelAccount);
565
+ /**
566
+ * Send a plain text message.
567
+ *
568
+ * @param text - the plain text message.
569
+ * @returns A `Promise` representing the asynchronous operation.
570
+ *
571
+ * @beta
572
+ */
573
+ sendMessage(text: string): Promise<void>;
574
+ /**
575
+ * Send an adaptive card message.
576
+ *
577
+ * @param card - the adaptive card raw JSON.
578
+ * @returns A `Promise` representing the asynchronous operation.
579
+ *
580
+ * @beta
581
+ */
582
+ sendAdaptiveCard(card: unknown): Promise<void>;
583
+ /**
584
+ * @internal
585
+ */
586
+ private newConversation;
587
+ }
588
+
589
+ /**
590
+ * Provides utility method to build bot message with cards that supported in Teams.
591
+ */
592
+ export declare class MessageBuilder {
593
+ /**
594
+ * Build a bot message activity attached with adaptive card.
595
+ *
596
+ * @param getCardData Function to prepare your card data.
597
+ * @param cardTemplate The adaptive card template.
598
+ * @returns A bot message activity attached with an adaptive card.
599
+ *
600
+ * @example
601
+ * ```javascript
602
+ * const cardTemplate = {
603
+ * type: "AdaptiveCard",
604
+ * body: [
605
+ * {
606
+ * "type": "TextBlock",
607
+ * "text": "${title}",
608
+ * "size": "Large"
609
+ * },
610
+ * {
611
+ * "type": "TextBlock",
612
+ * "text": "${description}"
613
+ * }],
614
+ * $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
615
+ * version: "1.4"
616
+ * };
617
+ *
618
+ * type CardData = {
619
+ * title: string,
620
+ * description: string
621
+ * };
622
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(() => {
623
+ * return {
624
+ * title: "sample card title",
625
+ * description: "sample card description"
626
+ * }}, cardTemplate);
627
+ * ```
628
+ *
629
+ * @beta
630
+ */
631
+ static attachAdaptiveCard<TData>(getCardData: () => TData, cardTemplate: any): Partial<Activity_2>;
632
+ /**
633
+ * Build a bot message activity attached with an adaptive card.
634
+ *
635
+ * @param card The adaptive card content.
636
+ * @returns A bot message activity attached with an adaptive card.
637
+ *
638
+ * @beta
639
+ */
640
+ static attachAdaptiveCardWithoutData(card: any): Partial<Activity_2>;
641
+ /**
642
+ * Build a bot message activity attached with an hero card.
643
+ *
644
+ * @param title The card title.
645
+ * @param images Optional. The array of images to include on the card.
646
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
647
+ * is converted to an `imBack` button with a title and value set to the value of the string.
648
+ * @param other Optional. Any additional properties to include on the card.
649
+ *
650
+ * @returns A bot message activity attached with a hero card.
651
+ *
652
+ * @example
653
+ * ```javascript
654
+ * const message = MessageBuilder.attachHeroCard(
655
+ * 'sample title',
656
+ * ['https://example.com/sample.jpg'],
657
+ * ['action']
658
+ * );
659
+ * ```
660
+ *
661
+ * @beta
662
+ */
663
+ static attachHeroCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<HeroCard>): Partial<Activity_2>;
664
+ /**
665
+ * Returns an attachment for a sign-in card.
666
+ *
667
+ * @param title The title for the card's sign-in button.
668
+ * @param url The URL of the sign-in page to use.
669
+ * @param text Optional. Additional text to include on the card.
670
+ *
671
+ * @returns A bot message activity attached with a sign-in card.
672
+ *
673
+ * @remarks
674
+ * For channels that don't natively support sign-in cards, an alternative message is rendered.
675
+ *
676
+ * @beta
677
+ */
678
+ static attachSigninCard(title: string, url: string, text?: string): Partial<Activity_2>;
679
+ /**
680
+ * Build a bot message activity attached with an Office 365 connector card.
681
+ *
682
+ * @param card A description of the Office 365 connector card.
683
+ * @returns A bot message activity attached with an Office 365 connector card.
684
+ *
685
+ * @beta
686
+ */
687
+ static attachO365ConnectorCard(card: O365ConnectorCard): Partial<Activity_2>;
688
+ /**
689
+ * Build a message activity attached with a receipt card.
690
+ * @param card A description of the receipt card.
691
+ * @returns A message activity attached with a receipt card.
692
+ *
693
+ * @beta
694
+ */
695
+ static AttachReceiptCard(card: ReceiptCard): Partial<Activity_2>;
696
+ /**
697
+ *
698
+ * @param title The card title.
699
+ * @param images Optional. The array of images to include on the card.
700
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
701
+ * is converted to an `imBack` button with a title and value set to the value of the string.
702
+ * @param other Optional. Any additional properties to include on the card.
703
+ * @returns A message activity attached with a thumbnail card
704
+ *
705
+ * @beta
706
+ */
707
+ static attachThumbnailCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<ThumbnailCard>): Partial<Activity_2>;
708
+ /**
709
+ * Add an attachement to a bot activity.
710
+ * @param attachement The attachment object to attach.
711
+ * @returns A message activity with an attachment.
712
+ *
713
+ * @beta
714
+ */
715
+ static attachContent(attachement: Attachment): Partial<Activity_2>;
716
+ }
717
+
356
718
  /**
357
719
  * Microsoft Graph auth provider for Teams Framework
358
720
  *
@@ -389,6 +751,97 @@ export declare class MsGraphAuthProvider implements AuthenticationProvider {
389
751
  getAccessToken(): Promise<string>;
390
752
  }
391
753
 
754
+ /**
755
+ * Represent a notification target.
756
+ *
757
+ * @beta
758
+ */
759
+ export declare interface NotificationTarget {
760
+ /**
761
+ * The type of target, could be "Channel" or "Group" or "Person".
762
+ *
763
+ * @beta
764
+ */
765
+ readonly type?: NotificationTargetType;
766
+ /**
767
+ * Send a plain text message.
768
+ *
769
+ * @param text - the plain text message.
770
+ *
771
+ * @beta
772
+ */
773
+ sendMessage(text: string): Promise<void>;
774
+ /**
775
+ * Send an adaptive card message.
776
+ *
777
+ * @param card - the adaptive card raw JSON.
778
+ *
779
+ * @beta
780
+ */
781
+ sendAdaptiveCard(card: unknown): Promise<void>;
782
+ }
783
+
784
+ /**
785
+ * Interface for a storage provider that stores and retrieves notification target references.
786
+ *
787
+ * @beta
788
+ */
789
+ declare interface NotificationTargetStorage {
790
+ /**
791
+ * Read one notification target by its key.
792
+ *
793
+ * @param key - the key of a notification target.
794
+ *
795
+ * @returns - the notification target. Or undefined if not found.
796
+ *
797
+ * @beta
798
+ */
799
+ read(key: string): Promise<{
800
+ [key: string]: unknown;
801
+ } | undefined>;
802
+ /**
803
+ * List all stored notification targets.
804
+ *
805
+ * @returns - an array of notification target. Or an empty array if nothing is stored.
806
+ *
807
+ * @beta
808
+ */
809
+ list(): Promise<{
810
+ [key: string]: unknown;
811
+ }[]>;
812
+ /**
813
+ * Write one notification target by its key.
814
+ *
815
+ * @param key - the key of a notification target.
816
+ * @param object - the notification target.
817
+ *
818
+ * @beta
819
+ */
820
+ write(key: string, object: {
821
+ [key: string]: unknown;
822
+ }): Promise<void>;
823
+ /**
824
+ * Delete one notificaton target by its key.
825
+ *
826
+ * @param key - the key of a notification target.
827
+ *
828
+ * @beta
829
+ */
830
+ delete(key: string): Promise<void>;
831
+ }
832
+
833
+ /**
834
+ * The target type where the notification will be sent to.
835
+ *
836
+ * @remarks
837
+ * - "Channel" means to a team channel. (By default, notification to a team will be sent to its "General" channel.)
838
+ * - "Group" means to a group chat.
839
+ * - "Person" means to a personal chat.
840
+ *
841
+ * @beta
842
+ */
843
+ export declare type NotificationTargetType = "Channel" | "Group" | "Person";
844
+
392
845
  /**
393
846
  * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
394
847
  *
@@ -476,6 +929,28 @@ export declare class OnBehalfOfUserCredential implements TokenCredential {
476
929
  private generateAuthServerError;
477
930
  }
478
931
 
932
+ /**
933
+ * Send an adaptive card message to a notification target.
934
+ *
935
+ * @param target - the notification target.
936
+ * @param card - the adaptive card raw JSON.
937
+ * @returns A `Promise` representing the asynchronous operation.
938
+ *
939
+ * @beta
940
+ */
941
+ export declare function sendAdaptiveCard(target: NotificationTarget, card: unknown): Promise<void>;
942
+
943
+ /**
944
+ * Send a plain text message to a notification target.
945
+ *
946
+ * @param target - the notification target.
947
+ * @param text - the plain text message.
948
+ * @returns A `Promise` representing the asynchronous operation.
949
+ *
950
+ * @beta
951
+ */
952
+ export declare function sendMessage(target: NotificationTarget, text: string): Promise<void>;
953
+
479
954
  /**
480
955
  * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
481
956
  *
@@ -522,6 +997,89 @@ export declare function setLogger(logger?: Logger): void;
522
997
  */
523
998
  export declare function setLogLevel(level: LogLevel): void;
524
999
 
1000
+ /**
1001
+ * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1002
+ * - Personal chat
1003
+ * - Group chat
1004
+ * - Team (by default the `General` channel)
1005
+ *
1006
+ * @remarks
1007
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1008
+ *
1009
+ * @beta
1010
+ */
1011
+ export declare class TeamsBotInstallation implements NotificationTarget {
1012
+ /**
1013
+ * The bound `BotFrameworkAdapter`.
1014
+ *
1015
+ * @beta
1016
+ */
1017
+ readonly adapter: BotFrameworkAdapter;
1018
+ /**
1019
+ * The bound `ConversationReference`.
1020
+ *
1021
+ * @beta
1022
+ */
1023
+ readonly conversationReference: Partial<ConversationReference>;
1024
+ /**
1025
+ * Notification target type.
1026
+ *
1027
+ * @remarks
1028
+ * - "Channel" means bot is installed into a team and notification will be sent to its "General" channel.
1029
+ * - "Group" means bot is installed into a group chat.
1030
+ * - "Person" means bot is installed into a personal scope and notification will be sent to personal chat.
1031
+ *
1032
+ * @beta
1033
+ */
1034
+ readonly type?: NotificationTargetType;
1035
+ /**
1036
+ * Constructor
1037
+ *
1038
+ * @remarks
1039
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1040
+ *
1041
+ * @param adapter - the bound `BotFrameworkAdapter`.
1042
+ * @param conversationReference - the bound `ConversationReference`.
1043
+ *
1044
+ * @beta
1045
+ */
1046
+ constructor(adapter: BotFrameworkAdapter, conversationReference: Partial<ConversationReference>);
1047
+ /**
1048
+ * Send a plain text message.
1049
+ *
1050
+ * @param text - the plain text message.
1051
+ * @returns A `Promise` representing the asynchronous operation.
1052
+ *
1053
+ * @beta
1054
+ */
1055
+ sendMessage(text: string): Promise<void>;
1056
+ /**
1057
+ * Send an adaptive card message.
1058
+ *
1059
+ * @param card - the adaptive card raw JSON.
1060
+ * @returns A `Promise` representing the asynchronous operation.
1061
+ *
1062
+ * @beta
1063
+ */
1064
+ sendAdaptiveCard(card: unknown): Promise<void>;
1065
+ /**
1066
+ * Get channels from this bot installation.
1067
+ *
1068
+ * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1069
+ *
1070
+ * @beta
1071
+ */
1072
+ channels(): Promise<Channel[]>;
1073
+ /**
1074
+ * Get members from this bot installation.
1075
+ *
1076
+ * @returns an array of members from where the bot is installed.
1077
+ *
1078
+ * @beta
1079
+ */
1080
+ members(): Promise<Member[]>;
1081
+ }
1082
+
525
1083
  /**
526
1084
  * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
527
1085
  * help receive oauth token, asks the user to consent if needed.
@@ -809,6 +1367,26 @@ export declare class TeamsFx implements TeamsFxConfiguration {
809
1367
  private loadFromEnv;
810
1368
  }
811
1369
 
1370
+ /**
1371
+ * Interface for a command handler that can process command to a TeamsFx bot and return a response.
1372
+ *
1373
+ * @beta
1374
+ */
1375
+ export declare interface TeamsFxBotCommandHandler {
1376
+ /**
1377
+ * The command name or RegExp pattern that can trigger this handler.
1378
+ */
1379
+ commandNameOrPattern: string | RegExp;
1380
+ /**
1381
+ * Handles a bot command received activity.
1382
+ *
1383
+ * @param context The bot context.
1384
+ * @param receivedText The command text the user types from Teams.
1385
+ * @returns A `Promise` representing an activity or text to send as the command response.
1386
+ */
1387
+ handleCommandReceived(context: TurnContext, receivedText: string): Promise<string | Partial<Activity>>;
1388
+ }
1389
+
812
1390
  /**
813
1391
  * TeamsFx interface that provides credential and configuration.
814
1392
  * @beta