@microsoft/teamsfx 2.0.0-experimental.0 → 2.0.0-rc.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,8 +1,7 @@
1
1
  /// <reference types="node" />
2
2
 
3
3
  import { AccessToken } from '@azure/identity';
4
- import { Activity } from 'botbuilder-core';
5
- import { Activity as Activity_2 } from 'botbuilder';
4
+ import { Activity } from 'botbuilder';
6
5
  import { Attachment } from 'botbuilder';
7
6
  import { AuthenticationProvider } from '@microsoft/microsoft-graph-client';
8
7
  import { AxiosInstance } from 'axios';
@@ -12,29 +11,54 @@ import { CardAction } from 'botbuilder';
12
11
  import { CardImage } from 'botbuilder';
13
12
  import { ChannelInfo } from 'botbuilder';
14
13
  import { Client } from '@microsoft/microsoft-graph-client';
14
+ import { ComponentDialog } from 'botbuilder-dialogs';
15
15
  import { ConnectionConfig } from 'tedious';
16
16
  import { ConversationReference } from 'botbuilder';
17
+ import { ConversationState } from 'botbuilder';
17
18
  import { Dialog } from 'botbuilder-dialogs';
18
19
  import { DialogContext } from 'botbuilder-dialogs';
19
20
  import { DialogTurnResult } from 'botbuilder-dialogs';
20
21
  import { GetTokenOptions } from '@azure/identity';
21
22
  import { HeroCard } from 'botbuilder';
23
+ import { InvokeResponse } from 'botbuilder';
24
+ import { MessagingExtensionResponse } from 'botbuilder';
22
25
  import { O365ConnectorCard } from 'botbuilder';
23
26
  import { ReceiptCard } from 'botbuilder';
24
27
  import { SecureContextOptions } from 'tls';
28
+ import { SigninStateVerificationQuery } from 'botbuilder';
29
+ import { StatePropertyAccessor } from 'botbuilder';
30
+ import { StatusCodes } from 'botbuilder';
31
+ import { Storage as Storage_2 } from 'botbuilder';
32
+ import { TeamDetails } from 'botbuilder';
25
33
  import { TeamsChannelAccount } from 'botbuilder';
26
34
  import { ThumbnailCard } from 'botbuilder';
27
35
  import { TokenCredential } from '@azure/identity';
28
36
  import { TokenResponse } from 'botframework-schema';
29
- import { TurnContext } from 'botbuilder-core';
30
- import { TurnContext as TurnContext_2 } from 'botbuilder';
37
+ import { TurnContext } from 'botbuilder';
38
+ import { UserState } from 'botbuilder';
31
39
  import { WebRequest } from 'botbuilder';
32
40
  import { WebResponse } from 'botbuilder';
33
41
 
42
+ /**
43
+ * Options used to control how the response card will be sent to users.
44
+ */
45
+ export declare enum AdaptiveCardResponse {
46
+ /**
47
+ * The response card will be replaced the current one for the interactor who trigger the action.
48
+ */
49
+ ReplaceForInteractor = 0,
50
+ /**
51
+ * The response card will be replaced the current one for all users in the chat.
52
+ */
53
+ ReplaceForAll = 1,
54
+ /**
55
+ * The response card will be sent as a new message for all users in the chat.
56
+ */
57
+ NewForAll = 2
58
+ }
59
+
34
60
  /**
35
61
  * Define available location for API Key location
36
- *
37
- * @beta
38
62
  */
39
63
  export declare enum ApiKeyLocation {
40
64
  /**
@@ -49,8 +73,6 @@ export declare enum ApiKeyLocation {
49
73
 
50
74
  /**
51
75
  * Provider that handles API Key authentication
52
- *
53
- * @beta
54
76
  */
55
77
  export declare class ApiKeyProvider implements AuthProvider {
56
78
  private keyName;
@@ -64,8 +86,6 @@ export declare class ApiKeyProvider implements AuthProvider {
64
86
  *
65
87
  * @throws {@link ErrorCode|InvalidParameter} - when key name or key value is empty.
66
88
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
67
- *
68
- * @beta
69
89
  */
70
90
  constructor(keyName: string, keyValue: string, keyLocation: ApiKeyLocation);
71
91
  /**
@@ -78,8 +98,6 @@ export declare class ApiKeyProvider implements AuthProvider {
78
98
  *
79
99
  * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when API key already exists in request header or url query parameter.
80
100
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
81
- *
82
- * @beta
83
101
  */
84
102
  AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
85
103
  }
@@ -95,8 +113,6 @@ export declare class ApiKeyProvider implements AuthProvider {
95
113
  *
96
114
  * @remarks
97
115
  * Only works in in server side.
98
- *
99
- * @beta
100
116
  */
101
117
  export declare class AppCredential implements TokenCredential {
102
118
  private readonly msalClient;
@@ -106,12 +122,22 @@ export declare class AppCredential implements TokenCredential {
106
122
  * @remarks
107
123
  * Only works in in server side.
108
124
  *
109
- * @param {AuthenticationConfiguration} authConfig - The authentication configuration. Use environment variables if not provided.
125
+ * @param {AppCredentialAuthConfig} authConfig - The authentication configuration.
110
126
  *
111
127
  * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret or tenant id is not found in config.
112
128
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
129
+ */
130
+ constructor(authConfig: AppCredentialAuthConfig);
131
+ /**
132
+ * Constructor of AppCredential.
133
+ *
134
+ * @remarks
135
+ * Only works in in server side.
136
+ *
137
+ * @param {AuthenticationConfiguration} authConfig - The authentication configuration. Use environment variables if not provided.
113
138
  *
114
- * @beta
139
+ * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret or tenant id is not found in config.
140
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
115
141
  */
116
142
  constructor(authConfig: AuthenticationConfiguration);
117
143
  /**
@@ -137,8 +163,6 @@ export declare class AppCredential implements TokenCredential {
137
163
  *
138
164
  * @returns Access token with expected scopes.
139
165
  * Throw error if get access token failed.
140
- *
141
- * @beta
142
166
  */
143
167
  getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
144
168
  /**
@@ -151,9 +175,13 @@ export declare class AppCredential implements TokenCredential {
151
175
  private loadAndValidateConfig;
152
176
  }
153
177
 
178
+ /**
179
+ * Authentication configuration for AppCredential used in node environment
180
+ */
181
+ export declare type AppCredentialAuthConfig = OnBehalfOfCredentialAuthConfig;
182
+
154
183
  /**
155
184
  * Authentication related configuration.
156
- * @beta
157
185
  */
158
186
  export declare interface AuthenticationConfiguration {
159
187
  /**
@@ -200,8 +228,6 @@ export declare interface AuthenticationConfiguration {
200
228
 
201
229
  /**
202
230
  * Defines method that injects authentication info to http requests
203
- *
204
- * @beta
205
231
  */
206
232
  export declare interface AuthProvider {
207
233
  /**
@@ -209,8 +235,6 @@ export declare interface AuthProvider {
209
235
  *
210
236
  * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
211
237
  * Refer https://axios-http.com/docs/req_config for detailed document.
212
- *
213
- * @beta
214
238
  */
215
239
  AddAuthenticationInfo: (config: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
216
240
  }
@@ -219,8 +243,6 @@ export { AxiosInstance }
219
243
 
220
244
  /**
221
245
  * Provider that handles Basic authentication
222
- *
223
- * @beta
224
246
  */
225
247
  export declare class BasicAuthProvider implements AuthProvider {
226
248
  private userName;
@@ -232,8 +254,6 @@ export declare class BasicAuthProvider implements AuthProvider {
232
254
  *
233
255
  * @throws {@link ErrorCode|InvalidParameter} - when username or password is empty.
234
256
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
235
- *
236
- * @beta
237
257
  */
238
258
  constructor(userName: string, password: string);
239
259
  /**
@@ -246,23 +266,17 @@ export declare class BasicAuthProvider implements AuthProvider {
246
266
  *
247
267
  * @throws {@link ErrorCode|AuthorizationInfoAlreadyExists} - when Authorization header or auth property already exists in request configuration.
248
268
  * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
249
- *
250
- * @beta
251
269
  */
252
270
  AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
253
271
  }
254
272
 
255
273
  /**
256
274
  * Provider that handles Bearer Token authentication
257
- *
258
- * @beta
259
275
  */
260
276
  export declare class BearerTokenAuthProvider implements AuthProvider {
261
277
  private getToken;
262
278
  /**
263
279
  * @param { () => Promise<string> } getToken - Function that returns the content of bearer token used in http request
264
- *
265
- * @beta
266
280
  */
267
281
  constructor(getToken: () => Promise<string>);
268
282
  /**
@@ -274,1690 +288,2225 @@ export declare class BearerTokenAuthProvider implements AuthProvider {
274
288
  * @returns Updated axios request config.
275
289
  *
276
290
  * @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
291
  */
311
292
  AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
312
293
  }
313
294
 
314
295
  /**
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
296
+ * Interface for SSO configuration for Bot SSO
321
297
  */
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;
298
+ export declare interface BotSsoConfig {
329
299
  /**
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
- * Constructor.
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
300
+ * aad related configurations
373
301
  */
374
- private newConversation;
302
+ aad: {
303
+ /**
304
+ * The list of scopes for which the token will have access
305
+ */
306
+ scopes: string[];
307
+ } & ((OnBehalfOfCredentialAuthConfig & {
308
+ initiateLoginEndpoint: string;
309
+ }) | AuthenticationConfiguration);
310
+ dialog?: {
311
+ /**
312
+ * Custom sso execution activity handler class which should implement the interface {@link BotSsoExecutionActivityHandler}. If not provided, it will use {@link DefaultBotSsoExecutionActivityHandler} by default
313
+ */
314
+ CustomBotSsoExecutionActivityHandler?: new (ssoConfig: BotSsoConfig) => BotSsoExecutionActivityHandler;
315
+ /**
316
+ * Conversation state for sso command bot, if not provided, it will use internal memory storage to create a new one.
317
+ */
318
+ conversationState?: ConversationState;
319
+ /**
320
+ * User state for sso command bot, if not provided, it will use internal memory storage to create a new one.
321
+ */
322
+ userState?: UserState;
323
+ /**
324
+ * Used by {@link BotSsoExecutionDialog} to remove duplicated messages, if not provided, it will use internal memory storage
325
+ */
326
+ dedupStorage?: Storage_2;
327
+ /**
328
+ * Settings used to configure an teams sso prompt dialog.
329
+ */
330
+ ssoPromptConfig?: {
331
+ /**
332
+ * Number of milliseconds the prompt will wait for the user to authenticate.
333
+ * Defaults to a value `900,000` (15 minutes.)
334
+ */
335
+ timeout?: number;
336
+ /**
337
+ * Value indicating whether the TeamsBotSsoPrompt should end upon receiving an
338
+ * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
339
+ * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
340
+ * Defaults to value `true`
341
+ */
342
+ endOnInvalidMessage?: boolean;
343
+ };
344
+ };
375
345
  }
376
346
 
377
347
  /**
378
- * A command bot for receiving commands and sending responses in Teams.
348
+ * Interface for user to customize SSO execution activity handler
379
349
  *
380
350
  * @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 message 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.
351
+ * Bot SSO execution activity handler is to handle SSO login process and trigger SSO command using {@link BotSsoExecutionDialog}.
352
+ * You can use this interface to implement your own SSO execution dialog, and pass it to ConversationBot options:
465
353
  *
466
354
  * ```typescript
467
- * // enable through constructor
468
- * const conversationBot = new ConversationBot({
469
- * notification: {
470
- * enabled: true,
355
+ * export const commandBot = new ConversationBot({
356
+ * ...
357
+ * ssoConfig: {
358
+ * ...
359
+ * dialog: {
360
+ * CustomBotSsoExecutionActivityHandler: YourCustomBotSsoExecutionActivityHandler,
361
+ * }
471
362
  * },
363
+ * ...
472
364
  * });
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
365
  * ```
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
366
+ * For details information about how to implement a BotSsoExecutionActivityHandler, please refer DefaultBotSsoExecutionActivityHandler class source code: https://aka.ms/teamsfx-default-sso-execution-activity-handler
495
367
  */
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;
368
+ export declare interface BotSsoExecutionActivityHandler {
509
369
  /**
510
- * The entrypoint of notification.
511
- *
512
- * @beta
513
- */
514
- readonly notification?: NotificationBot;
515
- /**
516
- * Creates new instance of the `ConversationBot`.
370
+ * Add {@link TeamsFxBotSsoCommandHandler} instance to {@link BotSsoExecutionDialog}
371
+ * @param handler {@link BotSsoExecutionDialogHandler} callback function
372
+ * @param triggerPatterns The trigger pattern
517
373
  *
518
374
  * @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
375
+ * This function is used to add SSO command to {@link BotSsoExecutionDialog} instance.
549
376
  */
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 {
377
+ addCommand(handler: BotSsoExecutionDialogHandler, triggerPatterns: TriggerPatterns): void;
559
378
  /**
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
379
+ * Called to initiate the event emission process.
380
+ * @param context The context object for the current turn.
568
381
  */
569
- adapter?: BotFrameworkAdapter;
382
+ run(context: TurnContext): Promise<void>;
570
383
  /**
571
- * If `adapter` is not provided, this `adapterConfig` will be passed to the new `BotFrameworkAdapter` when created internally.
384
+ * Receives invoke activities with Activity name of 'signin/verifyState'.
385
+ * @param context A context object for this turn.
386
+ * @param query Signin state (part of signin action auth flow) verification invoke query.
387
+ * @returns A promise that represents the work queued.
572
388
  *
573
389
  * @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
390
+ * It should trigger {@link BotSsoExecutionDialog} instance to handle signin process
585
391
  */
586
- command?: CommandOptions & {
587
- /**
588
- * Whether to enable command or not.
589
- *
590
- * @beta
591
- */
592
- enabled?: boolean;
593
- };
392
+ handleTeamsSigninVerifyState(context: TurnContext, query: SigninStateVerificationQuery): Promise<void>;
594
393
  /**
595
- * The notification part.
394
+ * Receives invoke activities with Activity name of 'signin/tokenExchange'
395
+ * @param context A context object for this turn.
396
+ * @param query Signin state (part of signin action auth flow) verification invoke query
397
+ * @returns A promise that represents the work queued.
596
398
  *
597
- * @beta
399
+ * @remark
400
+ * It should trigger {@link BotSsoExecutionDialog} instance to handle signin process
598
401
  */
599
- notification?: NotificationOptions_2 & {
600
- /**
601
- * Whether to enable notification or not.
602
- *
603
- * @beta
604
- */
605
- enabled?: boolean;
606
- };
402
+ handleTeamsSigninTokenExchange(context: TurnContext, query: SigninStateVerificationQuery): Promise<void>;
607
403
  }
608
404
 
609
405
  /**
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
406
+ * Sso execution dialog, use to handle sso command
622
407
  */
623
- export declare function createApiClient(apiEndpoint: string, authProvider: AuthProvider): AxiosInstance;
408
+ export declare class BotSsoExecutionDialog extends ComponentDialog {
409
+ private dedupStorage;
410
+ private dedupStorageKeys;
411
+ private commandMapping;
412
+ /**
413
+ * Creates a new instance of the BotSsoExecutionDialog.
414
+ * @param {@link Storage} dedupStorage Helper storage to remove duplicated messages
415
+ * @param {@link TeamsBotSsoPromptSettings} settings The list of scopes for which the token will have access
416
+ * @param {@link TeamsFx} teamsfx instance for authentication
417
+ * @param {string} dialogName custom dialog name
418
+ */
419
+ constructor(dedupStorage: Storage_2, ssoPromptSettings: TeamsBotSsoPromptSettings, teamsfx: TeamsFx, dialogName?: string);
420
+ /**
421
+ * Creates a new instance of the BotSsoExecutionDialog.
422
+ * @param {@link Storage} dedupStorage Helper storage to remove duplicated messages
423
+ * @param {@link TeamsBotSsoPromptSettings} settings The list of scopes for which the token will have access
424
+ * @param {@link OnBehalfOfCredentialAuthConfig} authConfig The authentication configuration.
425
+ * @param {string} initiateLoginEndpoint Login URL for Teams to redirect to.
426
+ * @param {string} dialogName custom dialog name
427
+ */
428
+ constructor(dedupStorage: Storage_2, ssoPromptSettings: TeamsBotSsoPromptSettings, authConfig: OnBehalfOfCredentialAuthConfig, initiateLoginEndpoint: string, dialogName?: string);
429
+ /**
430
+ * Add TeamsFxBotSsoCommandHandler instance
431
+ * @param handler {@link BotSsoExecutionDialogHandler} callback function
432
+ * @param triggerPatterns The trigger pattern
433
+ */
434
+ addCommand(handler: BotSsoExecutionDialogHandler, triggerPatterns: TriggerPatterns): void;
435
+ private getCommandHash;
436
+ /**
437
+ * The run method handles the incoming activity (in the form of a DialogContext) and passes it through the dialog system.
438
+ *
439
+ * @param context The context object for the current turn.
440
+ * @param accessor The instance of StatePropertyAccessor for dialog system.
441
+ */
442
+ run(context: TurnContext, accessor: StatePropertyAccessor): Promise<void>;
443
+ private getActivityText;
444
+ private commandRouteStep;
445
+ private ssoStep;
446
+ private dedupStep;
447
+ /**
448
+ * Called when the component is ending.
449
+ *
450
+ * @param context Context for the current turn of conversation.
451
+ */
452
+ protected onEndDialog(context: TurnContext): Promise<void>;
453
+ /**
454
+ * If a user is signed into multiple Teams clients, the Bot might receive a "signin/tokenExchange" from each client.
455
+ * Each token exchange request for a specific user login will have an identical activity.value.Id.
456
+ * Only one of these token exchange requests should be processed by the bot. For a distributed bot in production,
457
+ * this requires a distributed storage to ensure only one token exchange is processed.
458
+ * @param context Context for the current turn of conversation.
459
+ * @returns boolean value indicate whether the message should be removed
460
+ */
461
+ private shouldDedup;
462
+ private getStorageKey;
463
+ private matchPattern;
464
+ private isPatternMatched;
465
+ private getMatchesCommandId;
466
+ /**
467
+ * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
468
+ * @param dc dialog context
469
+ * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
470
+ * @internal
471
+ */
472
+ private ensureMsTeamsChannel;
473
+ }
624
474
 
625
- /**
626
- * Get Microsoft graph client.
627
- *
628
- * @example
629
- * Get Microsoft graph client by TokenCredential
630
- * ```typescript
631
- * // Sso token example (Azure Function)
632
- * const ssoToken = "YOUR_TOKEN_STRING";
633
- * const options = {"AAD_APP_ID", "AAD_APP_SECRET"};
634
- * const credential = new OnBehalfOfAADUserCredential(ssoToken, options);
635
- * const graphClient = await createMicrosoftGraphClient(credential);
636
- * const profile = await graphClient.api("/me").get();
637
- *
638
- * // TeamsBotSsoPrompt example (Bot Application)
639
- * const requiredScopes = ["User.Read"];
640
- * const config: Configuration = {
641
- * loginUrl: loginUrl,
642
- * clientId: clientId,
643
- * clientSecret: clientSecret,
644
- * tenantId: tenantId
645
- * };
646
- * const prompt = new TeamsBotSsoPrompt(dialogId, {
647
- * config: config
648
- * scopes: '["User.Read"],
649
- * });
650
- * this.addDialog(prompt);
651
- *
652
- * const oboCredential = new OnBehalfOfAADUserCredential(
653
- * getUserId(dialogContext),
654
- * {
655
- * clientId: "AAD_APP_ID",
656
- * clientSecret: "AAD_APP_SECRET"
657
- * });
658
- * try {
659
- * const graphClient = await createMicrosoftGraphClient(credential);
660
- * const profile = await graphClient.api("/me").get();
661
- * } catch (e) {
662
- * dialogContext.beginDialog(dialogId);
663
- * return Dialog.endOfTurn();
664
- * }
665
- * ```
666
- *
667
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
668
- * @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
669
- *
670
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
671
- *
672
- * @returns Graph client with specified scopes.
673
- *
674
- * @beta
675
- */
676
- export declare function createMicrosoftGraphClient(teamsfx: TeamsFxConfiguration, scopes?: string | string[]): Client;
475
+ export declare type BotSsoExecutionDialogHandler = (context: TurnContext, tokenResponse: TeamsBotSsoPromptTokenResponse, message: CommandMessage) => Promise<void>;
677
476
 
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;
477
+ /**
478
+ * A card action bot to respond to adaptive card universal actions.
479
+ */
480
+ export declare class CardActionBot {
481
+ private readonly adapter;
482
+ private middleware;
483
+ /**
484
+ * Creates a new instance of the `CardActionBot`.
485
+ *
486
+ * @param adapter The bound `BotFrameworkAdapter`.
487
+ * @param options - initialize options
488
+ */
489
+ constructor(adapter: BotFrameworkAdapter, options?: CardActionOptions);
490
+ /**
491
+ * Registers a card action handler to the bot.
492
+ * @param actionHandler A card action handler to be registered.
493
+ */
494
+ registerHandler(actionHandler: TeamsFxAdaptiveCardActionHandler): void;
495
+ /**
496
+ * Registers card action handlers to the bot.
497
+ * @param actionHandlers A set of card action handlers to be registered.
498
+ */
499
+ registerHandlers(actionHandlers: TeamsFxAdaptiveCardActionHandler[]): void;
500
+ }
694
501
 
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;
502
+ /**
503
+ * Options to initialize {@link CardActionBot}.
504
+ */
505
+ export declare interface CardActionOptions {
506
+ /**
507
+ * The action handlers to registered with the action bot. Each command should implement the interface {@link TeamsFxAdaptiveCardActionHandler} so that it can be correctly handled by this bot.
508
+ */
509
+ actions?: TeamsFxAdaptiveCardActionHandler[];
510
+ }
709
511
 
710
- /**
711
- * Error code to trace the error types.
712
- * @beta
713
- */
714
- export declare enum ErrorCode {
715
- /**
716
- * Invalid parameter error.
717
- */
718
- InvalidParameter = "InvalidParameter",
719
- /**
720
- * Invalid configuration error.
721
- */
722
- InvalidConfiguration = "InvalidConfiguration",
723
- /**
724
- * Invalid certificate error.
725
- */
726
- InvalidCertificate = "InvalidCertificate",
727
- /**
728
- * Internal error.
729
- */
730
- InternalError = "InternalError",
731
- /**
732
- * Channel is not supported error.
733
- */
734
- ChannelNotSupported = "ChannelNotSupported",
735
- /**
736
- * Runtime is not supported error.
737
- */
738
- RuntimeNotSupported = "RuntimeNotSupported",
739
- /**
740
- * User failed to finish the AAD consent flow failed.
741
- */
742
- ConsentFailed = "ConsentFailed",
743
- /**
744
- * The user or administrator has not consented to use the application error.
745
- */
746
- UiRequiredError = "UiRequiredError",
747
- /**
748
- * Token is not within its valid time range error.
749
- */
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
- }
512
+ /**
513
+ * Provider that handles Certificate authentication
514
+ */
515
+ export declare class CertificateAuthProvider implements AuthProvider {
516
+ private certOption;
517
+ /**
518
+ *
519
+ * @param { SecureContextOptions } certOption - information about the cert used in http requests
520
+ *
521
+ * @throws {@link ErrorCode|InvalidParameter} - when cert option is empty.
522
+ */
523
+ constructor(certOption: SecureContextOptions);
524
+ /**
525
+ * Adds authentication info to http requests.
526
+ *
527
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
528
+ * Refer https://axios-http.com/docs/req_config for detailed document.
529
+ *
530
+ * @returns Updated axios request config.
531
+ *
532
+ * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
533
+ */
534
+ AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
535
+ }
772
536
 
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
- }
537
+ /**
538
+ * A {@link NotificationTarget} that represents a team channel.
539
+ *
540
+ * @remarks
541
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
542
+ */
543
+ export declare class Channel implements NotificationTarget {
544
+ /**
545
+ * The parent {@link TeamsBotInstallation} where this channel is created from.
546
+ */
547
+ readonly parent: TeamsBotInstallation;
548
+ /**
549
+ * Detailed channel information.
550
+ */
551
+ readonly info: ChannelInfo;
552
+ /**
553
+ * Notification target type. For channel it's always "Channel".
554
+ */
555
+ readonly type: NotificationTargetType;
556
+ /**
557
+ * Constructor.
558
+ *
559
+ * @remarks
560
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
561
+ *
562
+ * @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
563
+ * @param info - Detailed channel information.
564
+ */
565
+ constructor(parent: TeamsBotInstallation, info: ChannelInfo);
566
+ /**
567
+ * Send a plain text message.
568
+ *
569
+ * @param text - the plain text message.
570
+ * @param onError - an optional error handler that can catch exceptions during message sending.
571
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
572
+ * @returns the response of sending message.
573
+ */
574
+ sendMessage(text: string, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
575
+ /**
576
+ * Send an adaptive card message.
577
+ *
578
+ * @param card - the adaptive card raw JSON.
579
+ * @param onError - an optional error handler that can catch exceptions during adaptive card sending.
580
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
581
+ * @returns the response of sending adaptive card message.
582
+ */
583
+ sendAdaptiveCard(card: unknown, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
584
+ /**
585
+ * @internal
586
+ */
587
+ private newConversation;
588
+ }
795
589
 
796
- /**
797
- * Get log level.
798
- *
799
- * @returns Log level
800
- *
801
- * @beta
802
- */
803
- export declare function getLogLevel(): LogLevel | undefined;
590
+ /**
591
+ * A command bot for receiving commands and sending responses in Teams.
592
+ *
593
+ * @remarks
594
+ * 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.
595
+ */
596
+ export declare class CommandBot {
597
+ private readonly adapter;
598
+ private readonly middleware;
599
+ private readonly ssoConfig;
600
+ /**
601
+ * Creates a new instance of the `CommandBot`.
602
+ *
603
+ * @param adapter The bound `BotFrameworkAdapter`.
604
+ * @param options - initialize options
605
+ */
606
+ constructor(adapter: BotFrameworkAdapter, options?: CommandOptions, ssoCommandActivityHandler?: BotSsoExecutionActivityHandler, ssoConfig?: BotSsoConfig);
607
+ /**
608
+ * Registers a command into the command bot.
609
+ *
610
+ * @param command The command to register.
611
+ */
612
+ registerCommand(command: TeamsFxBotCommandHandler): void;
613
+ /**
614
+ * Registers commands into the command bot.
615
+ *
616
+ * @param commands The commands to register.
617
+ */
618
+ registerCommands(commands: TeamsFxBotCommandHandler[]): void;
619
+ /**
620
+ * Registers a sso command into the command bot.
621
+ *
622
+ * @param command The command to register.
623
+ */
624
+ registerSsoCommand(ssoCommand: TeamsFxBotSsoCommandHandler): void;
625
+ /**
626
+ * Registers commands into the command bot.
627
+ *
628
+ * @param commands The commands to register.
629
+ */
630
+ registerSsoCommands(ssoCommands: TeamsFxBotSsoCommandHandler[]): void;
631
+ private validateSsoActivityHandler;
632
+ }
804
633
 
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>;
634
+ /**
635
+ * Interface for a command message that can handled in a command handler.
636
+ */
637
+ export declare interface CommandMessage {
638
+ /**
639
+ * Text of the message sent by the user.
640
+ */
641
+ text: string;
642
+ /**
643
+ * The capture groups that matched to the {@link TriggerPatterns} in a {@link TeamsFxBotCommandHandler} instance.
644
+ */
645
+ matches?: RegExpMatchArray;
646
+ }
820
647
 
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
- }
648
+ /**
649
+ * Options to initialize {@link CommandBot}.
650
+ */
651
+ export declare interface CommandOptions {
652
+ /**
653
+ * 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.
654
+ */
655
+ commands?: TeamsFxBotCommandHandler[];
656
+ /**
657
+ * The commands to registered with the sso command bot. Each sso command should implement the interface {@link TeamsFxBotSsoCommandHandler} so that it can be correctly handled by this command bot.
658
+ */
659
+ ssoCommands?: TeamsFxBotSsoCommandHandler[];
660
+ }
836
661
 
837
- /**
838
- * Log function for customized logging.
839
- *
840
- * @beta
841
- */
842
- export declare type LogFunction = (level: LogLevel, message: string) => void;
662
+ /**
663
+ * Provide utilities for bot conversation, including:
664
+ * - handle command and response.
665
+ * - send notification to varies targets (e.g., member, group, channel).
666
+ *
667
+ * @example
668
+ * For command and response, you can register your commands through the constructor, or use the `registerCommand` and `registerCommands` API to add commands later.
669
+ *
670
+ * ```typescript
671
+ * // register through constructor
672
+ * const conversationBot = new ConversationBot({
673
+ * command: {
674
+ * enabled: true,
675
+ * commands: [ new HelloWorldCommandHandler() ],
676
+ * },
677
+ * });
678
+ *
679
+ * // register through `register*` API
680
+ * conversationBot.command.registerCommand(new HelpCommandHandler());
681
+ * ```
682
+ *
683
+ * For notification, you can enable notification at initialization, then send notifications at any time.
684
+ *
685
+ * ```typescript
686
+ * // enable through constructor
687
+ * const conversationBot = new ConversationBot({
688
+ * notification: {
689
+ * enabled: true,
690
+ * },
691
+ * });
692
+ *
693
+ * // get all bot installations and send message
694
+ * for (const target of await conversationBot.notification.installations()) {
695
+ * await target.sendMessage("Hello Notification");
696
+ * }
697
+ *
698
+ * // alternative - send message to all members
699
+ * for (const target of await conversationBot.notification.installations()) {
700
+ * for (const member of await target.members()) {
701
+ * await member.sendMessage("Hello Notification");
702
+ * }
703
+ * }
704
+ * ```
705
+ *
706
+ * @remarks
707
+ * Set `adapter` in {@link ConversationOptions} to use your own bot adapter.
708
+ *
709
+ * 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.
710
+ *
711
+ * For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
712
+ */
713
+ export declare class ConversationBot {
714
+ /**
715
+ * The bot adapter.
716
+ */
717
+ readonly adapter: BotFrameworkAdapter;
718
+ /**
719
+ * The entrypoint of command and response.
720
+ */
721
+ readonly command?: CommandBot;
722
+ /**
723
+ * The entrypoint of notification.
724
+ */
725
+ readonly notification?: NotificationBot;
726
+ /**
727
+ * The action handler used for adaptive card universal actions.
728
+ */
729
+ readonly cardAction?: CardActionBot;
730
+ /**
731
+ * Creates new instance of the `ConversationBot`.
732
+ *
733
+ * @remarks
734
+ * It's recommended to create your own adapter and storage for production environment instead of the default one.
735
+ *
736
+ * @param options - initialize options
737
+ */
738
+ constructor(options: ConversationOptions);
739
+ private createDefaultAdapter;
740
+ /**
741
+ * The request handler to integrate with web request.
742
+ *
743
+ * @param req - an Express or Restify style request object.
744
+ * @param res - an Express or Restify style response object.
745
+ * @param logic - the additional function to handle bot context.
746
+ *
747
+ * @example
748
+ * For example, to use with Restify:
749
+ * ``` typescript
750
+ * // The default/empty behavior
751
+ * server.post("api/messages", conversationBot.requestHandler);
752
+ *
753
+ * // Or, add your own logic
754
+ * server.post("api/messages", async (req, res) => {
755
+ * await conversationBot.requestHandler(req, res, async (context) => {
756
+ * // your-own-context-logic
757
+ * });
758
+ * });
759
+ * ```
760
+ */
761
+ requestHandler(req: WebRequest, res: WebResponse, logic?: (context: TurnContext) => Promise<any>): Promise<void>;
762
+ }
843
763
 
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
- }
764
+ /**
765
+ * Options to initialize {@link ConversationBot}
766
+ */
767
+ export declare interface ConversationOptions {
768
+ /**
769
+ * The bot adapter. If not provided, a default adapter will be created:
770
+ * - with `adapterConfig` as constructor parameter.
771
+ * - with a default error handler that logs error to console, sends trace activity, and sends error message to user.
772
+ *
773
+ * @remarks
774
+ * If neither `adapter` nor `adapterConfig` is provided, will use BOT_ID and BOT_PASSWORD from environment variables.
775
+ */
776
+ adapter?: BotFrameworkAdapter;
777
+ /**
778
+ * If `adapter` is not provided, this `adapterConfig` will be passed to the new `BotFrameworkAdapter` when created internally.
779
+ *
780
+ * @remarks
781
+ * If neither `adapter` nor `adapterConfig` is provided, will use BOT_ID and BOT_PASSWORD from environment variables.
782
+ */
783
+ adapterConfig?: {
784
+ [key: string]: unknown;
785
+ };
786
+ /**
787
+ * Configurations for sso command bot
788
+ */
789
+ ssoConfig?: BotSsoConfig;
790
+ /**
791
+ * The command part.
792
+ */
793
+ command?: CommandOptions & {
794
+ /**
795
+ * Whether to enable command or not.
796
+ */
797
+ enabled?: boolean;
798
+ };
799
+ /**
800
+ * The notification part.
801
+ */
802
+ notification?: NotificationOptions_2 & {
803
+ /**
804
+ * Whether to enable notification or not.
805
+ */
806
+ enabled?: boolean;
807
+ };
808
+ /**
809
+ * The adaptive card action handler part.
810
+ */
811
+ cardAction?: CardActionOptions & {
812
+ /**
813
+ * Whether to enable adaptive card actions or not.
814
+ */
815
+ enabled?: boolean;
816
+ };
817
+ }
866
818
 
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
- }
819
+ /**
820
+ * Initializes new Axios instance with specific auth provider
821
+ *
822
+ * @param apiEndpoint - Base url of the API
823
+ * @param authProvider - Auth provider that injects authentication info to each request
824
+ * @returns axios instance configured with specfic auth provider
825
+ *
826
+ * @example
827
+ * ```typescript
828
+ * const client = createApiClient("https://my-api-endpoint-base-url", new BasicAuthProvider("xxx","xxx"));
829
+ * ```
830
+ */
831
+ export declare function createApiClient(apiEndpoint: string, authProvider: AuthProvider): AxiosInstance;
890
832
 
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
- * Constructor.
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
- }
833
+ /**
834
+ * Get Microsoft graph client.
835
+ * @example
836
+ * Get Microsoft graph client by TokenCredential
837
+ * ```typescript
838
+ * // Sso token example (Azure Function)
839
+ * const ssoToken = "YOUR_TOKEN_STRING";
840
+ * const options = {"AAD_APP_ID", "AAD_APP_SECRET"};
841
+ * const credential = new OnBehalfOfAADUserCredential(ssoToken, options);
842
+ * const graphClient = await createMicrosoftGraphClient(credential);
843
+ * const profile = await graphClient.api("/me").get();
844
+ *
845
+ * // TeamsBotSsoPrompt example (Bot Application)
846
+ * const requiredScopes = ["User.Read"];
847
+ * const config: Configuration = {
848
+ * loginUrl: loginUrl,
849
+ * clientId: clientId,
850
+ * clientSecret: clientSecret,
851
+ * tenantId: tenantId
852
+ * };
853
+ * const prompt = new TeamsBotSsoPrompt(dialogId, {
854
+ * config: config
855
+ * scopes: '["User.Read"],
856
+ * });
857
+ * this.addDialog(prompt);
858
+ *
859
+ * const oboCredential = new OnBehalfOfAADUserCredential(
860
+ * getUserId(dialogContext),
861
+ * {
862
+ * clientId: "AAD_APP_ID",
863
+ * clientSecret: "AAD_APP_SECRET"
864
+ * });
865
+ * try {
866
+ * const graphClient = await createMicrosoftGraphClient(credential);
867
+ * const profile = await graphClient.api("/me").get();
868
+ * } catch (e) {
869
+ * dialogContext.beginDialog(dialogId);
870
+ * return Dialog.endOfTurn();
871
+ * }
872
+ * ```
873
+ *
874
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
875
+ * @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
876
+ *
877
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
878
+ *
879
+ * @returns Graph client with specified scopes.
880
+ */
881
+ export declare function createMicrosoftGraphClient(teamsfx: TeamsFxConfiguration, scopes?: string | string[]): Client;
953
882
 
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 extends object>(cardTemplate: unknown, 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: unknown): 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>;
1044
- /**
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
1051
- */
1052
- static attachO365ConnectorCard(card: O365ConnectorCard): Partial<Activity_2>;
1053
- /**
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
1059
- */
1060
- static AttachReceiptCard(card: ReceiptCard): Partial<Activity_2>;
1061
- /**
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
1071
- */
1072
- static attachThumbnailCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<ThumbnailCard>): Partial<Activity_2>;
1073
- /**
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
1079
- */
1080
- static attachContent(attachement: Attachment): Partial<Activity_2>;
1081
- }
883
+ /**
884
+ * Get Microsoft graph client.
885
+ * @example
886
+ * Get Microsoft graph client by TokenCredential
887
+ * ```typescript
888
+ * // In browser: TeamsUserCredential
889
+ * const authConfig: TeamsUserCredentialAuthConfig = {
890
+ * clientId: "xxx",
891
+ initiateLoginEndpoint: "https://xxx/auth-start.html",
892
+ * };
1082
893
 
1083
- /**
1084
- * Microsoft Graph auth provider for Teams Framework
1085
- *
1086
- * @beta
1087
- */
1088
- export declare class MsGraphAuthProvider implements AuthenticationProvider {
1089
- private teamsfx;
1090
- private scopes;
1091
- /**
1092
- * Constructor of MsGraphAuthProvider.
1093
- *
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
1102
- */
1103
- constructor(teamsfx: TeamsFxConfiguration, scopes?: string | string[]);
1104
- /**
1105
- * Get access token for Microsoft Graph API requests.
1106
- *
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.
1114
- *
1115
- */
1116
- getAccessToken(): Promise<string>;
1117
- }
894
+ * const credential = new TeamsUserCredential(authConfig);
1118
895
 
1119
- /**
1120
- * Provide utilities to send notification to varies targets (e.g., member, group, channel).
1121
- *
1122
- * @beta
1123
- */
1124
- export declare class NotificationBot {
1125
- private readonly conversationReferenceStore;
1126
- private readonly adapter;
1127
- /**
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
1137
- */
1138
- constructor(adapter: BotFrameworkAdapter, options?: NotificationOptions_2);
1139
- /**
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
1148
- */
1149
- installations(): Promise<TeamsBotInstallation[]>;
1150
- }
896
+ * const scope = "User.Read";
897
+ * await credential.login(scope);
1151
898
 
1152
- /**
1153
- * Options to initialize {@link NotificationBot}.
1154
- *
1155
- * @beta
1156
- */
1157
- declare interface NotificationOptions_2 {
1158
- /**
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
1170
- */
1171
- storage?: NotificationTargetStorage;
1172
- }
1173
- export { NotificationOptions_2 as NotificationOptions }
899
+ * const client = createMicrosoftGraphClientWithCredential(credential, scope);
1174
900
 
1175
- /**
1176
- * Represent a notification target.
1177
- *
1178
- * @beta
1179
- */
1180
- export declare interface NotificationTarget {
1181
- /**
1182
- * The type of target, could be "Channel" or "Group" or "Person".
1183
- *
1184
- * @beta
1185
- */
1186
- readonly type?: NotificationTargetType;
1187
- /**
1188
- * Send a plain text message.
1189
- *
1190
- * @param text - the plain text message.
1191
- *
1192
- * @beta
1193
- */
1194
- sendMessage(text: string): Promise<void>;
1195
- /**
1196
- * Send an adaptive card message.
1197
- *
1198
- * @param card - the adaptive card raw JSON.
1199
- *
1200
- * @beta
1201
- */
1202
- sendAdaptiveCard(card: unknown): Promise<void>;
1203
- }
901
+ * // In node: OnBehalfOfUserCredential
902
+ * const oboAuthConfig: OnBehalfOfCredentialAuthConfig = {
903
+ * authorityHost: "xxx",
904
+ * clientId: "xxx",
905
+ * tenantId: "xxx",
906
+ * clientSecret: "xxx",
907
+ * };
1204
908
 
1205
- /**
1206
- * Interface for a storage provider that stores and retrieves notification target references.
1207
- *
1208
- * @beta
1209
- */
1210
- export declare interface NotificationTargetStorage {
1211
- /**
1212
- * Read one notification target by its key.
1213
- *
1214
- * @param key - the key of a notification target.
1215
- *
1216
- * @returns - the notification target. Or undefined if not found.
1217
- *
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.
1227
- *
1228
- * @beta
1229
- */
1230
- list(): Promise<{
1231
- [key: string]: unknown;
1232
- }[]>;
1233
- /**
1234
- * Write one notification target by its key.
1235
- *
1236
- * @param key - the key of a notification target.
1237
- * @param object - the notification target.
1238
- *
1239
- * @beta
1240
- */
1241
- write(key: string, object: {
1242
- [key: string]: unknown;
1243
- }): Promise<void>;
1244
- /**
1245
- * Delete one notification target by its key.
1246
- *
1247
- * @param key - the key of a notification target.
1248
- *
1249
- * @beta
1250
- */
1251
- delete(key: string): Promise<void>;
1252
- }
909
+ * const oboCredential = new OnBehalfOfUserCredential(ssoToken, oboAuthConfig);
910
+ * const scope = "User.Read";
911
+ * const client = createMicrosoftGraphClientWithCredential(oboCredential, scope);
1253
912
 
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";
913
+ * // In node: AppCredential
914
+ * const appAuthConfig: AppCredentialAuthConfig = {
915
+ * authorityHost: "xxx",
916
+ * clientId: "xxx",
917
+ * tenantId: "xxx",
918
+ * clientSecret: "xxx",
919
+ * };
920
+ * const appCredential = new AppCredential(appAuthConfig);
921
+ * const scope = "User.Read";
922
+ * const client = createMicrosoftGraphClientWithCredential(appCredential, scope);
923
+ *
924
+ * const profile = await client.api("/me").get();
925
+ * ```
926
+ *
927
+ * @param {TokenCredential} credential - Used to provide configuration and auth.
928
+ * @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
929
+ *
930
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
931
+ *
932
+ * @returns Graph client with specified scopes.
933
+ */
934
+ export declare function createMicrosoftGraphClientWithCredential(credential: TokenCredential, scopes?: string | string[]): Client;
1265
935
 
1266
- /**
1267
- * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
1268
- *
1269
- * @example
1270
- * ```typescript
1271
- * const credential = new OnBehalfOfUserCredential(ssoToken);
1272
- * ```
1273
- *
1274
- * @remarks
1275
- * Can only be used in server side.
1276
- *
1277
- * @beta
1278
- */
1279
- export declare class OnBehalfOfUserCredential implements TokenCredential {
1280
- private msalClient;
1281
- private ssoToken;
1282
- /**
1283
- * Constructor of OnBehalfOfUserCredential
1284
- *
1285
- * @remarks
1286
- * Only works in in server side.
1287
- *
1288
- * @param {string} ssoToken - User token provided by Teams SSO feature.
1289
- * @param {AuthenticationConfiguration} config - The authentication configuration. Use environment variables if not provided.
1290
- *
1291
- * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
1292
- * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1293
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1294
- *
1295
- * @beta
1296
- */
1297
- constructor(ssoToken: string, config: AuthenticationConfiguration);
1298
- /**
1299
- * Get access token from credential.
1300
- *
1301
- * @example
1302
- * ```typescript
1303
- * await credential.getToken([]) // Get SSO token using empty string array
1304
- * await credential.getToken("") // Get SSO token using empty string
1305
- * await credential.getToken([".default"]) // Get Graph access token with default scope using string array
1306
- * await credential.getToken(".default") // Get Graph access token with default scope using string
1307
- * await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
1308
- * await credential.getToken("User.Read") // Get Graph access token for single scope using string
1309
- * await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
1310
- * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
1311
- * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
1312
- * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
1313
- * ```
1314
- *
1315
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1316
- * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
1317
- *
1318
- * @throws {@link ErrorCode|InternalError} when failed to acquire access token on behalf of user with unknown error.
1319
- * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1320
- * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1321
- * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
1322
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1323
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1324
- *
1325
- * @returns Access token with expected scopes.
1326
- *
1327
- * @remarks
1328
- * If scopes is empty string or array, it returns SSO token.
1329
- * If scopes is non-empty, it returns access token for target scope.
1330
- *
1331
- * @beta
1332
- */
1333
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1334
- /**
1335
- * Get basic user info from SSO token.
1336
- *
1337
- * @example
1338
- * ```typescript
1339
- * const currentUser = getUserInfo();
1340
- * ```
1341
- *
1342
- * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1343
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1344
- *
1345
- * @returns Basic user info with user displayName, objectId and preferredUserName.
1346
- *
1347
- * @beta
1348
- */
1349
- getUserInfo(): UserInfo;
1350
- private generateAuthServerError;
1351
- }
936
+ /**
937
+ * Helper to create SecureContextOptions from PEM format cert
938
+ *
939
+ * @param { string | Buffer } cert - The cert chain in PEM format
940
+ * @param { string | Buffer } key - The private key for the cert chain
941
+ * @param { {passphrase?: string; ca?: string | Buffer} } options - Optional settings when create the cert options.
942
+ *
943
+ * @returns Instance of SecureContextOptions
944
+ *
945
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
946
+ *
947
+ */
948
+ export declare function createPemCertOption(cert: string | Buffer, key: string | Buffer, options?: {
949
+ passphrase?: string;
950
+ ca?: string | Buffer;
951
+ }): SecureContextOptions;
1352
952
 
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>;
953
+ /**
954
+ * Helper to create SecureContextOptions from PFX format cert
955
+ *
956
+ * @param { string | Buffer } pfx - The content of .pfx file
957
+ * @param { {passphrase?: string} } options - Optional settings when create the cert options.
958
+ *
959
+ * @returns Instance of SecureContextOptions
960
+ *
961
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
962
+ *
963
+ */
964
+ export declare function createPfxCertOption(pfx: string | Buffer, options?: {
965
+ passphrase?: string;
966
+ }): SecureContextOptions;
1363
967
 
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>;
968
+ /**
969
+ * Error code to trace the error types.
970
+ */
971
+ export declare enum ErrorCode {
972
+ /**
973
+ * Invalid parameter error.
974
+ */
975
+ InvalidParameter = "InvalidParameter",
976
+ /**
977
+ * Invalid configuration error.
978
+ */
979
+ InvalidConfiguration = "InvalidConfiguration",
980
+ /**
981
+ * Invalid certificate error.
982
+ */
983
+ InvalidCertificate = "InvalidCertificate",
984
+ /**
985
+ * Internal error.
986
+ */
987
+ InternalError = "InternalError",
988
+ /**
989
+ * Channel is not supported error.
990
+ */
991
+ ChannelNotSupported = "ChannelNotSupported",
992
+ /**
993
+ * Failed to retrieve sso token
994
+ */
995
+ FailedToRetrieveSsoToken = "FailedToRetrieveSsoToken",
996
+ /**
997
+ * Failed to process sso handler
998
+ */
999
+ FailedToProcessSsoHandler = "FailedToProcessSsoHandler",
1000
+ /**
1001
+ * Cannot find command
1002
+ */
1003
+ CannotFindCommand = "CannotFindCommand",
1004
+ /**
1005
+ * Failed to run sso step
1006
+ */
1007
+ FailedToRunSsoStep = "FailedToRunSsoStep",
1008
+ /**
1009
+ * Failed to run dedup step
1010
+ */
1011
+ FailedToRunDedupStep = "FailedToRunDedupStep",
1012
+ /**
1013
+ * Sso activity handler is undefined
1014
+ */
1015
+ SsoActivityHandlerIsUndefined = "SsoActivityHandlerIsUndefined",
1016
+ /**
1017
+ * Runtime is not supported error.
1018
+ */
1019
+ RuntimeNotSupported = "RuntimeNotSupported",
1020
+ /**
1021
+ * User failed to finish the AAD consent flow failed.
1022
+ */
1023
+ ConsentFailed = "ConsentFailed",
1024
+ /**
1025
+ * The user or administrator has not consented to use the application error.
1026
+ */
1027
+ UiRequiredError = "UiRequiredError",
1028
+ /**
1029
+ * Token is not within its valid time range error.
1030
+ */
1031
+ TokenExpiredError = "TokenExpiredError",
1032
+ /**
1033
+ * Call service (AAD or simple authentication server) failed.
1034
+ */
1035
+ ServiceError = "ServiceError",
1036
+ /**
1037
+ * Operation failed.
1038
+ */
1039
+ FailedOperation = "FailedOperation",
1040
+ /**
1041
+ * Invalid response error.
1042
+ */
1043
+ InvalidResponse = "InvalidResponse",
1044
+ /**
1045
+ * Identity type error.
1046
+ */
1047
+ IdentityTypeNotSupported = "IdentityTypeNotSupported",
1048
+ /**
1049
+ * Authentication info already exists error.
1050
+ */
1051
+ AuthorizationInfoAlreadyExists = "AuthorizationInfoAlreadyExists"
1052
+ }
1374
1053
 
1375
- /**
1376
- * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
1377
- *
1378
- * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
1379
- *
1380
- * @example
1381
- * ```typescript
1382
- * setLogFunction((level: LogLevel, message: string) => {
1383
- * if (level === LogLevel.Error) {
1384
- * console.log(message);
1385
- * }
1386
- * });
1387
- * ```
1388
- *
1389
- * @beta
1390
- */
1391
- export declare function setLogFunction(logFunction?: LogFunction): void;
1054
+ /**
1055
+ * Error class with code and message thrown by the SDK.
1056
+ */
1057
+ export declare class ErrorWithCode extends Error {
1058
+ /**
1059
+ * Error code
1060
+ *
1061
+ * @readonly
1062
+ */
1063
+ code: string | undefined;
1064
+ /**
1065
+ * Constructor of ErrorWithCode.
1066
+ *
1067
+ * @param {string} message - error message.
1068
+ * @param {ErrorCode} code - error code.
1069
+ */
1070
+ constructor(message?: string, code?: ErrorCode);
1071
+ }
1392
1072
 
1393
- /**
1394
- * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
1395
- *
1396
- * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
1397
- *
1398
- * @example
1399
- * ```typescript
1400
- * setLogger({
1401
- * verbose: console.debug,
1402
- * info: console.info,
1403
- * warn: console.warn,
1404
- * error: console.error,
1405
- * });
1406
- * ```
1407
- *
1408
- * @beta
1409
- */
1410
- export declare function setLogger(logger?: Logger): void;
1073
+ /**
1074
+ * Get log level.
1075
+ *
1076
+ * @returns Log level
1077
+ */
1078
+ export declare function getLogLevel(): LogLevel | undefined;
1411
1079
 
1412
- /**
1413
- * Update log level helper.
1414
- *
1415
- * @param { LogLevel } level - log level in configuration
1416
- *
1417
- * @beta
1418
- */
1419
- export declare function setLogLevel(level: LogLevel): void;
1080
+ export declare interface GetTeamsUserTokenOptions extends GetTokenOptions {
1081
+ resources?: string[];
1082
+ }
1420
1083
 
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
- }
1084
+ /**
1085
+ * Generate connection configuration consumed by tedious.
1086
+ *
1087
+ * @deprecated we recommend you compose your own Tedious configuration for better flexibility.
1088
+ *
1089
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth
1090
+ * @param { string? } databaseName - specify database name to override default one if there are multiple databases.
1091
+ *
1092
+ * @returns Connection configuration of tedious for the SQL.
1093
+ *
1094
+ * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
1095
+ * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
1096
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1097
+ */
1098
+ export declare function getTediousConnectionConfig(teamsfx: TeamsFx, databaseName?: string): Promise<ConnectionConfig>;
1503
1099
 
1504
- /**
1505
- * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
1506
- * help receive oauth token, asks the user to consent if needed.
1507
- *
1508
- * @remarks
1509
- * The prompt will attempt to retrieve the users current token of the desired scopes and store it in
1510
- * the token store.
1511
- *
1512
- * User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO):
1513
- * https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots
1514
- *
1515
- * @example
1516
- * When used with your bots `DialogSet` you can simply add a new instance of the prompt as a named
1517
- * dialog using `DialogSet.add()`. You can then start the prompt from a waterfall step using either
1518
- * `DialogContext.beginDialog()` or `DialogContext.prompt()`. The user will be prompted to sign in as
1519
- * needed and their access token will be passed as an argument to the callers next waterfall step:
1520
- *
1521
- * ```JavaScript
1522
- * const { ConversationState, MemoryStorage } = require('botbuilder');
1523
- * const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
1524
- * const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');
1525
- *
1526
- * const convoState = new ConversationState(new MemoryStorage());
1527
- * const dialogState = convoState.createProperty('dialogState');
1528
- * const dialogs = new DialogSet(dialogState);
1529
- *
1530
- * dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
1531
- * scopes: ["User.Read"],
1532
- * }));
1533
- *
1534
- * dialogs.add(new WaterfallDialog('taskNeedingLogin', [
1535
- * async (step) => {
1536
- * return await step.beginDialog('TeamsBotSsoPrompt');
1537
- * },
1538
- * async (step) => {
1539
- * const token = step.result;
1540
- * if (token) {
1541
- *
1542
- * // ... continue with task needing access token ...
1543
- *
1544
- * } else {
1545
- * await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
1546
- * return await step.endDialog();
1547
- * }
1548
- * }
1549
- * ]));
1550
- * ```
1551
- *
1552
- * @beta
1553
- */
1554
- export declare class TeamsBotSsoPrompt extends Dialog {
1555
- private teamsfx;
1556
- private settings;
1557
- /**
1558
- * Constructor of TeamsBotSsoPrompt.
1559
- *
1560
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth
1561
- * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
1562
- * @param settings Settings used to configure the prompt.
1563
- *
1564
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1565
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1566
- *
1567
- * @beta
1568
- */
1569
- constructor(teamsfx: TeamsFx, dialogId: string, settings: TeamsBotSsoPromptSettings);
1570
- /**
1571
- * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
1572
- * @remarks
1573
- * If the task is successful, the result indicates whether the prompt is still
1574
- * active after the turn has been processed by the prompt.
1575
- *
1576
- * @param dc The DialogContext for the current turn of the conversation.
1577
- *
1578
- * @throws {@link ErrorCode|InvalidParameter} when timeout property in teams bot sso prompt settings is not number or is not positive.
1579
- * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
1580
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1581
- *
1582
- * @returns A `Promise` representing the asynchronous operation.
1583
- *
1584
- * @beta
1585
- */
1586
- beginDialog(dc: DialogContext): Promise<DialogTurnResult>;
1587
- /**
1588
- * Called when a prompt dialog is the active dialog and the user replied with a new activity.
1589
- *
1590
- * @remarks
1591
- * If the task is successful, the result indicates whether the dialog is still
1592
- * active after the turn has been processed by the dialog.
1593
- * The prompt generally continues to receive the user's replies until it accepts the
1594
- * user's reply as valid input for the prompt.
1595
- *
1596
- * @param dc The DialogContext for the current turn of the conversation.
1597
- *
1598
- * @returns A `Promise` representing the asynchronous operation.
1599
- *
1600
- * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
1601
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1602
- *
1603
- * @beta
1604
- */
1605
- continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
1606
- private loadAndValidateConfig;
1607
- /**
1608
- * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
1609
- * @param dc dialog context
1610
- * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
1611
- * @internal
1612
- */
1613
- private ensureMsTeamsChannel;
1614
- /**
1615
- * Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
1616
- * For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
1617
- *
1618
- * @internal
1619
- */
1620
- private sendOAuthCardAsync;
1621
- /**
1622
- * Get sign in resource.
1623
- *
1624
- * @throws {@link ErrorCode|InvalidConfiguration} if client id, tenant id or initiate login endpoint is not found in config.
1625
- *
1626
- * @internal
1627
- */
1628
- private getSignInResource;
1629
- /**
1630
- * @internal
1631
- */
1632
- private recognizeToken;
1633
- /**
1634
- * @internal
1635
- */
1636
- private getTokenExchangeInvokeResponse;
1637
- /**
1638
- * @internal
1639
- */
1640
- private isTeamsVerificationInvoke;
1641
- /**
1642
- * @internal
1643
- */
1644
- private isTokenExchangeRequestInvoke;
1645
- /**
1646
- * @internal
1647
- */
1648
- private isTokenExchangeRequest;
1649
- }
1100
+ /**
1101
+ * Users execute query in message extension with SSO or access token.
1102
+ *
1103
+ * @param {TurnContext} context - The context object for the current turn.
1104
+ * @param {OnBehalfOfCredentialAuthConfig} config - User custom the message extension authentication configuration.
1105
+ * @param {initiateLoginEndpoint} initiateLoginEndpoint - Login page for Teams to redirect to.
1106
+ * @param {string| string[]} scopes - The list of scopes for which the token will have access.
1107
+ * @param {function} logic - Business logic when executing the query in message extension with SSO or access token.
1108
+ *
1109
+ * @throws {@link ErrorCode|InternalError} when User invoke not response to message extension query.
1110
+ * @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
1111
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1112
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
1113
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1114
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1115
+ *
1116
+ * @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
1117
+ */
1118
+ export declare function handleMessageExtensionQueryWithSSO(context: TurnContext, config: OnBehalfOfCredentialAuthConfig, initiateLoginEndpoint: string, scopes: string | string[], logic: (token: MessageExtensionTokenResponse) => Promise<any>): Promise<void | MessagingExtensionResponse>;
1650
1119
 
1651
- /**
1652
- * Settings used to configure an TeamsBotSsoPrompt instance.
1653
- *
1654
- * @beta
1655
- */
1656
- export declare interface TeamsBotSsoPromptSettings {
1657
- /**
1658
- * The array of strings that declare the desired permissions and the resources requested.
1659
- */
1660
- scopes: string[];
1661
- /**
1662
- * (Optional) number of milliseconds the prompt will wait for the user to authenticate.
1663
- * Defaults to a value `900,000` (15 minutes.)
1664
- */
1665
- timeout?: number;
1666
- /**
1667
- * (Optional) value indicating whether the TeamsBotSsoPrompt should end upon receiving an
1668
- * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
1669
- * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
1670
- * Defaults to value `true`
1671
- */
1672
- endOnInvalidMessage?: boolean;
1673
- }
1120
+ /**
1121
+ * Users execute query in message extension with SSO or access token.
1122
+ *
1123
+ *
1124
+ * @param {TurnContext} context - The context object for the current turn.
1125
+ * @param {AuthenticationConfiguration} config - User custom the message extension authentication configuration.
1126
+ * @param {string| string[]} scopes - The list of scopes for which the token will have access.
1127
+ * @param {function} logic - Business logic when executing the query in message extension with SSO or access token.
1128
+ *
1129
+ * @throws {@link ErrorCode|InternalError} when User invoke not response to message extension query.
1130
+ * @throws {@link ErrorCode|InternalError} when failed to get access token with unknown error.
1131
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1132
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
1133
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1134
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1135
+ *
1136
+ * @returns A MessageExtension Response for the activity. If the logic not return any, return void instead.
1137
+ */
1138
+ export declare function handleMessageExtensionQueryWithToken(context: TurnContext, config: AuthenticationConfiguration | null, scopes: string | string[], logic: (token: MessageExtensionTokenResponse) => Promise<any>): Promise<MessagingExtensionResponse | void>;
1674
1139
 
1675
- /**
1676
- * Token response provided by Teams Bot SSO prompt
1677
- *
1678
- * @beta
1679
- */
1680
- export declare interface TeamsBotSsoPromptTokenResponse extends TokenResponse {
1681
- /**
1682
- * SSO token for user
1683
- */
1684
- ssoToken: string;
1685
- /**
1686
- * Expire time of SSO token
1687
- */
1688
- ssoTokenExpiration: string;
1689
- }
1140
+ /**
1141
+ * Identity type to use in authentication.
1142
+ */
1143
+ export declare enum IdentityType {
1144
+ /**
1145
+ * Represents the current user of Teams.
1146
+ */
1147
+ User = "User",
1148
+ /**
1149
+ * Represents the application itself.
1150
+ */
1151
+ App = "Application"
1152
+ }
1690
1153
 
1691
- /**
1692
- * A class providing credential and configuration.
1693
- * @beta
1694
- */
1695
- export declare class TeamsFx implements TeamsFxConfiguration {
1696
- private configuration;
1697
- private oboUserCredential?;
1698
- private appCredential?;
1699
- private identityType;
1700
- /**
1701
- * Constructor of TeamsFx
1702
- *
1703
- * @param {IdentityType} identityType - Choose user or app identity
1704
- * @param customConfig - key/value pairs of customized configuration that overrides default ones.
1705
- *
1706
- * @throws {@link ErrorCode|IdentityTypeNotSupported} when setting app identity in browser.
1707
- *
1708
- * @beta
1709
- */
1710
- constructor(identityType?: IdentityType, customConfig?: Record<string, string>);
1711
- /**
1712
- * Identity type set by user.
1713
- *
1714
- * @returns identity type.
1715
- * @beta
1716
- */
1717
- getIdentityType(): IdentityType;
1718
- /**
1719
- * Credential instance according to identity type choice.
1720
- *
1721
- * @remarks If user identity is chose, will return {@link TeamsUserCredential}
1722
- * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
1723
- * identity is chose, will return {@link AppCredential}.
1724
- *
1725
- * @returns instance implements TokenCredential interface.
1726
- * @beta
1727
- */
1728
- getCredential(): TokenCredential;
1729
- /**
1730
- * Get user information.
1731
- * @returns UserInfo object.
1732
- * @beta
1733
- */
1734
- getUserInfo(): Promise<UserInfo>;
1735
- /**
1736
- * Popup login page to get user's access token with specific scopes.
1737
- *
1738
- * @remarks
1739
- * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
1740
- *
1741
- * @example
1742
- * ```typescript
1743
- * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
1744
- * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
1745
- * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
1746
- * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
1747
- * ```
1748
- * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
1749
- *
1750
- * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
1751
- * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
1752
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1753
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1754
- *
1755
- * @beta
1756
- */
1757
- login(scopes: string | string[]): Promise<void>;
1758
- /**
1759
- * Set SSO token when using user identity in NodeJS.
1760
- * @param {string} ssoToken - used for on behalf of user flow.
1761
- * @returns self instance.
1762
- * @beta
1763
- */
1764
- setSsoToken(ssoToken: string): TeamsFx;
1765
- /**
1766
- * Usually used by service plugins to retrieve specific config
1767
- * @param {string} key - configuration key.
1768
- * @returns value in configuration.
1769
- * @beta
1770
- */
1771
- getConfig(key: string): string;
1772
- /**
1773
- * Check the value of specific key.
1774
- * @param {string} key - configuration key.
1775
- * @returns true if corresponding value is not empty string.
1776
- * @beta
1777
- */
1778
- hasConfig(key: string): boolean;
1779
- /**
1780
- * Get all configurations.
1781
- * @returns key value mappings.
1782
- * @beta
1783
- */
1784
- getConfigs(): Record<string, string>;
1785
- /**
1786
- * Load configuration from environment variables.
1787
- */
1788
- private loadFromEnv;
1789
- }
1154
+ /**
1155
+ * Status code for an `application/vnd.microsoft.error` invoke response.
1156
+ */
1157
+ export declare enum InvokeResponseErrorCode {
1158
+ /**
1159
+ * Invalid request.
1160
+ */
1161
+ BadRequest = 400,
1162
+ /**
1163
+ * Internal server error.
1164
+ */
1165
+ InternalServerError = 500
1166
+ }
1790
1167
 
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
- * Or no return value if developers want to send the response activity by themselves in this method.
1808
- */
1809
- handleCommandReceived(context: TurnContext, message: CommandMessage): Promise<string | Partial<Activity> | void>;
1810
- }
1168
+ /**
1169
+ * Provides methods for formatting various invoke responses a bot can send to respond to an invoke request.
1170
+ *
1171
+ * @remarks
1172
+ * All of these functions return an {@link InvokeResponse} object, which can be
1173
+ * passed as input to generate a new `invokeResponse` activity.
1174
+ *
1175
+ * This example sends an invoke response that contains an adaptive card.
1176
+ *
1177
+ * ```typescript
1178
+ *
1179
+ * const myCard = {
1180
+ * type: "AdaptiveCard",
1181
+ * body: [
1182
+ * {
1183
+ * "type": "TextBlock",
1184
+ * "text": "This is a sample card"
1185
+ * }],
1186
+ * $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
1187
+ * version: "1.4"
1188
+ * };
1189
+ *
1190
+ * const invokeResponse = InvokeResponseFactory.adaptiveCard(myCard);
1191
+ * await context.sendActivity({
1192
+ * type: ActivityTypes.InvokeResponse,
1193
+ * value: invokeResponse,
1194
+ * });
1195
+ * ```
1196
+ */
1197
+ export declare class InvokeResponseFactory {
1198
+ /**
1199
+ * Create an invoke response from a text message.
1200
+ * The type of the invoke response is `application/vnd.microsoft.activity.message`
1201
+ * indicates the request was successfully processed.
1202
+ *
1203
+ * @param message A text message included in a invoke response.
1204
+ *
1205
+ * @returns {InvokeResponse} An InvokeResponse object.
1206
+ */
1207
+ static textMessage(message: string): InvokeResponse;
1208
+ /**
1209
+ * Create an invoke response from an adaptive card.
1210
+ *
1211
+ * The type of the invoke response is `application/vnd.microsoft.card.adaptive` indicates
1212
+ * the request was successfully processed, and the response includes an adaptive card
1213
+ * that the client should display in place of the current one.
1214
+ *
1215
+ * @param card The adaptive card JSON payload.
1216
+ *
1217
+ * @returns {InvokeResponse} An InvokeResponse object.
1218
+ */
1219
+ static adaptiveCard(card: unknown): InvokeResponse;
1220
+ /**
1221
+ * Create an invoke response with error code and message.
1222
+ *
1223
+ * The type of the invoke response is `application/vnd.microsoft.error` indicates
1224
+ * the request was failed to processed.
1225
+ *
1226
+ * @param errorCode The status code indicates error, available values:
1227
+ * - 400 (BadRequest): indicate the incoming request was invalid.
1228
+ * - 500 (InternalServerError): indicate an unexpected error occurred.
1229
+ * @param errorMessage The error message.
1230
+ *
1231
+ * @returns {InvokeResponse} An InvokeResponse object.
1232
+ */
1233
+ static errorResponse(errorCode: InvokeResponseErrorCode, errorMessage: string): InvokeResponse;
1234
+ /**
1235
+ * Create an invoke response with status code and response value.
1236
+ * @param statusCode The status code.
1237
+ * @param body The value of the response body.
1238
+ *
1239
+ * @returns {InvokeResponse} An InvokeResponse object.
1240
+ */
1241
+ static createInvokeResponse(statusCode: StatusCodes, body?: unknown): InvokeResponse;
1242
+ }
1811
1243
 
1812
- /**
1813
- * TeamsFx interface that provides credential and configuration.
1814
- * @beta
1815
- */
1816
- declare interface TeamsFxConfiguration {
1817
- /**
1818
- * Identity type set by user.
1819
- *
1820
- * @returns identity type.
1821
- * @beta
1822
- */
1823
- getIdentityType(): IdentityType;
1824
- /**
1825
- * Credential instance according to identity type choice.
1826
- *
1827
- * @remarks If user identity is chose, will return {@link TeamsUserCredential}
1828
- * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
1829
- * identity is chose, will return {@link AppCredential}.
1830
- *
1831
- * @returns instance implements TokenCredential interface.
1832
- * @beta
1833
- */
1834
- getCredential(): TokenCredential;
1835
- /**
1836
- * Get user information.
1837
- * @returns UserInfo object.
1838
- * @beta
1839
- */
1840
- getUserInfo(): Promise<UserInfo>;
1841
- /**
1842
- * Popup login page to get user's access token with specific scopes.
1843
- *
1844
- * @remarks
1845
- * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
1846
- *
1847
- * @example
1848
- * ```typescript
1849
- * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
1850
- * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
1851
- * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
1852
- * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
1853
- * ```
1854
- * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
1855
- *
1856
- * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
1857
- * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
1858
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1859
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1860
- *
1861
- * @beta
1862
- */
1863
- login(scopes: string | string[]): Promise<void>;
1864
- /**
1865
- * Set SSO token when using user identity in NodeJS.
1866
- * @param {string} ssoToken - used for on behalf of user flow.
1867
- * @returns self instance.
1868
- * @beta
1869
- */
1870
- setSsoToken(ssoToken: string): TeamsFxConfiguration;
1871
- /**
1872
- * Usually used by service plugins to retrieve specific config
1873
- * @param {string} key - configuration key.
1874
- * @returns value in configuration.
1875
- * @beta
1876
- */
1877
- getConfig(key: string): string;
1878
- /**
1879
- * Check the value of specific key.
1880
- * @param {string} key - configuration key.
1881
- * @returns true if corresponding value is not empty string.
1882
- * @beta
1883
- */
1884
- hasConfig(key: string): boolean;
1885
- /**
1886
- * Get all configurations.
1887
- * @returns key value mappings.
1888
- * @beta
1889
- */
1890
- getConfigs(): Record<string, string>;
1891
- }
1244
+ /**
1245
+ * Log function for customized logging.
1246
+ */
1247
+ export declare type LogFunction = (level: LogLevel, message: string) => void;
1892
1248
 
1893
- /**
1894
- * Represent Teams current user's identity, and it is used within Teams client applications.
1895
- *
1896
- * @remarks
1897
- * Can only be used within Teams.
1898
- *
1899
- * @beta
1900
- */
1901
- export declare class TeamsUserCredential implements TokenCredential {
1902
- /**
1903
- * Constructor of TeamsUserCredential.
1904
- * @remarks
1905
- * Can only be used within Teams.
1906
- * @beta
1907
- */
1908
- constructor(authConfig: AuthenticationConfiguration);
1909
- /**
1910
- * Popup login page to get user's access token with specific scopes.
1911
- * @remarks
1912
- * Can only be used within Teams.
1913
- * @beta
1914
- */
1915
- login(scopes: string | string[]): Promise<void>;
1916
- /**
1917
- * Get access token from credential.
1918
- * @remarks
1919
- * Can only be used within Teams.
1920
- * @beta
1921
- */
1922
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1923
- /**
1924
- * Get basic user info from SSO token
1925
- * @remarks
1926
- * Can only be used within Teams.
1927
- * @beta
1928
- */
1929
- getUserInfo(): Promise<UserInfo>;
1930
- }
1249
+ /**
1250
+ * Interface for customized logger.
1251
+ */
1252
+ export declare interface Logger {
1253
+ /**
1254
+ * Writes to error level logging or lower.
1255
+ */
1256
+ error(message: string): void;
1257
+ /**
1258
+ * Writes to warning level logging or lower.
1259
+ */
1260
+ warn(message: string): void;
1261
+ /**
1262
+ * Writes to info level logging or lower.
1263
+ */
1264
+ info(message: string): void;
1265
+ /**
1266
+ * Writes to verbose level logging.
1267
+ */
1268
+ verbose(message: string): void;
1269
+ }
1931
1270
 
1932
- /**
1933
- * The trigger pattern used to trigger a {@link TeamsFxBotCommandHandler} instance.
1934
- */
1935
- export declare type TriggerPatterns = string | RegExp | (string | RegExp)[];
1271
+ /**
1272
+ * Log level.
1273
+ */
1274
+ export declare enum LogLevel {
1275
+ /**
1276
+ * Show verbose, information, warning and error message.
1277
+ */
1278
+ Verbose = 0,
1279
+ /**
1280
+ * Show information, warning and error message.
1281
+ */
1282
+ Info = 1,
1283
+ /**
1284
+ * Show warning and error message.
1285
+ */
1286
+ Warn = 2,
1287
+ /**
1288
+ * Show error message.
1289
+ */
1290
+ Error = 3
1291
+ }
1936
1292
 
1937
- /**
1938
- * UserInfo with user displayName, objectId and preferredUserName.
1939
- *
1940
- * @beta
1941
- */
1942
- export declare interface UserInfo {
1943
- /**
1944
- * User Display Name.
1945
- *
1946
- * @readonly
1947
- */
1948
- displayName: string;
1949
- /**
1950
- * User unique reference within the Azure Active Directory domain.
1951
- *
1952
- * @readonly
1953
- */
1954
- objectId: string;
1955
- /**
1956
- * Usually be the email address.
1957
- *
1958
- * @readonly
1959
- */
1960
- preferredUserName: string;
1961
- }
1293
+ /**
1294
+ * A {@link NotificationTarget} that represents a team member.
1295
+ *
1296
+ * @remarks
1297
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}.
1298
+ */
1299
+ export declare class Member implements NotificationTarget {
1300
+ /**
1301
+ * The parent {@link TeamsBotInstallation} where this member is created from.
1302
+ */
1303
+ readonly parent: TeamsBotInstallation;
1304
+ /**
1305
+ * Detailed member account information.
1306
+ */
1307
+ readonly account: TeamsChannelAccount;
1308
+ /**
1309
+ * Notification target type. For member it's always "Person".
1310
+ */
1311
+ readonly type: NotificationTargetType;
1312
+ /**
1313
+ * Constructor.
1314
+ *
1315
+ * @remarks
1316
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
1317
+ *
1318
+ * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
1319
+ * @param account - Detailed member account information.
1320
+ */
1321
+ constructor(parent: TeamsBotInstallation, account: TeamsChannelAccount);
1322
+ /**
1323
+ * Send a plain text message.
1324
+ *
1325
+ * @param text - the plain text message.
1326
+ * @param onError - an optional error handler that can catch exceptions during message sending.
1327
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
1328
+ * @returns the response of sending message.
1329
+ */
1330
+ sendMessage(text: string, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
1331
+ /**
1332
+ * Send an adaptive card message.
1333
+ *
1334
+ * @param card - the adaptive card raw JSON.
1335
+ * @param onError - an optional error handler that can catch exceptions during adaptive card sending.
1336
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
1337
+ * @returns the response of sending adaptive card message.
1338
+ */
1339
+ sendAdaptiveCard(card: unknown, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
1340
+ /**
1341
+ * @internal
1342
+ */
1343
+ private newConversation;
1344
+ }
1345
+
1346
+ /**
1347
+ * Provides utility method to build bot message with cards that supported in Teams.
1348
+ */
1349
+ export declare class MessageBuilder {
1350
+ /**
1351
+ * Build a bot message activity attached with adaptive card.
1352
+ *
1353
+ * @param cardTemplate The adaptive card template.
1354
+ * @param data card data used to render the template.
1355
+ * @returns A bot message activity attached with an adaptive card.
1356
+ *
1357
+ * @example
1358
+ * ```javascript
1359
+ * const cardTemplate = {
1360
+ * type: "AdaptiveCard",
1361
+ * body: [
1362
+ * {
1363
+ * "type": "TextBlock",
1364
+ * "text": "${title}",
1365
+ * "size": "Large"
1366
+ * },
1367
+ * {
1368
+ * "type": "TextBlock",
1369
+ * "text": "${description}"
1370
+ * }],
1371
+ * $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
1372
+ * version: "1.4"
1373
+ * };
1374
+ *
1375
+ * type CardData = {
1376
+ * title: string,
1377
+ * description: string
1378
+ * };
1379
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(
1380
+ * cardTemplate, {
1381
+ * title: "sample card title",
1382
+ * description: "sample card description"
1383
+ * });
1384
+ * ```
1385
+ */
1386
+ static attachAdaptiveCard<TData extends object>(cardTemplate: unknown, data: TData): Partial<Activity>;
1387
+ /**
1388
+ * Build a bot message activity attached with an adaptive card.
1389
+ *
1390
+ * @param card The adaptive card content.
1391
+ * @returns A bot message activity attached with an adaptive card.
1392
+ */
1393
+ static attachAdaptiveCardWithoutData(card: unknown): Partial<Activity>;
1394
+ /**
1395
+ * Build a bot message activity attached with an hero card.
1396
+ *
1397
+ * @param title The card title.
1398
+ * @param images Optional. The array of images to include on the card.
1399
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
1400
+ * is converted to an `imBack` button with a title and value set to the value of the string.
1401
+ * @param other Optional. Any additional properties to include on the card.
1402
+ *
1403
+ * @returns A bot message activity attached with a hero card.
1404
+ *
1405
+ * @example
1406
+ * ```javascript
1407
+ * const message = MessageBuilder.attachHeroCard(
1408
+ * 'sample title',
1409
+ * ['https://example.com/sample.jpg'],
1410
+ * ['action']
1411
+ * );
1412
+ * ```
1413
+ */
1414
+ static attachHeroCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<HeroCard>): Partial<Activity>;
1415
+ /**
1416
+ * Returns an attachment for a sign-in card.
1417
+ *
1418
+ * @param title The title for the card's sign-in button.
1419
+ * @param url The URL of the sign-in page to use.
1420
+ * @param text Optional. Additional text to include on the card.
1421
+ *
1422
+ * @returns A bot message activity attached with a sign-in card.
1423
+ *
1424
+ * @remarks
1425
+ * For channels that don't natively support sign-in cards, an alternative message is rendered.
1426
+ */
1427
+ static attachSigninCard(title: string, url: string, text?: string): Partial<Activity>;
1428
+ /**
1429
+ * Build a bot message activity attached with an Office 365 connector card.
1430
+ *
1431
+ * @param card A description of the Office 365 connector card.
1432
+ * @returns A bot message activity attached with an Office 365 connector card.
1433
+ */
1434
+ static attachO365ConnectorCard(card: O365ConnectorCard): Partial<Activity>;
1435
+ /**
1436
+ * Build a message activity attached with a receipt card.
1437
+ * @param card A description of the receipt card.
1438
+ * @returns A message activity attached with a receipt card.
1439
+ */
1440
+ static AttachReceiptCard(card: ReceiptCard): Partial<Activity>;
1441
+ /**
1442
+ *
1443
+ * @param title The card title.
1444
+ * @param images Optional. The array of images to include on the card.
1445
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
1446
+ * is converted to an `imBack` button with a title and value set to the value of the string.
1447
+ * @param other Optional. Any additional properties to include on the card.
1448
+ * @returns A message activity attached with a thumbnail card
1449
+ */
1450
+ static attachThumbnailCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<ThumbnailCard>): Partial<Activity>;
1451
+ /**
1452
+ * Add an attachement to a bot activity.
1453
+ * @param attachement The attachment object to attach.
1454
+ * @returns A message activity with an attachment.
1455
+ */
1456
+ static attachContent(attachement: Attachment): Partial<Activity>;
1457
+ }
1458
+
1459
+ /**
1460
+ * Token response provided by Teams Bot SSO prompt
1461
+ */
1462
+ export declare interface MessageExtensionTokenResponse extends TokenResponse {
1463
+ /**
1464
+ * SSO token for user
1465
+ */
1466
+ ssoToken: string;
1467
+ /**
1468
+ * Expire time of SSO token
1469
+ */
1470
+ ssoTokenExpiration: string;
1471
+ }
1472
+
1473
+ /**
1474
+ * The response of a message action, e.g., `sendMessage`, `sendAdaptiveCard`.
1475
+ */
1476
+ declare interface MessageResponse {
1477
+ /**
1478
+ * Id of the message.
1479
+ */
1480
+ id?: string;
1481
+ }
1482
+
1483
+ /**
1484
+ * Microsoft Graph auth provider for Teams Framework
1485
+ */
1486
+ export declare class MsGraphAuthProvider implements AuthenticationProvider {
1487
+ private credentialOrTeamsFx;
1488
+ private scopes;
1489
+ /**
1490
+ * Constructor of MsGraphAuthProvider.
1491
+ *
1492
+ * @param {TeamsFxConfiguration} teamsfx - Used to provide configuration and auth.
1493
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1494
+ *
1495
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1496
+ *
1497
+ * @returns An instance of MsGraphAuthProvider.
1498
+ */
1499
+ constructor(teamsfx: TeamsFxConfiguration, scopes?: string | string[]);
1500
+ /**
1501
+ * Constructor of MsGraphAuthProvider.
1502
+ *
1503
+ * @param {TokenCredential} credential - credential used to provide configuration and auth.
1504
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1505
+ *
1506
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1507
+ *
1508
+ * @returns An instance of MsGraphAuthProvider.
1509
+ */
1510
+ constructor(credential: TokenCredential, scopes?: string | string[]);
1511
+ /**
1512
+ * Get access token for Microsoft Graph API requests.
1513
+ *
1514
+ * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
1515
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1516
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1517
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
1518
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1519
+ *
1520
+ * @returns Access token from the credential.
1521
+ *
1522
+ */
1523
+ getAccessToken(): Promise<string>;
1524
+ }
1525
+
1526
+ /**
1527
+ * Provide utilities to send notification to varies targets (e.g., member, group, channel).
1528
+ */
1529
+ export declare class NotificationBot {
1530
+ private readonly conversationReferenceStore;
1531
+ private readonly adapter;
1532
+ /**
1533
+ * constructor of the notification bot.
1534
+ *
1535
+ * @remarks
1536
+ * To ensure accuracy, it's recommended to initialize before handling any message.
1537
+ *
1538
+ * @param adapter - the bound `BotFrameworkAdapter`
1539
+ * @param options - initialize options
1540
+ */
1541
+ constructor(adapter: BotFrameworkAdapter, options?: NotificationOptions_2);
1542
+ /**
1543
+ * Get all targets where the bot is installed.
1544
+ *
1545
+ * @remarks
1546
+ * The result is retrieving from the persisted storage.
1547
+ *
1548
+ * @returns - an array of {@link TeamsBotInstallation}.
1549
+ */
1550
+ installations(): Promise<TeamsBotInstallation[]>;
1551
+ /**
1552
+ * Returns the first {@link Member} where predicate is true, and undefined otherwise.
1553
+ *
1554
+ * @param predicate find calls predicate once for each member of the installation,
1555
+ * until it finds one where predicate returns true. If such a member is found, find
1556
+ * immediately returns that member. Otherwise, find returns undefined.
1557
+ * @param scope the scope to find members from the installations
1558
+ * (personal chat, group chat, Teams channel).
1559
+ * @returns the first {@link Member} where predicate is true, and undefined otherwise.
1560
+ */
1561
+ findMember(predicate: (member: Member) => Promise<boolean>, scope?: SearchScope): Promise<Member | undefined>;
1562
+ /**
1563
+ * Returns the first {@link Channel} where predicate is true, and undefined otherwise.
1564
+ * (Ensure the bot app is installed into the `General` channel, otherwise undefined will be returned.)
1565
+ *
1566
+ * @param predicate find calls predicate once for each channel of the installation,
1567
+ * until it finds one where predicate returns true. If such a channel is found, find
1568
+ * immediately returns that channel. Otherwise, find returns undefined.
1569
+ * @returns the first {@link Channel} where predicate is true, and undefined otherwise.
1570
+ */
1571
+ findChannel(predicate: (channel: Channel, teamDetails: TeamDetails | undefined) => Promise<boolean>): Promise<Channel | undefined>;
1572
+ /**
1573
+ * Returns all {@link Member} where predicate is true, and empty array otherwise.
1574
+ *
1575
+ * @param predicate find calls predicate for each member of the installation.
1576
+ * @param scope the scope to find members from the installations
1577
+ * (personal chat, group chat, Teams channel).
1578
+ * @returns an array of {@link Member} where predicate is true, and empty array otherwise.
1579
+ */
1580
+ findAllMembers(predicate: (member: Member) => Promise<boolean>, scope?: SearchScope): Promise<Member[]>;
1581
+ /**
1582
+ * Returns all {@link Channel} where predicate is true, and empty array otherwise.
1583
+ * (Ensure the bot app is installed into the `General` channel, otherwise empty array will be returned.)
1584
+ *
1585
+ * @param predicate find calls predicate for each channel of the installation.
1586
+ * @returns an array of {@link Channel} where predicate is true, and empty array otherwise.
1587
+ */
1588
+ findAllChannels(predicate: (channel: Channel, teamDetails: TeamDetails | undefined) => Promise<boolean>): Promise<Channel[]>;
1589
+ private matchSearchScope;
1590
+ }
1591
+
1592
+ /**
1593
+ * Options to initialize {@link NotificationBot}.
1594
+ */
1595
+ declare interface NotificationOptions_2 {
1596
+ /**
1597
+ * An optional storage to persist bot notification connections.
1598
+ *
1599
+ * @remarks
1600
+ * If `storage` is not provided, a default local file storage will be used,
1601
+ * which stores notification connections into:
1602
+ * - ".notification.localstore.json" if running locally
1603
+ * - "${process.env.TEMP}/.notification.localstore.json" if `process.env.RUNNING_ON_AZURE` is set to "1"
1604
+ *
1605
+ * It's recommended to use your own shared storage for production environment.
1606
+ */
1607
+ storage?: NotificationTargetStorage;
1608
+ }
1609
+ export { NotificationOptions_2 as NotificationOptions }
1610
+
1611
+ /**
1612
+ * Represent a notification target.
1613
+ */
1614
+ export declare interface NotificationTarget {
1615
+ /**
1616
+ * The type of target, could be "Channel" or "Group" or "Person".
1617
+ */
1618
+ readonly type?: NotificationTargetType;
1619
+ /**
1620
+ * Send a plain text message.
1621
+ *
1622
+ * @param text - the plain text message.
1623
+ * @param onError - an optional error handler that can catch exceptions during message sending.
1624
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
1625
+ *
1626
+ * @returns the response of sending message.
1627
+ */
1628
+ sendMessage(text: string, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
1629
+ /**
1630
+ * Send an adaptive card message.
1631
+ *
1632
+ * @param card - the adaptive card raw JSON.
1633
+ * @param onError - an optional error handler that can catch exceptions during adaptive card sending.
1634
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
1635
+ *
1636
+ * @returns the response of sending adaptive card message.
1637
+ */
1638
+ sendAdaptiveCard(card: unknown, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
1639
+ }
1640
+
1641
+ /**
1642
+ * Interface for a storage provider that stores and retrieves notification target references.
1643
+ */
1644
+ export declare interface NotificationTargetStorage {
1645
+ /**
1646
+ * Read one notification target by its key.
1647
+ *
1648
+ * @param key - the key of a notification target.
1649
+ *
1650
+ * @returns - the notification target. Or undefined if not found.
1651
+ */
1652
+ read(key: string): Promise<{
1653
+ [key: string]: unknown;
1654
+ } | undefined>;
1655
+ /**
1656
+ * List all stored notification targets.
1657
+ *
1658
+ * @returns - an array of notification target. Or an empty array if nothing is stored.
1659
+ */
1660
+ list(): Promise<{
1661
+ [key: string]: unknown;
1662
+ }[]>;
1663
+ /**
1664
+ * Write one notification target by its key.
1665
+ *
1666
+ * @param key - the key of a notification target.
1667
+ * @param object - the notification target.
1668
+ */
1669
+ write(key: string, object: {
1670
+ [key: string]: unknown;
1671
+ }): Promise<void>;
1672
+ /**
1673
+ * Delete one notification target by its key.
1674
+ *
1675
+ * @param key - the key of a notification target.
1676
+ */
1677
+ delete(key: string): Promise<void>;
1678
+ }
1679
+
1680
+ /**
1681
+ * The target type where the notification will be sent to.
1682
+ *
1683
+ * @remarks
1684
+ * - "Channel" means to a team channel. (By default, notification to a team will be sent to its "General" channel.)
1685
+ * - "Group" means to a group chat.
1686
+ * - "Person" means to a personal chat.
1687
+ */
1688
+ export declare enum NotificationTargetType {
1689
+ /**
1690
+ * The notification will be sent to a team channel.
1691
+ * (By default, notification to a team will be sent to its "General" channel.)
1692
+ */
1693
+ Channel = "Channel",
1694
+ /**
1695
+ * The notification will be sent to a group chat.
1696
+ */
1697
+ Group = "Group",
1698
+ /**
1699
+ * The notification will be sent to a personal chat.
1700
+ */
1701
+ Person = "Person"
1702
+ }
1703
+
1704
+ /**
1705
+ * Authentication configuration for OnBehalfOfCredential used in node environment
1706
+ */
1707
+ export declare type OnBehalfOfCredentialAuthConfig = {
1708
+ /**
1709
+ * Hostname of AAD authority.
1710
+ */
1711
+ authorityHost: string;
1712
+ /**
1713
+ * The client (application) ID of an App Registration in the tenant
1714
+ */
1715
+ clientId: string;
1716
+ /**
1717
+ * AAD tenant id
1718
+ *
1719
+ * @readonly
1720
+ */
1721
+ tenantId: string;
1722
+ } & ({
1723
+ /**
1724
+ * Secret string that the application uses when requesting a token. Only used in confidential client applications. Can be created in the Azure app registration portal.
1725
+ */
1726
+ clientSecret: string;
1727
+ certificateContent?: never;
1728
+ } | {
1729
+ clientSecret?: never;
1730
+ /**
1731
+ * The content of a PEM-encoded public/private key certificate.
1732
+ *
1733
+ * @readonly
1734
+ */
1735
+ certificateContent: string;
1736
+ });
1737
+
1738
+ /**
1739
+ * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
1740
+ *
1741
+ * @example
1742
+ * ```typescript
1743
+ * const credential = new OnBehalfOfUserCredential(ssoToken);
1744
+ * ```
1745
+ *
1746
+ * @remarks
1747
+ * Can only be used in server side.
1748
+ */
1749
+ export declare class OnBehalfOfUserCredential implements TokenCredential {
1750
+ private msalClient;
1751
+ private ssoToken;
1752
+ /**
1753
+ * Constructor of OnBehalfOfUserCredential
1754
+ *
1755
+ * @remarks
1756
+ * Only works in in server side.
1757
+ *
1758
+ * @param {string} ssoToken - User token provided by Teams SSO feature.
1759
+ * @param {OnBehalfOfCredentialAuthConfig} config - The authentication configuration.
1760
+ *
1761
+ * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
1762
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1763
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1764
+ */
1765
+ constructor(ssoToken: string, config: OnBehalfOfCredentialAuthConfig);
1766
+ /**
1767
+ * Constructor of OnBehalfOfUserCredential
1768
+ *
1769
+ * @remarks
1770
+ * Only works in in server side.
1771
+ *
1772
+ * @param {string} ssoToken - User token provided by Teams SSO feature.
1773
+ * @param {AuthenticationConfiguration} config - The authentication configuration. Use environment variables if not provided.
1774
+ *
1775
+ * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
1776
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1777
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1778
+ */
1779
+ constructor(ssoToken: string, config: AuthenticationConfiguration);
1780
+ /**
1781
+ * Get access token from credential.
1782
+ *
1783
+ * @example
1784
+ * ```typescript
1785
+ * await credential.getToken([]) // Get SSO token using empty string array
1786
+ * await credential.getToken("") // Get SSO token using empty string
1787
+ * await credential.getToken([".default"]) // Get Graph access token with default scope using string array
1788
+ * await credential.getToken(".default") // Get Graph access token with default scope using string
1789
+ * await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
1790
+ * await credential.getToken("User.Read") // Get Graph access token for single scope using string
1791
+ * await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
1792
+ * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
1793
+ * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
1794
+ * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
1795
+ * ```
1796
+ *
1797
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1798
+ * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
1799
+ *
1800
+ * @throws {@link ErrorCode|InternalError} when failed to acquire access token on behalf of user with unknown error.
1801
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1802
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1803
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
1804
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1805
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1806
+ *
1807
+ * @returns Access token with expected scopes.
1808
+ *
1809
+ * @remarks
1810
+ * If scopes is empty string or array, it returns SSO token.
1811
+ * If scopes is non-empty, it returns access token for target scope.
1812
+ */
1813
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1814
+ /**
1815
+ * Get basic user info from SSO token.
1816
+ *
1817
+ * @example
1818
+ * ```typescript
1819
+ * const currentUser = getUserInfo();
1820
+ * ```
1821
+ *
1822
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1823
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1824
+ *
1825
+ * @returns Basic user info with user displayName, objectId and preferredUserName.
1826
+ */
1827
+ getUserInfo(): UserInfo;
1828
+ private generateAuthServerError;
1829
+ }
1830
+
1831
+ /**
1832
+ * The search scope when calling {@link NotificationBot.findMember} and {@link NotificationBot.findAllMembers}.
1833
+ * The search scope is a flagged enum and it can be combined with `|`.
1834
+ * For example, to search from personal chat and group chat, use `SearchScope.Person | SearchScope.Group`.
1835
+ */
1836
+ export declare enum SearchScope {
1837
+ /**
1838
+ * Search members from the installations in personal chat only.
1839
+ */
1840
+ Person = 1,
1841
+ /**
1842
+ * Search members from the installations in group chat only.
1843
+ */
1844
+ Group = 2,
1845
+ /**
1846
+ * Search members from the installations in Teams channel only.
1847
+ */
1848
+ Channel = 4,
1849
+ /**
1850
+ * Search members from all installations including personal chat, group chat and Teams channel.
1851
+ */
1852
+ All = 7
1853
+ }
1854
+
1855
+ /**
1856
+ * Send an adaptive card message to a notification target.
1857
+ *
1858
+ * @param target - the notification target.
1859
+ * @param card - the adaptive card raw JSON.
1860
+ * @param onError - an optional error handler that can catch exceptions during adaptive card sending.
1861
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
1862
+ * @returns the response of sending adaptive card message.
1863
+ */
1864
+ export declare function sendAdaptiveCard(target: NotificationTarget, card: unknown, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
1865
+
1866
+ /**
1867
+ * Send a plain text message to a notification target.
1868
+ *
1869
+ * @param target - the notification target.
1870
+ * @param text - the plain text message.
1871
+ * @param onError - an optional error handler that can catch exceptions during message sending.
1872
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
1873
+ * @returns the response of sending message.
1874
+ */
1875
+ export declare function sendMessage(target: NotificationTarget, text: string, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
1876
+
1877
+ /**
1878
+ * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
1879
+ *
1880
+ * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
1881
+ *
1882
+ * @example
1883
+ * ```typescript
1884
+ * setLogFunction((level: LogLevel, message: string) => {
1885
+ * if (level === LogLevel.Error) {
1886
+ * console.log(message);
1887
+ * }
1888
+ * });
1889
+ * ```
1890
+ */
1891
+ export declare function setLogFunction(logFunction?: LogFunction): void;
1892
+
1893
+ /**
1894
+ * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
1895
+ *
1896
+ * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
1897
+ *
1898
+ * @example
1899
+ * ```typescript
1900
+ * setLogger({
1901
+ * verbose: console.debug,
1902
+ * info: console.info,
1903
+ * warn: console.warn,
1904
+ * error: console.error,
1905
+ * });
1906
+ * ```
1907
+ */
1908
+ export declare function setLogger(logger?: Logger): void;
1909
+
1910
+ /**
1911
+ * Update log level helper.
1912
+ *
1913
+ * @param { LogLevel } level - log level in configuration
1914
+ */
1915
+ export declare function setLogLevel(level: LogLevel): void;
1916
+
1917
+ /**
1918
+ * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1919
+ * - Personal chat
1920
+ * - Group chat
1921
+ * - Team (by default the `General` channel)
1922
+ *
1923
+ * @remarks
1924
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1925
+ */
1926
+ export declare class TeamsBotInstallation implements NotificationTarget {
1927
+ /**
1928
+ * The bound `BotFrameworkAdapter`.
1929
+ */
1930
+ readonly adapter: BotFrameworkAdapter;
1931
+ /**
1932
+ * The bound `ConversationReference`.
1933
+ */
1934
+ readonly conversationReference: Partial<ConversationReference>;
1935
+ /**
1936
+ * Notification target type.
1937
+ *
1938
+ * @remarks
1939
+ * - "Channel" means bot is installed into a team and notification will be sent to its "General" channel.
1940
+ * - "Group" means bot is installed into a group chat.
1941
+ * - "Person" means bot is installed into a personal scope and notification will be sent to personal chat.
1942
+ */
1943
+ readonly type?: NotificationTargetType;
1944
+ /**
1945
+ * Constructor
1946
+ *
1947
+ * @remarks
1948
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1949
+ *
1950
+ * @param adapter - the bound `BotFrameworkAdapter`.
1951
+ * @param conversationReference - the bound `ConversationReference`.
1952
+ */
1953
+ constructor(adapter: BotFrameworkAdapter, conversationReference: Partial<ConversationReference>);
1954
+ /**
1955
+ * Send a plain text message.
1956
+ *
1957
+ * @param text - the plain text message.
1958
+ * @param onError - an optional error handler that can catch exceptions during message sending.
1959
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
1960
+ * @returns the response of sending message.
1961
+ */
1962
+ sendMessage(text: string, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
1963
+ /**
1964
+ * Send an adaptive card message.
1965
+ *
1966
+ * @param card - the adaptive card raw JSON.
1967
+ * @param onError - an optional error handler that can catch exceptions during adaptive card sending.
1968
+ * If not defined, error will be handled by `BotAdapter.onTurnError`.
1969
+ * @returns the response of sending adaptive card message.
1970
+ */
1971
+ sendAdaptiveCard(card: unknown, onError?: (context: TurnContext, error: Error) => Promise<void>): Promise<MessageResponse>;
1972
+ /**
1973
+ * Get channels from this bot installation.
1974
+ *
1975
+ * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1976
+ */
1977
+ channels(): Promise<Channel[]>;
1978
+ /**
1979
+ * Get members from this bot installation.
1980
+ *
1981
+ * @returns an array of members from where the bot is installed.
1982
+ */
1983
+ members(): Promise<Member[]>;
1984
+ /**
1985
+ * Get team details from this bot installation
1986
+ *
1987
+ * @returns the team details if bot is installed into a team, otherwise returns undefined.
1988
+ */
1989
+ getTeamDetails(): Promise<TeamDetails | undefined>;
1990
+ }
1991
+
1992
+ /**
1993
+ * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
1994
+ * help receive oauth token, asks the user to consent if needed.
1995
+ *
1996
+ * @remarks
1997
+ * The prompt will attempt to retrieve the users current token of the desired scopes and store it in
1998
+ * the token store.
1999
+ *
2000
+ * User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO):
2001
+ * https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots
2002
+ *
2003
+ * @example
2004
+ * When used with your bots `DialogSet` you can simply add a new instance of the prompt as a named
2005
+ * dialog using `DialogSet.add()`. You can then start the prompt from a waterfall step using either
2006
+ * `DialogContext.beginDialog()` or `DialogContext.prompt()`. The user will be prompted to sign in as
2007
+ * needed and their access token will be passed as an argument to the callers next waterfall step:
2008
+ *
2009
+ * ```JavaScript
2010
+ * const { ConversationState, MemoryStorage } = require('botbuilder');
2011
+ * const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
2012
+ * const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');
2013
+ *
2014
+ * const convoState = new ConversationState(new MemoryStorage());
2015
+ * const dialogState = convoState.createProperty('dialogState');
2016
+ * const dialogs = new DialogSet(dialogState);
2017
+ *
2018
+ * dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
2019
+ * scopes: ["User.Read"],
2020
+ * }));
2021
+ *
2022
+ * dialogs.add(new WaterfallDialog('taskNeedingLogin', [
2023
+ * async (step) => {
2024
+ * return await step.beginDialog('TeamsBotSsoPrompt');
2025
+ * },
2026
+ * async (step) => {
2027
+ * const token = step.result;
2028
+ * if (token) {
2029
+ *
2030
+ * // ... continue with task needing access token ...
2031
+ *
2032
+ * } else {
2033
+ * await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
2034
+ * return await step.endDialog();
2035
+ * }
2036
+ * }
2037
+ * ]));
2038
+ * ```
2039
+ */
2040
+ export declare class TeamsBotSsoPrompt extends Dialog {
2041
+ private authConfig;
2042
+ private initiateLoginEndpoint;
2043
+ private settings;
2044
+ /**
2045
+ * Constructor of TeamsBotSsoPrompt.
2046
+ *
2047
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth
2048
+ * @param {string} dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
2049
+ * @param {TeamsBotSsoPromptSettings} settings Settings used to configure the prompt.
2050
+ *
2051
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
2052
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
2053
+ */
2054
+ constructor(teamsfx: TeamsFx, dialogId: string, settings: TeamsBotSsoPromptSettings);
2055
+ /**
2056
+ * Constructor of TeamsBotSsoPrompt.
2057
+ *
2058
+ * @param {OnBehalfOfCredentialAuthConfig} authConfig - Used to provide configuration and auth
2059
+ * @param {string} initiateLoginEndpoint - Login URL for Teams to redirect to
2060
+ * @param {string} dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
2061
+ * @param {TeamsBotSsoPromptSettings} settings Settings used to configure the prompt.
2062
+ *
2063
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
2064
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
2065
+ */
2066
+ constructor(authConfig: OnBehalfOfCredentialAuthConfig, initiateLoginEndpoint: string, dialogId: string, settings: TeamsBotSsoPromptSettings);
2067
+ /**
2068
+ * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
2069
+ * @remarks
2070
+ * If the task is successful, the result indicates whether the prompt is still
2071
+ * active after the turn has been processed by the prompt.
2072
+ *
2073
+ * @param dc The DialogContext for the current turn of the conversation.
2074
+ *
2075
+ * @throws {@link ErrorCode|InvalidParameter} when timeout property in teams bot sso prompt settings is not number or is not positive.
2076
+ * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
2077
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
2078
+ *
2079
+ * @returns A `Promise` representing the asynchronous operation.
2080
+ */
2081
+ beginDialog(dc: DialogContext): Promise<DialogTurnResult>;
2082
+ /**
2083
+ * Called when a prompt dialog is the active dialog and the user replied with a new activity.
2084
+ *
2085
+ * @remarks
2086
+ * If the task is successful, the result indicates whether the dialog is still
2087
+ * active after the turn has been processed by the dialog.
2088
+ * The prompt generally continues to receive the user's replies until it accepts the
2089
+ * user's reply as valid input for the prompt.
2090
+ *
2091
+ * @param dc The DialogContext for the current turn of the conversation.
2092
+ *
2093
+ * @returns A `Promise` representing the asynchronous operation.
2094
+ *
2095
+ * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
2096
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
2097
+ */
2098
+ continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
2099
+ private loadAndValidateConfig;
2100
+ /**
2101
+ * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
2102
+ * @param dc dialog context
2103
+ * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
2104
+ * @internal
2105
+ */
2106
+ private ensureMsTeamsChannel;
2107
+ /**
2108
+ * Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
2109
+ * For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
2110
+ *
2111
+ * @internal
2112
+ */
2113
+ private sendOAuthCardAsync;
2114
+ /**
2115
+ * Get sign in resource.
2116
+ *
2117
+ * @throws {@link ErrorCode|InvalidConfiguration} if client id, tenant id or initiate login endpoint is not found in config.
2118
+ *
2119
+ * @internal
2120
+ */
2121
+ private getSignInResource;
2122
+ /**
2123
+ * @internal
2124
+ */
2125
+ private recognizeToken;
2126
+ /**
2127
+ * @internal
2128
+ */
2129
+ private getTokenExchangeInvokeResponse;
2130
+ /**
2131
+ * @internal
2132
+ */
2133
+ private isTeamsVerificationInvoke;
2134
+ /**
2135
+ * @internal
2136
+ */
2137
+ private isTokenExchangeRequestInvoke;
2138
+ /**
2139
+ * @internal
2140
+ */
2141
+ private isTokenExchangeRequest;
2142
+ }
2143
+
2144
+ /**
2145
+ * Settings used to configure an TeamsBotSsoPrompt instance.
2146
+ */
2147
+ export declare interface TeamsBotSsoPromptSettings {
2148
+ /**
2149
+ * The array of strings that declare the desired permissions and the resources requested.
2150
+ */
2151
+ scopes: string[];
2152
+ /**
2153
+ * (Optional) number of milliseconds the prompt will wait for the user to authenticate.
2154
+ * Defaults to a value `900,000` (15 minutes.)
2155
+ */
2156
+ timeout?: number;
2157
+ /**
2158
+ * (Optional) value indicating whether the TeamsBotSsoPrompt should end upon receiving an
2159
+ * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
2160
+ * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
2161
+ * Defaults to value `true`
2162
+ */
2163
+ endOnInvalidMessage?: boolean;
2164
+ }
2165
+
2166
+ /**
2167
+ * Token response provided by Teams Bot SSO prompt
2168
+ */
2169
+ export declare interface TeamsBotSsoPromptTokenResponse extends TokenResponse {
2170
+ /**
2171
+ * SSO token for user
2172
+ */
2173
+ ssoToken: string;
2174
+ /**
2175
+ * Expire time of SSO token
2176
+ */
2177
+ ssoTokenExpiration: string;
2178
+ }
2179
+
2180
+ /**
2181
+ * A class providing credential and configuration.
2182
+ */
2183
+ export declare class TeamsFx implements TeamsFxConfiguration {
2184
+ private configuration;
2185
+ private oboUserCredential?;
2186
+ private appCredential?;
2187
+ private identityType;
2188
+ /**
2189
+ * Constructor of TeamsFx
2190
+ *
2191
+ * @param {IdentityType} identityType - Choose user or app identity
2192
+ * @param customConfig - key/value pairs of customized configuration that overrides default ones.
2193
+ *
2194
+ * @throws {@link ErrorCode|IdentityTypeNotSupported} when setting app identity in browser.
2195
+ */
2196
+ constructor(identityType?: IdentityType, customConfig?: Record<string, string> | AuthenticationConfiguration);
2197
+ /**
2198
+ * Identity type set by user.
2199
+ *
2200
+ * @returns identity type.
2201
+ */
2202
+ getIdentityType(): IdentityType;
2203
+ /**
2204
+ * Credential instance according to identity type choice.
2205
+ *
2206
+ * @remarks If user identity is chose, will return {@link TeamsUserCredential}
2207
+ * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
2208
+ * identity is chose, will return {@link AppCredential}.
2209
+ *
2210
+ * @returns instance implements TokenCredential interface.
2211
+ */
2212
+ getCredential(): TokenCredential;
2213
+ /**
2214
+ * Get user information.
2215
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
2216
+ * @returns UserInfo object.
2217
+ */
2218
+ getUserInfo(resources?: string[]): Promise<UserInfo>;
2219
+ /**
2220
+ * Popup login page to get user's access token with specific scopes.
2221
+ *
2222
+ * @remarks
2223
+ * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
2224
+ *
2225
+ * @example
2226
+ * ```typescript
2227
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
2228
+ * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
2229
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
2230
+ * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
2231
+ * ```
2232
+ * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
2233
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
2234
+ *
2235
+ * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
2236
+ * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
2237
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
2238
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
2239
+ */
2240
+ login(scopes: string | string[], resources?: string[]): Promise<void>;
2241
+ /**
2242
+ * Set SSO token when using user identity in NodeJS.
2243
+ * @param {string} ssoToken - used for on behalf of user flow.
2244
+ * @returns self instance.
2245
+ */
2246
+ setSsoToken(ssoToken: string): TeamsFx;
2247
+ /**
2248
+ * Usually used by service plugins to retrieve specific config
2249
+ * @param {string} key - configuration key.
2250
+ * @returns value in configuration.
2251
+ */
2252
+ getConfig(key: string): string;
2253
+ /**
2254
+ * Check the value of specific key.
2255
+ * @param {string} key - configuration key.
2256
+ * @returns true if corresponding value is not empty string.
2257
+ */
2258
+ hasConfig(key: string): boolean;
2259
+ /**
2260
+ * Get all configurations.
2261
+ * @returns key value mappings.
2262
+ */
2263
+ getConfigs(): Record<string, string>;
2264
+ /**
2265
+ * Load configuration from environment variables.
2266
+ */
2267
+ private loadFromEnv;
2268
+ }
2269
+
2270
+ /**
2271
+ * Interface for adaptive card action handler that can process card action invoke and return a response.
2272
+ */
2273
+ export declare interface TeamsFxAdaptiveCardActionHandler {
2274
+ /**
2275
+ * The verb defined in adaptive card action that can trigger this handler.
2276
+ * The verb string here is case-insensitive.
2277
+ */
2278
+ triggerVerb: string;
2279
+ /**
2280
+ * Specify the behavior for how the card response will be sent in Teams conversation.
2281
+ * The default value is `AdaptiveCardResponse.ReplaceForInteractor`, which means the card
2282
+ * response will replace the current one only for the interactor.
2283
+ */
2284
+ adaptiveCardResponse?: AdaptiveCardResponse;
2285
+ /**
2286
+ * The handler function that will be invoked when the action is fired.
2287
+ * @param context The turn context.
2288
+ * @param actionData The contextual data that associated with the action.
2289
+ *
2290
+ * @returns A `Promise` representing a invoke response for the adaptive card invoke action.
2291
+ * You can use the `InvokeResponseFactory` utility class to create an invoke response from
2292
+ * - A text message:
2293
+ * ```typescript
2294
+ * return InvokeResponseFactory.textMessage("Action is processed successfully!");
2295
+ * ```
2296
+ * - An adaptive card:
2297
+ * ```typescript
2298
+ * const responseCard = AdaptiveCards.declare(helloWorldCard).render(actionData);
2299
+ return InvokeResponseFactory.adaptiveCard(responseCard);
2300
+ * ```
2301
+ * - An error response:
2302
+ * ```typescript
2303
+ * return InvokeResponseFactory.errorResponse(InvokeResponseErrorCode.BadRequest, "Invalid request");
2304
+ * ```
2305
+ *
2306
+ * @remark For more details about the invoke response format, refer to https://docs.microsoft.com/en-us/adaptive-cards/authoring-cards/universal-action-model#response-format.
2307
+ */
2308
+ handleActionInvoked(context: TurnContext, actionData: any): Promise<InvokeResponse>;
2309
+ }
2310
+
2311
+ /**
2312
+ * Interface for a command handler that can process command to a TeamsFx bot and return a response.
2313
+ */
2314
+ export declare interface TeamsFxBotCommandHandler {
2315
+ /**
2316
+ * The string or regular expression patterns that can trigger this handler.
2317
+ */
2318
+ triggerPatterns: TriggerPatterns;
2319
+ /**
2320
+ * Handles a bot command received activity.
2321
+ *
2322
+ * @param context The bot context.
2323
+ * @param message The command message the user types from Teams.
2324
+ * @returns A `Promise` representing an activity or text to send as the command response.
2325
+ * Or no return value if developers want to send the response activity by themselves in this method.
2326
+ */
2327
+ handleCommandReceived(context: TurnContext, message: CommandMessage): Promise<string | Partial<Activity> | void>;
2328
+ }
2329
+
2330
+ /**
2331
+ * Interface for a command handler that can process sso command to a TeamsFx bot and return a response.
2332
+ */
2333
+ export declare interface TeamsFxBotSsoCommandHandler {
2334
+ /**
2335
+ * The string or regular expression patterns that can trigger this handler.
2336
+ */
2337
+ triggerPatterns: TriggerPatterns;
2338
+ /**
2339
+ * Handles a bot command received activity.
2340
+ *
2341
+ * @param context The bot context.
2342
+ * @param message The command message the user types from Teams.
2343
+ * @param tokenResponse The tokenResponse which contains sso token that can be used to exchange access token for the bot.
2344
+ * @returns A `Promise` representing an activity or text to send as the command response.
2345
+ * Or no return value if developers want to send the response activity by themselves in this method.
2346
+ */
2347
+ handleCommandReceived(context: TurnContext, message: CommandMessage, tokenResponse: TeamsBotSsoPromptTokenResponse): Promise<string | Partial<Activity> | void>;
2348
+ }
2349
+
2350
+ /**
2351
+ * TeamsFx interface that provides credential and configuration.
2352
+ */
2353
+ declare interface TeamsFxConfiguration {
2354
+ /**
2355
+ * Identity type set by user.
2356
+ *
2357
+ * @returns identity type.
2358
+ */
2359
+ getIdentityType(): IdentityType;
2360
+ /**
2361
+ * Credential instance according to identity type choice.
2362
+ *
2363
+ * @remarks If user identity is chose, will return {@link TeamsUserCredential}
2364
+ * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
2365
+ * identity is chose, will return {@link AppCredential}.
2366
+ *
2367
+ * @returns instance implements TokenCredential interface.
2368
+ */
2369
+ getCredential(): TokenCredential;
2370
+ /**
2371
+ * Get user information.
2372
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
2373
+ * @returns UserInfo object.
2374
+ */
2375
+ getUserInfo(resources?: string[]): Promise<UserInfo>;
2376
+ /**
2377
+ * Popup login page to get user's access token with specific scopes.
2378
+ *
2379
+ * @remarks
2380
+ * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
2381
+ *
2382
+ * @example
2383
+ * ```typescript
2384
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
2385
+ * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
2386
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
2387
+ * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
2388
+ * ```
2389
+ * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
2390
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
2391
+ *
2392
+ * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
2393
+ * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
2394
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
2395
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
2396
+ */
2397
+ login(scopes: string | string[], resources?: string[]): Promise<void>;
2398
+ /**
2399
+ * Set SSO token when using user identity in NodeJS.
2400
+ * @param {string} ssoToken - used for on behalf of user flow.
2401
+ * @returns self instance.
2402
+ */
2403
+ setSsoToken(ssoToken: string): TeamsFxConfiguration;
2404
+ /**
2405
+ * Usually used by service plugins to retrieve specific config
2406
+ * @param {string} key - configuration key.
2407
+ * @returns value in configuration.
2408
+ */
2409
+ getConfig(key: string): string;
2410
+ /**
2411
+ * Check the value of specific key.
2412
+ * @param {string} key - configuration key.
2413
+ * @returns true if corresponding value is not empty string.
2414
+ */
2415
+ hasConfig(key: string): boolean;
2416
+ /**
2417
+ * Get all configurations.
2418
+ * @returns key value mappings.
2419
+ */
2420
+ getConfigs(): Record<string, string>;
2421
+ }
2422
+
2423
+ /**
2424
+ * Represent Teams current user's identity, and it is used within Teams client applications.
2425
+ *
2426
+ * @remarks
2427
+ * Can only be used within Teams.
2428
+ */
2429
+ export declare class TeamsUserCredential implements TokenCredential {
2430
+ /**
2431
+ * Constructor of TeamsUserCredential.
2432
+ * @remarks
2433
+ * Can only be used within Teams.
2434
+ */
2435
+ constructor(authConfig: TeamsUserCredentialAuthConfig);
2436
+ constructor(authConfig: AuthenticationConfiguration);
2437
+ /**
2438
+ * Popup login page to get user's access token with specific scopes.
2439
+ *
2440
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
2441
+ *
2442
+ * @remarks
2443
+ * Can only be used within Teams.
2444
+ */
2445
+ login(scopes: string | string[], resources?: string[]): Promise<void>;
2446
+ /**
2447
+ * Get access token from credential.
2448
+ * @remarks
2449
+ * Can only be used within Teams.
2450
+ */
2451
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
2452
+ /**
2453
+ * Get basic user info from SSO token
2454
+ *
2455
+ * @param {string[]} resources - The optional list of resources for full trust Teams apps.
2456
+ *
2457
+ * @remarks
2458
+ * Can only be used within Teams.
2459
+ */
2460
+ getUserInfo(resources?: string[]): Promise<UserInfo>;
2461
+ }
2462
+
2463
+ /**
2464
+ * Authentication configuration for TeamsUserCredential used in browser environment
2465
+ */
2466
+ export declare type TeamsUserCredentialAuthConfig = {
2467
+ /**
2468
+ * Login page for Teams to redirect to.
2469
+ */
2470
+ initiateLoginEndpoint: string;
2471
+ /**
2472
+ * The client (application) ID of an App Registration in the tenant
2473
+ */
2474
+ clientId: string;
2475
+ };
2476
+
2477
+ /**
2478
+ * The trigger pattern used to trigger a {@link TeamsFxBotCommandHandler} instance.
2479
+ */
2480
+ export declare type TriggerPatterns = string | RegExp | (string | RegExp)[];
2481
+
2482
+ /**
2483
+ * UserInfo with user displayName, objectId and preferredUserName.
2484
+ */
2485
+ export declare interface UserInfo {
2486
+ /**
2487
+ * User Display Name.
2488
+ *
2489
+ * @readonly
2490
+ */
2491
+ displayName: string;
2492
+ /**
2493
+ * User unique reference within the Azure Active Directory domain.
2494
+ *
2495
+ * @readonly
2496
+ */
2497
+ objectId: string;
2498
+ /**
2499
+ * User tenant ID.
2500
+ *
2501
+ * @readonly
2502
+ */
2503
+ tenantId: string;
2504
+ /**
2505
+ * Usually be the email address.
2506
+ *
2507
+ * @readonly
2508
+ */
2509
+ preferredUserName: string;
2510
+ }
1962
2511
 
1963
- export { }
2512
+ export { }