@microsoft/teamsfx 0.6.2-rc.0 → 0.6.3-alpha.81c48cbfc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,35 @@
1
+ /// <reference types="node" />
2
+
1
3
  import { AccessToken } from '@azure/identity';
4
+ import { Activity } from 'botbuilder-core';
5
+ import { Activity as Activity_2 } from 'botbuilder';
6
+ import { Attachment } from 'botbuilder';
2
7
  import { AuthenticationProvider } from '@microsoft/microsoft-graph-client';
8
+ import { AxiosInstance } from 'axios';
9
+ import { AxiosRequestConfig } from 'axios';
10
+ import { BotFrameworkAdapter } from 'botbuilder';
11
+ import { CardAction } from 'botbuilder';
12
+ import { CardImage } from 'botbuilder';
13
+ import { ChannelInfo } from 'botbuilder';
3
14
  import { Client } from '@microsoft/microsoft-graph-client';
4
15
  import { ConnectionConfig } from 'tedious';
16
+ import { ConversationReference } from 'botbuilder';
5
17
  import { Dialog } from 'botbuilder-dialogs';
6
18
  import { DialogContext } from 'botbuilder-dialogs';
7
19
  import { DialogTurnResult } from 'botbuilder-dialogs';
8
20
  import { GetTokenOptions } from '@azure/identity';
21
+ import { HeroCard } from 'botbuilder';
22
+ import { O365ConnectorCard } from 'botbuilder';
23
+ import { ReceiptCard } from 'botbuilder';
24
+ import { SecureContextOptions } from 'tls';
25
+ import { TeamsChannelAccount } from 'botbuilder';
26
+ import { ThumbnailCard } from 'botbuilder';
9
27
  import { TokenCredential } from '@azure/identity';
10
28
  import { TokenResponse } from 'botframework-schema';
29
+ import { TurnContext } from 'botbuilder-core';
30
+ import { TurnContext as TurnContext_2 } from 'botbuilder';
31
+ import { WebRequest } from 'botbuilder';
32
+ import { WebResponse } from 'botbuilder';
11
33
 
12
34
  /**
13
35
  * Represent Microsoft 365 tenant identity, and it is usually used when user is not involved like time-triggered automation job.
@@ -124,835 +146,1713 @@ export declare interface AuthenticationConfiguration {
124
146
  }
125
147
 
126
148
  /**
127
- * Get Microsoft graph client.
149
+ * Defines method that injects authentication info to http requests
128
150
  *
129
- * @example
130
- * Get Microsoft graph client by TokenCredential
131
- * ```typescript
132
- * // Sso token example (Azure Function)
133
- * const ssoToken = "YOUR_TOKEN_STRING";
134
- * const options = {"AAD_APP_ID", "AAD_APP_SECRET"};
135
- * const credential = new OnBehalfOfAADUserCredential(ssoToken, options);
136
- * const graphClient = await createMicrosoftGraphClient(credential);
137
- * const profile = await graphClient.api("/me").get();
138
- *
139
- * // TeamsBotSsoPrompt example (Bot Application)
140
- * const requiredScopes = ["User.Read"];
141
- * const config: Configuration = {
142
- * loginUrl: loginUrl,
143
- * clientId: clientId,
144
- * clientSecret: clientSecret,
145
- * tenantId: tenantId
146
- * };
147
- * const prompt = new TeamsBotSsoPrompt(dialogId, {
148
- * config: config
149
- * scopes: '["User.Read"],
150
- * });
151
- * this.addDialog(prompt);
152
- *
153
- * const oboCredential = new OnBehalfOfAADUserCredential(
154
- * getUserId(dialogContext),
155
- * {
156
- * clientId: "AAD_APP_ID",
157
- * clientSecret: "AAD_APP_SECRET"
158
- * });
159
- * try {
160
- * const graphClient = await createMicrosoftGraphClient(credential);
161
- * const profile = await graphClient.api("/me").get();
162
- * } catch (e) {
163
- * dialogContext.beginDialog(dialogId);
164
- * return Dialog.endOfTurn();
165
- * }
166
- * ```
167
- *
168
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
169
- * @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
170
- *
171
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
172
- *
173
- * @returns Graph client with specified scopes.
174
- *
175
- * @beta
176
- */
177
- export declare function createMicrosoftGraphClient(teamsfx: TeamsFxConfiguration, scopes?: string | string[]): Client;
178
-
179
- /**
180
- * Error code to trace the error types.
181
151
  * @beta
182
152
  */
183
- export declare enum ErrorCode {
184
- /**
185
- * Invalid parameter error.
186
- */
187
- InvalidParameter = "InvalidParameter",
188
- /**
189
- * Invalid configuration error.
190
- */
191
- InvalidConfiguration = "InvalidConfiguration",
153
+ export declare interface AuthProvider {
192
154
  /**
193
- * Invalid certificate error.
194
- */
195
- InvalidCertificate = "InvalidCertificate",
196
- /**
197
- * Internal error.
198
- */
199
- InternalError = "InternalError",
200
- /**
201
- * Channel is not supported error.
202
- */
203
- ChannelNotSupported = "ChannelNotSupported",
204
- /**
205
- * Runtime is not supported error.
206
- */
207
- RuntimeNotSupported = "RuntimeNotSupported",
208
- /**
209
- * User failed to finish the AAD consent flow failed.
210
- */
211
- ConsentFailed = "ConsentFailed",
212
- /**
213
- * The user or administrator has not consented to use the application error.
214
- */
215
- UiRequiredError = "UiRequiredError",
216
- /**
217
- * Token is not within its valid time range error.
218
- */
219
- TokenExpiredError = "TokenExpiredError",
220
- /**
221
- * Call service (AAD or simple authentication server) failed.
222
- */
223
- ServiceError = "ServiceError",
224
- /**
225
- * Operation failed.
226
- */
227
- FailedOperation = "FailedOperation",
228
- /**
229
- * Invalid response error.
230
- */
231
- InvalidResponse = "InvalidResponse",
232
- /**
233
- * Identity type error.
155
+ * Adds authentication info to http requests
156
+ *
157
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
158
+ * Refer https://axios-http.com/docs/req_config for detailed document.
159
+ *
160
+ * @beta
234
161
  */
235
- IdentityTypeNotSupported = "IdentityTypeNotSupported"
162
+ AddAuthenticationInfo: (config: AxiosRequestConfig) => Promise<AxiosRequestConfig>;
236
163
  }
237
164
 
238
165
  /**
239
- * Error class with code and message thrown by the SDK.
166
+ * Provider that handles Bearer Token authentication
240
167
  *
241
168
  * @beta
242
169
  */
243
- export declare class ErrorWithCode extends Error {
170
+ export declare class BearerTokenAuthProvider implements AuthProvider {
171
+ private getToken;
244
172
  /**
245
- * Error code
173
+ * @param getToken Function that returns the content of bearer token used in http request
246
174
  *
247
- * @readonly
175
+ * @beta
248
176
  */
249
- code: string | undefined;
177
+ constructor(getToken: () => Promise<string>);
250
178
  /**
251
- * Constructor of ErrorWithCode.
179
+ * Adds authentication info to http requests
252
180
  *
253
- * @param {string} message - error message.
254
- * @param {ErrorCode} code - error code.
181
+ * @param config - Contains all the request information and can be updated to include extra authentication info.
182
+ * Refer https://axios-http.com/docs/req_config for detailed document.
255
183
  *
256
184
  * @beta
257
185
  */
258
- constructor(message?: string, code?: ErrorCode);
259
- }
260
-
261
- /**
262
- * Get log level.
263
- *
264
- * @returns Log level
265
- *
266
- * @beta
267
- */
268
- export declare function getLogLevel(): LogLevel | undefined;
269
-
270
- /**
271
- * Generate connection configuration consumed by tedious.
272
- *
273
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth
274
- * @param { string? } databaseName - specify database name to override default one if there are multiple databases.
275
- *
276
- * @returns Connection configuration of tedious for the SQL.
277
- *
278
- * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
279
- * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
280
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
281
- *
282
- * @beta
283
- */
284
- export declare function getTediousConnectionConfig(teamsfx: TeamsFx, databaseName?: string): Promise<ConnectionConfig>;
285
-
286
- /**
287
- * Identity type to use in authentication.
288
- *
289
- * @beta
290
- */
291
- export declare enum IdentityType {
292
- /**
293
- * Represents the current user of Teams.
294
- */
295
- User = "User",
296
- /**
297
- * Represents the application itself.
298
- */
299
- App = "Application"
300
- }
301
-
302
- /**
303
- * Log function for customized logging.
304
- *
305
- * @beta
306
- */
307
- export declare type LogFunction = (level: LogLevel, message: string) => void;
308
-
309
- /**
310
- * Interface for customized logger.
311
- * @beta
312
- */
313
- export declare interface Logger {
314
- /**
315
- * Writes to error level logging or lower.
316
- */
317
- error(message: string): void;
318
- /**
319
- * Writes to warning level logging or lower.
320
- */
321
- warn(message: string): void;
322
- /**
323
- * Writes to info level logging or lower.
324
- */
325
- info(message: string): void;
326
- /**
327
- * Writes to verbose level logging.
328
- */
329
- verbose(message: string): void;
186
+ AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
330
187
  }
331
188
 
332
189
  /**
333
- * Log level.
190
+ * Provider that handles Certificate authentication
334
191
  *
335
192
  * @beta
336
193
  */
337
- export declare enum LogLevel {
338
- /**
339
- * Show verbose, information, warning and error message.
340
- */
341
- Verbose = 0,
342
- /**
343
- * Show information, warning and error message.
344
- */
345
- Info = 1,
194
+ export declare class CertificateAuthProvider implements AuthProvider {
195
+ private certOption;
346
196
  /**
347
- * Show warning and error message.
348
- */
349
- Warn = 2,
350
- /**
351
- * Show error message.
352
- */
353
- Error = 3
354
- }
355
-
356
- /**
357
- * Microsoft Graph auth provider for Teams Framework
358
- *
359
- * @beta
360
- */
361
- export declare class MsGraphAuthProvider implements AuthenticationProvider {
362
- private teamsfx;
363
- private scopes;
364
- /**
365
- * Constructor of MsGraphAuthProvider.
366
- *
367
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
368
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
369
- *
370
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
371
197
  *
372
- * @returns An instance of MsGraphAuthProvider.
198
+ * @param { SecureContextOptions } certOption - information about the cert used in http requests
373
199
  *
374
200
  * @beta
375
201
  */
376
- constructor(teamsfx: TeamsFxConfiguration, scopes?: string | string[]);
202
+ constructor(certOption: SecureContextOptions);
377
203
  /**
378
- * Get access token for Microsoft Graph API requests.
204
+ * Adds authentication info to http requests.
379
205
  *
380
- * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
381
- * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
382
- * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
383
- * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
384
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
206
+ * @param { AxiosRequestConfig } config - Contains all the request information and can be updated to include extra authentication info.
207
+ * Refer https://axios-http.com/docs/req_config for detailed document.
208
+ *
209
+ * @returns Updated axios request config.
385
210
  *
386
- * @returns Access token from the credential.
211
+ * @throws {@link ErrorCode|InvalidParameter} - when custom httpsAgent in the request has duplicate properties with certOption provided in constructor.
387
212
  *
213
+ * @beta
388
214
  */
389
- getAccessToken(): Promise<string>;
215
+ AddAuthenticationInfo(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
390
216
  }
391
217
 
392
218
  /**
393
- * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
394
- *
395
- * @example
396
- * ```typescript
397
- * const credential = new OnBehalfOfUserCredential(ssoToken);
398
- * ```
219
+ * A {@link NotificationTarget} that represents a team channel.
399
220
  *
400
221
  * @remarks
401
- * Can only be used in server side.
222
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}.
402
223
  *
403
224
  * @beta
404
225
  */
405
- export declare class OnBehalfOfUserCredential implements TokenCredential {
406
- private msalClient;
407
- private ssoToken;
226
+ export declare class Channel implements NotificationTarget {
408
227
  /**
409
- * Constructor of OnBehalfOfUserCredential
410
- *
411
- * @remarks
412
- * Only works in in server side.
413
- *
414
- * @param {string} ssoToken - User token provided by Teams SSO feature.
415
- * @param {AuthenticationConfiguration} config - The authentication configuration. Use environment variables if not provided.
416
- *
417
- * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
418
- * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
419
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
228
+ * The parent {@link TeamsBotInstallation} where this channel is created from.
420
229
  *
421
230
  * @beta
422
231
  */
423
- constructor(ssoToken: string, config: AuthenticationConfiguration);
232
+ readonly parent: TeamsBotInstallation;
424
233
  /**
425
- * Get access token from credential.
426
- *
427
- * @example
428
- * ```typescript
429
- * await credential.getToken([]) // Get SSO token using empty string array
430
- * await credential.getToken("") // Get SSO token using empty string
431
- * await credential.getToken([".default"]) // Get Graph access token with default scope using string array
432
- * await credential.getToken(".default") // Get Graph access token with default scope using string
433
- * await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
434
- * await credential.getToken("User.Read") // Get Graph access token for single scope using string
435
- * await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
436
- * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
437
- * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
438
- * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
439
- * ```
440
- *
441
- * @param {string | string[]} scopes - The list of scopes for which the token will have access.
442
- * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
443
- *
444
- * @throws {@link ErrorCode|InternalError} when failed to acquire access token on behalf of user with unknown error.
445
- * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
446
- * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
447
- * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
448
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
449
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
450
- *
451
- * @returns Access token with expected scopes.
452
- *
453
- * @remarks
454
- * If scopes is empty string or array, it returns SSO token.
455
- * If scopes is non-empty, it returns access token for target scope.
234
+ * Detailed channel information.
456
235
  *
457
236
  * @beta
458
237
  */
459
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
238
+ readonly info: ChannelInfo;
460
239
  /**
461
- * Get basic user info from SSO token.
462
- *
463
- * @example
464
- * ```typescript
465
- * const currentUser = getUserInfo();
466
- * ```
467
- *
468
- * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
469
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
470
- *
471
- * @returns Basic user info with user displayName, objectId and preferredUserName.
240
+ * Notification target type. For channel it's always "Channel".
472
241
  *
473
242
  * @beta
474
243
  */
475
- getUserInfo(): UserInfo;
476
- private generateAuthServerError;
477
- }
478
-
479
- /**
480
- * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
481
- *
482
- * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
483
- *
484
- * @example
485
- * ```typescript
486
- * setLogFunction((level: LogLevel, message: string) => {
487
- * if (level === LogLevel.Error) {
488
- * console.log(message);
489
- * }
490
- * });
491
- * ```
492
- *
493
- * @beta
494
- */
495
- export declare function setLogFunction(logFunction?: LogFunction): void;
496
-
497
- /**
498
- * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
499
- *
500
- * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
501
- *
502
- * @example
503
- * ```typescript
504
- * setLogger({
505
- * verbose: console.debug,
506
- * info: console.info,
507
- * warn: console.warn,
508
- * error: console.error,
509
- * });
510
- * ```
511
- *
512
- * @beta
513
- */
514
- export declare function setLogger(logger?: Logger): void;
515
-
516
- /**
517
- * Update log level helper.
518
- *
519
- * @param { LogLevel } level - log level in configuration
520
- *
521
- * @beta
522
- */
523
- export declare function setLogLevel(level: LogLevel): void;
524
-
525
- /**
526
- * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
527
- * help receive oauth token, asks the user to consent if needed.
528
- *
529
- * @remarks
530
- * The prompt will attempt to retrieve the users current token of the desired scopes and store it in
531
- * the token store.
532
- *
533
- * User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO):
534
- * https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots
535
- *
536
- * @example
537
- * When used with your bots `DialogSet` you can simply add a new instance of the prompt as a named
538
- * dialog using `DialogSet.add()`. You can then start the prompt from a waterfall step using either
539
- * `DialogContext.beginDialog()` or `DialogContext.prompt()`. The user will be prompted to sign in as
540
- * needed and their access token will be passed as an argument to the callers next waterfall step:
541
- *
542
- * ```JavaScript
543
- * const { ConversationState, MemoryStorage } = require('botbuilder');
544
- * const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
545
- * const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');
546
- *
547
- * const convoState = new ConversationState(new MemoryStorage());
548
- * const dialogState = convoState.createProperty('dialogState');
549
- * const dialogs = new DialogSet(dialogState);
550
- *
551
- * dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
552
- * scopes: ["User.Read"],
553
- * }));
554
- *
555
- * dialogs.add(new WaterfallDialog('taskNeedingLogin', [
556
- * async (step) => {
557
- * return await step.beginDialog('TeamsBotSsoPrompt');
558
- * },
559
- * async (step) => {
560
- * const token = step.result;
561
- * if (token) {
562
- *
563
- * // ... continue with task needing access token ...
564
- *
565
- * } else {
566
- * await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
567
- * return await step.endDialog();
568
- * }
569
- * }
570
- * ]));
571
- * ```
572
- *
573
- * @beta
574
- */
575
- export declare class TeamsBotSsoPrompt extends Dialog {
576
- private teamsfx;
577
- private settings;
244
+ readonly type: NotificationTargetType;
578
245
  /**
579
- * Constructor of TeamsBotSsoPrompt.
246
+ * Constuctor.
580
247
  *
581
- * @param {TeamsFx} teamsfx - Used to provide configuration and auth
582
- * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
583
- * @param settings Settings used to configure the prompt.
248
+ * @remarks
249
+ * It's recommended to get channels from {@link TeamsBotInstallation.channels()}, instead of using this constructor.
584
250
  *
585
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
586
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
251
+ * @param parent - The parent {@link TeamsBotInstallation} where this channel is created from.
252
+ * @param info - Detailed channel information.
587
253
  *
588
254
  * @beta
589
255
  */
590
- constructor(teamsfx: TeamsFx, dialogId: string, settings: TeamsBotSsoPromptSettings);
256
+ constructor(parent: TeamsBotInstallation, info: ChannelInfo);
591
257
  /**
592
- * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
593
- * @remarks
594
- * If the task is successful, the result indicates whether the prompt is still
595
- * active after the turn has been processed by the prompt.
596
- *
597
- * @param dc The DialogContext for the current turn of the conversation.
598
- *
599
- * @throws {@link ErrorCode|InvalidParameter} when timeout property in teams bot sso prompt settings is not number or is not positive.
600
- * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
601
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
258
+ * Send a plain text message.
602
259
  *
260
+ * @param text - the plain text message.
603
261
  * @returns A `Promise` representing the asynchronous operation.
604
262
  *
605
263
  * @beta
606
264
  */
607
- beginDialog(dc: DialogContext): Promise<DialogTurnResult>;
265
+ sendMessage(text: string): Promise<void>;
608
266
  /**
609
- * Called when a prompt dialog is the active dialog and the user replied with a new activity.
610
- *
611
- * @remarks
612
- * If the task is successful, the result indicates whether the dialog is still
613
- * active after the turn has been processed by the dialog.
614
- * The prompt generally continues to receive the user's replies until it accepts the
615
- * user's reply as valid input for the prompt.
616
- *
617
- * @param dc The DialogContext for the current turn of the conversation.
267
+ * Send an adaptive card message.
618
268
  *
269
+ * @param card - the adaptive card raw JSON.
619
270
  * @returns A `Promise` representing the asynchronous operation.
620
271
  *
621
- * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
622
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
623
- *
624
272
  * @beta
625
273
  */
626
- continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
627
- private loadAndValidateConfig;
274
+ sendAdaptiveCard(card: unknown): Promise<void>;
628
275
  /**
629
- * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
630
- * @param dc dialog context
631
- * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
632
276
  * @internal
633
277
  */
634
- private ensureMsTeamsChannel;
278
+ private newConversation;
279
+ }
280
+
281
+ /**
282
+ * A command bot for receiving commands and sending responses in Teams.
283
+ *
284
+ * @remarks
285
+ * 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.
286
+ *
287
+ * @beta
288
+ */
289
+ export declare class CommandBot {
290
+ private readonly adapter;
291
+ private readonly middleware;
635
292
  /**
636
- * Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
637
- * For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
293
+ * Creates a new instance of the `CommandBot`.
638
294
  *
639
- * @internal
295
+ * @param adapter The bound `BotFrameworkAdapter`.
296
+ * @param options - initialize options
297
+ *
298
+ * @beta
640
299
  */
641
- private sendOAuthCardAsync;
300
+ constructor(adapter: BotFrameworkAdapter, options?: CommandOptions);
642
301
  /**
643
- * Get sign in resource.
302
+ * Registers a command into the command bot.
644
303
  *
645
- * @throws {@link ErrorCode|InvalidConfiguration} if client id, tenant id or initiate login endpoint is not found in config.
304
+ * @param command The command to registered.
646
305
  *
647
- * @internal
648
- */
649
- private getSignInResource;
650
- /**
651
- * @internal
652
- */
653
- private recognizeToken;
654
- /**
655
- * @internal
656
- */
657
- private getTokenExchangeInvokeResponse;
658
- /**
659
- * @internal
660
- */
661
- private isTeamsVerificationInvoke;
662
- /**
663
- * @internal
306
+ * @beta
664
307
  */
665
- private isTokenExchangeRequestInvoke;
308
+ registerCommand(command: TeamsFxBotCommandHandler): void;
666
309
  /**
667
- * @internal
310
+ * Registers commands into the command bot.
311
+ *
312
+ * @param commands The command to registered.
313
+ *
314
+ * @beta
668
315
  */
669
- private isTokenExchangeRequest;
316
+ registerCommands(commands: TeamsFxBotCommandHandler[]): void;
670
317
  }
671
318
 
672
319
  /**
673
- * Settings used to configure an TeamsBotSsoPrompt instance.
674
- *
675
- * @beta
320
+ * Interface for a command messagge that can handled in a command handler.
676
321
  */
677
- export declare interface TeamsBotSsoPromptSettings {
678
- /**
679
- * The array of strings that declare the desired permissions and the resources requested.
680
- */
681
- scopes: string[];
322
+ export declare interface CommandMessage {
682
323
  /**
683
- * (Optional) number of milliseconds the prompt will wait for the user to authenticate.
684
- * Defaults to a value `900,000` (15 minutes.)
324
+ * Text of the message sent by the user.
685
325
  */
686
- timeout?: number;
326
+ text: string;
687
327
  /**
688
- * (Optional) value indicating whether the TeamsBotSsoPrompt should end upon receiving an
689
- * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
690
- * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
691
- * Defaults to value `true`
328
+ * The capture groups that matched to the {@link TriggerPatterns} in a {@link TeamsFxBotCommandHandler} instance.
692
329
  */
693
- endOnInvalidMessage?: boolean;
330
+ matches?: RegExpMatchArray;
694
331
  }
695
332
 
696
333
  /**
697
- * Token response provided by Teams Bot SSO prompt
334
+ * Options to initialize {@link CommandBot}.
698
335
  *
699
336
  * @beta
700
337
  */
701
- export declare interface TeamsBotSsoPromptTokenResponse extends TokenResponse {
338
+ export declare interface CommandOptions {
702
339
  /**
703
- * SSO token for user
704
- */
705
- ssoToken: string;
706
- /**
707
- * Expire time of SSO token
340
+ * 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.
341
+ *
342
+ * @beta
708
343
  */
709
- ssoTokenExpiration: string;
344
+ commands?: TeamsFxBotCommandHandler[];
710
345
  }
711
346
 
712
347
  /**
713
- * A class providing credential and configuration.
348
+ * Provide utilities for bot conversation, including:
349
+ * - handle command and response.
350
+ * - send notification to varies targets (e.g., member, group, channel).
351
+ *
352
+ * @example
353
+ * For command and response, you can register your commands through the constructor, or use the `registerCommand` and `registerCommands` API to add commands later.
354
+ *
355
+ * ```typescript
356
+ * // register through constructor
357
+ * const conversationBot = new ConversationBot({
358
+ * command: {
359
+ * enabled: true,
360
+ * commands: [ new HelloWorldCommandHandler() ],
361
+ * },
362
+ * });
363
+ *
364
+ * // register through `register*` API
365
+ * conversationBot.command.registerCommand(new HelpCommandHandler());
366
+ * ```
367
+ *
368
+ * For notification, you can enable notification at initialization, then send notifications at any time.
369
+ *
370
+ * ```typescript
371
+ * // enable through constructor
372
+ * const conversationBot = new ConversationBot({
373
+ * notification: {
374
+ * enabled: true,
375
+ * },
376
+ * });
377
+ *
378
+ * // get all bot installations and send message
379
+ * for (const target of await conversationBot.notification.installations()) {
380
+ * await target.sendMessage("Hello Notification");
381
+ * }
382
+ *
383
+ * // alternative - send message to all members
384
+ * for (const target of await conversationBot.notification.installations()) {
385
+ * for (const member of await target.members()) {
386
+ * await member.sendMessage("Hello Notification");
387
+ * }
388
+ * }
389
+ * ```
390
+ *
391
+ * @remarks
392
+ * Set `adapter` in {@link ConversationOptions} to use your own bot adapter.
393
+ *
394
+ * 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.
395
+ *
396
+ * For notification, set `notification.storage` in {@link ConversationOptions} to use your own storage implementation.
397
+ *
714
398
  * @beta
715
399
  */
716
- export declare class TeamsFx implements TeamsFxConfiguration {
717
- private configuration;
718
- private oboUserCredential?;
719
- private appCredential?;
720
- private identityType;
400
+ export declare class ConversationBot {
721
401
  /**
722
- * Constructor of TeamsFx
723
- *
724
- * @param {IdentityType} identityType - Choose user or app identity
725
- * @param customConfig - key/value pairs of customized configuration that overrides default ones.
726
- *
727
- * @throws {@link ErrorCode|IdentityTypeNotSupported} when setting app identity in browser.
402
+ * The bot adapter.
728
403
  *
729
404
  * @beta
730
405
  */
731
- constructor(identityType?: IdentityType, customConfig?: Record<string, string>);
406
+ readonly adapter: BotFrameworkAdapter;
732
407
  /**
733
- * Identity type set by user.
408
+ * The entrypoint of command and response.
734
409
  *
735
- * @returns identity type.
736
410
  * @beta
737
411
  */
738
- getIdentityType(): IdentityType;
412
+ readonly command?: CommandBot;
739
413
  /**
740
- * Credential instance according to identity type choice.
414
+ * The entrypoint of notification.
741
415
  *
742
- * @remarks If user identity is chose, will return {@link TeamsUserCredential}
743
- * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
744
- * identity is chose, will return {@link AppCredential}.
745
- *
746
- * @returns instance implements TokenCredential interface.
747
416
  * @beta
748
417
  */
749
- getCredential(): TokenCredential;
418
+ readonly notification?: NotificationBot;
750
419
  /**
751
- * Get user information.
752
- * @returns UserInfo object.
420
+ * Creates new instance of the `ConversationBot`.
421
+ *
422
+ * @remarks
423
+ * It's recommended to create your own adapter and storage for production environment instead of the default one.
424
+ *
425
+ * @param options - initialize options
426
+ *
753
427
  * @beta
754
428
  */
755
- getUserInfo(): Promise<UserInfo>;
429
+ constructor(options: ConversationOptions);
430
+ private createDefaultAdapter;
756
431
  /**
757
- * Popup login page to get user's access token with specific scopes.
432
+ * The request handler to integrate with web request.
758
433
  *
759
- * @remarks
760
- * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
434
+ * @param req - an Express or Restify style request object.
435
+ * @param res - an Express or Restify style response object.
436
+ * @param logic - the additional function to handle bot context.
761
437
  *
762
438
  * @example
763
- * ```typescript
764
- * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
765
- * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
766
- * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
767
- * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
439
+ * For example, to use with Restify:
440
+ * ``` typescript
441
+ * // The default/empty behavior
442
+ * server.post("api/messages", conversationBot.requestHandler);
443
+ *
444
+ * // Or, add your own logic
445
+ * server.post("api/messages", async (req, res) => {
446
+ * await conversationBot.requestHandler(req, res, async (context) => {
447
+ * // your-own-context-logic
448
+ * });
449
+ * });
768
450
  * ```
769
- * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
770
- *
771
- * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
772
- * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
773
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
774
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
775
451
  *
776
452
  * @beta
777
453
  */
778
- login(scopes: string | string[]): Promise<void>;
779
- /**
780
- * Set SSO token when using user identity in NodeJS.
781
- * @param {string} ssoToken - used for on behalf of user flow.
782
- * @returns self instance.
783
- * @beta
784
- */
785
- setSsoToken(ssoToken: string): TeamsFx;
786
- /**
787
- * Usually used by service plugins to retrieve specific config
788
- * @param {string} key - configuration key.
789
- * @returns value in configuration.
790
- * @beta
791
- */
792
- getConfig(key: string): string;
793
- /**
794
- * Check the value of specific key.
795
- * @param {string} key - configuration key.
796
- * @returns true if corresponding value is not empty string.
797
- * @beta
798
- */
799
- hasConfig(key: string): boolean;
800
- /**
801
- * Get all configurations.
802
- * @returns key value mappings.
803
- * @beta
804
- */
805
- getConfigs(): Record<string, string>;
806
- /**
807
- * Load configuration from environment variables.
808
- */
809
- private loadFromEnv;
454
+ requestHandler(req: WebRequest, res: WebResponse, logic?: (context: TurnContext_2) => Promise<any>): Promise<void>;
810
455
  }
811
456
 
812
457
  /**
813
- * TeamsFx interface that provides credential and configuration.
458
+ * Options to initialize {@link ConversationBot}
459
+ *
814
460
  * @beta
815
461
  */
816
- declare interface TeamsFxConfiguration {
462
+ export declare interface ConversationOptions {
817
463
  /**
818
- * Identity type set by user.
464
+ * The bot adapter. If not provided, a default adapter will be created:
465
+ * - with `adapterConfig` as constructor parameter.
466
+ * - with a default error handler that logs error to console, sends trace activity, and sends error message to user.
819
467
  *
820
- * @returns identity type.
821
- * @beta
822
- */
823
- getIdentityType(): IdentityType;
824
- /**
825
- * Credential instance according to identity type choice.
826
- *
827
- * @remarks If user identity is chose, will return {@link TeamsUserCredential}
828
- * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
829
- * identity is chose, will return {@link AppCredential}.
468
+ * @remarks
469
+ * If neither `adapter` nor `adapterConfig` is provided, will use BOT_ID and BOT_PASSWORD from environment variables.
830
470
  *
831
- * @returns instance implements TokenCredential interface.
832
- * @beta
833
- */
834
- getCredential(): TokenCredential;
835
- /**
836
- * Get user information.
837
- * @returns UserInfo object.
838
471
  * @beta
839
472
  */
840
- getUserInfo(): Promise<UserInfo>;
473
+ adapter?: BotFrameworkAdapter;
841
474
  /**
842
- * Popup login page to get user's access token with specific scopes.
475
+ * If `adapter` is not provided, this `adapterConfig` will be passed to the new `BotFrameworkAdapter` when created internally.
843
476
  *
844
477
  * @remarks
845
- * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
846
- *
847
- * @example
848
- * ```typescript
849
- * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
850
- * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
851
- * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
852
- * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
853
- * ```
854
- * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
855
- *
856
- * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
857
- * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
858
- * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
859
- * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
478
+ * If neither `adapter` nor `adapterConfig` is provided, will use BOT_ID and BOT_PASSWORD from environment variables.
860
479
  *
861
480
  * @beta
862
481
  */
863
- login(scopes: string | string[]): Promise<void>;
864
- /**
865
- * Set SSO token when using user identity in NodeJS.
866
- * @param {string} ssoToken - used for on behalf of user flow.
867
- * @returns self instance.
868
- * @beta
869
- */
870
- setSsoToken(ssoToken: string): TeamsFxConfiguration;
871
- /**
872
- * Usually used by service plugins to retrieve specific config
873
- * @param {string} key - configuration key.
874
- * @returns value in configuration.
875
- * @beta
876
- */
877
- getConfig(key: string): string;
482
+ adapterConfig?: {
483
+ [key: string]: unknown;
484
+ };
878
485
  /**
879
- * Check the value of specific key.
880
- * @param {string} key - configuration key.
881
- * @returns true if corresponding value is not empty string.
486
+ * The command part.
487
+ *
882
488
  * @beta
883
489
  */
884
- hasConfig(key: string): boolean;
490
+ command?: CommandOptions & {
491
+ /**
492
+ * Whether to enable command or not.
493
+ *
494
+ * @beta
495
+ */
496
+ enabled?: boolean;
497
+ };
885
498
  /**
886
- * Get all configurations.
887
- * @returns key value mappings.
499
+ * The notification part.
500
+ *
888
501
  * @beta
889
502
  */
890
- getConfigs(): Record<string, string>;
503
+ notification?: NotificationOptions_2 & {
504
+ /**
505
+ * Whether to enable notification or not.
506
+ *
507
+ * @beta
508
+ */
509
+ enabled?: boolean;
510
+ };
891
511
  }
892
512
 
893
513
  /**
894
- * Represent Teams current user's identity, and it is used within Teams client applications.
514
+ * Initializes new Axios instance with specific auth provider
895
515
  *
896
- * @remarks
897
- * Can only be used within Teams.
516
+ * @param apiEndpoint - Base url of the API
517
+ * @param authProvider - Auth provider that injects authentication info to each request
518
+ * @returns axios instance configured with specfic auth provider
519
+ *
520
+ * @example
521
+ * ```typescript
522
+ * const client = createApiClient("https://my-api-endpoint-base-url", new BasicAuthProvider("xxx","xxx"));
523
+ * ```
898
524
  *
899
525
  * @beta
900
526
  */
901
- export declare class TeamsUserCredential implements TokenCredential {
902
- /**
903
- * Constructor of TeamsUserCredential.
904
- * @remarks
905
- * Can only be used within Teams.
906
- * @beta
907
- */
908
- constructor(authConfig: AuthenticationConfiguration);
909
- /**
910
- * Popup login page to get user's access token with specific scopes.
911
- * @remarks
912
- * Can only be used within Teams.
913
- * @beta
914
- */
915
- login(scopes: string | string[]): Promise<void>;
916
- /**
917
- * Get access token from credential.
918
- * @remarks
919
- * Can only be used within Teams.
920
- * @beta
921
- */
922
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
923
- /**
924
- * Get basic user info from SSO token
925
- * @remarks
926
- * Can only be used within Teams.
927
- * @beta
928
- */
929
- getUserInfo(): Promise<UserInfo>;
930
- }
527
+ export declare function createApiClient(apiEndpoint: string, authProvider: AuthProvider): AxiosInstance;
931
528
 
932
529
  /**
933
- * UserInfo with user displayName, objectId and preferredUserName.
530
+ * Get Microsoft graph client.
531
+ *
532
+ * @example
533
+ * Get Microsoft graph client by TokenCredential
534
+ * ```typescript
535
+ * // Sso token example (Azure Function)
536
+ * const ssoToken = "YOUR_TOKEN_STRING";
537
+ * const options = {"AAD_APP_ID", "AAD_APP_SECRET"};
538
+ * const credential = new OnBehalfOfAADUserCredential(ssoToken, options);
539
+ * const graphClient = await createMicrosoftGraphClient(credential);
540
+ * const profile = await graphClient.api("/me").get();
541
+ *
542
+ * // TeamsBotSsoPrompt example (Bot Application)
543
+ * const requiredScopes = ["User.Read"];
544
+ * const config: Configuration = {
545
+ * loginUrl: loginUrl,
546
+ * clientId: clientId,
547
+ * clientSecret: clientSecret,
548
+ * tenantId: tenantId
549
+ * };
550
+ * const prompt = new TeamsBotSsoPrompt(dialogId, {
551
+ * config: config
552
+ * scopes: '["User.Read"],
553
+ * });
554
+ * this.addDialog(prompt);
555
+ *
556
+ * const oboCredential = new OnBehalfOfAADUserCredential(
557
+ * getUserId(dialogContext),
558
+ * {
559
+ * clientId: "AAD_APP_ID",
560
+ * clientSecret: "AAD_APP_SECRET"
561
+ * });
562
+ * try {
563
+ * const graphClient = await createMicrosoftGraphClient(credential);
564
+ * const profile = await graphClient.api("/me").get();
565
+ * } catch (e) {
566
+ * dialogContext.beginDialog(dialogId);
567
+ * return Dialog.endOfTurn();
568
+ * }
569
+ * ```
570
+ *
571
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
572
+ * @param scopes - The array of Microsoft Token scope of access. Default value is `[.default]`.
573
+ *
574
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
575
+ *
576
+ * @returns Graph client with specified scopes.
934
577
  *
935
578
  * @beta
936
579
  */
937
- export declare interface UserInfo {
938
- /**
939
- * User Display Name.
580
+ export declare function createMicrosoftGraphClient(teamsfx: TeamsFxConfiguration, scopes?: string | string[]): Client;
581
+
582
+ /**
583
+ * Helper to create SecureContextOptions from PEM format cert
584
+ *
585
+ * @param { string | Buffer } cert - The cert chain in PEM format
586
+ * @param { string | Buffer } key - The private key for the cert chain
587
+ * @param { string? } passphrase - The passphrase for private key
588
+ * @param { string? | Buffer? } ca - Overrides the trusted CA certificates
940
589
  *
941
- * @readonly
942
- */
943
- displayName: string;
944
- /**
945
- * User unique reference within the Azure Active Directory domain.
590
+ * @returns Instance of SecureContextOptions
946
591
  *
947
- * @readonly
948
- */
949
- objectId: string;
950
- /**
951
- * Usually be the email address.
592
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
952
593
  *
953
- * @readonly
954
594
  */
955
- preferredUserName: string;
956
- }
595
+ export declare function createPemCertOption(cert: string | Buffer, key: string | Buffer, passphrase?: string, ca?: string | Buffer): SecureContextOptions;
596
+
597
+ /**
598
+ * Helper to create SecureContextOptions from PFX format cert
599
+ *
600
+ * @param { string | Buffer } pfx - The content of .pfx file
601
+ * @param { string? } passphrase - Optional. The passphrase of .pfx file
602
+ *
603
+ * @returns Instance of SecureContextOptions
604
+ *
605
+ * @throws {@link ErrorCode|InvalidParameter} - when any parameter is empty
606
+ *
607
+ */
608
+ export declare function createPfxCertOption(pfx: string | Buffer, passphrase?: string): SecureContextOptions;
609
+
610
+ /**
611
+ * Error code to trace the error types.
612
+ * @beta
613
+ */
614
+ export declare enum ErrorCode {
615
+ /**
616
+ * Invalid parameter error.
617
+ */
618
+ InvalidParameter = "InvalidParameter",
619
+ /**
620
+ * Invalid configuration error.
621
+ */
622
+ InvalidConfiguration = "InvalidConfiguration",
623
+ /**
624
+ * Invalid certificate error.
625
+ */
626
+ InvalidCertificate = "InvalidCertificate",
627
+ /**
628
+ * Internal error.
629
+ */
630
+ InternalError = "InternalError",
631
+ /**
632
+ * Channel is not supported error.
633
+ */
634
+ ChannelNotSupported = "ChannelNotSupported",
635
+ /**
636
+ * Runtime is not supported error.
637
+ */
638
+ RuntimeNotSupported = "RuntimeNotSupported",
639
+ /**
640
+ * User failed to finish the AAD consent flow failed.
641
+ */
642
+ ConsentFailed = "ConsentFailed",
643
+ /**
644
+ * The user or administrator has not consented to use the application error.
645
+ */
646
+ UiRequiredError = "UiRequiredError",
647
+ /**
648
+ * Token is not within its valid time range error.
649
+ */
650
+ TokenExpiredError = "TokenExpiredError",
651
+ /**
652
+ * Call service (AAD or simple authentication server) failed.
653
+ */
654
+ ServiceError = "ServiceError",
655
+ /**
656
+ * Operation failed.
657
+ */
658
+ FailedOperation = "FailedOperation",
659
+ /**
660
+ * Invalid response error.
661
+ */
662
+ InvalidResponse = "InvalidResponse",
663
+ /**
664
+ * Identity type error.
665
+ */
666
+ IdentityTypeNotSupported = "IdentityTypeNotSupported"
667
+ }
668
+
669
+ /**
670
+ * Error class with code and message thrown by the SDK.
671
+ *
672
+ * @beta
673
+ */
674
+ export declare class ErrorWithCode extends Error {
675
+ /**
676
+ * Error code
677
+ *
678
+ * @readonly
679
+ */
680
+ code: string | undefined;
681
+ /**
682
+ * Constructor of ErrorWithCode.
683
+ *
684
+ * @param {string} message - error message.
685
+ * @param {ErrorCode} code - error code.
686
+ *
687
+ * @beta
688
+ */
689
+ constructor(message?: string, code?: ErrorCode);
690
+ }
691
+
692
+ /**
693
+ * Get log level.
694
+ *
695
+ * @returns Log level
696
+ *
697
+ * @beta
698
+ */
699
+ export declare function getLogLevel(): LogLevel | undefined;
700
+
701
+ /**
702
+ * Generate connection configuration consumed by tedious.
703
+ *
704
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth
705
+ * @param { string? } databaseName - specify database name to override default one if there are multiple databases.
706
+ *
707
+ * @returns Connection configuration of tedious for the SQL.
708
+ *
709
+ * @throws {@link ErrorCode|InvalidConfiguration} when SQL config resource configuration is invalid.
710
+ * @throws {@link ErrorCode|InternalError} when get user MSI token failed or MSI token is invalid.
711
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
712
+ *
713
+ * @beta
714
+ */
715
+ export declare function getTediousConnectionConfig(teamsfx: TeamsFx, databaseName?: string): Promise<ConnectionConfig>;
716
+
717
+ /**
718
+ * Identity type to use in authentication.
719
+ *
720
+ * @beta
721
+ */
722
+ export declare enum IdentityType {
723
+ /**
724
+ * Represents the current user of Teams.
725
+ */
726
+ User = "User",
727
+ /**
728
+ * Represents the application itself.
729
+ */
730
+ App = "Application"
731
+ }
732
+
733
+ /**
734
+ * Log function for customized logging.
735
+ *
736
+ * @beta
737
+ */
738
+ export declare type LogFunction = (level: LogLevel, message: string) => void;
739
+
740
+ /**
741
+ * Interface for customized logger.
742
+ * @beta
743
+ */
744
+ export declare interface Logger {
745
+ /**
746
+ * Writes to error level logging or lower.
747
+ */
748
+ error(message: string): void;
749
+ /**
750
+ * Writes to warning level logging or lower.
751
+ */
752
+ warn(message: string): void;
753
+ /**
754
+ * Writes to info level logging or lower.
755
+ */
756
+ info(message: string): void;
757
+ /**
758
+ * Writes to verbose level logging.
759
+ */
760
+ verbose(message: string): void;
761
+ }
762
+
763
+ /**
764
+ * Log level.
765
+ *
766
+ * @beta
767
+ */
768
+ export declare enum LogLevel {
769
+ /**
770
+ * Show verbose, information, warning and error message.
771
+ */
772
+ Verbose = 0,
773
+ /**
774
+ * Show information, warning and error message.
775
+ */
776
+ Info = 1,
777
+ /**
778
+ * Show warning and error message.
779
+ */
780
+ Warn = 2,
781
+ /**
782
+ * Show error message.
783
+ */
784
+ Error = 3
785
+ }
786
+
787
+ /**
788
+ * A {@link NotificationTarget} that represents a team member.
789
+ *
790
+ * @remarks
791
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}.
792
+ *
793
+ * @beta
794
+ */
795
+ export declare class Member implements NotificationTarget {
796
+ /**
797
+ * The parent {@link TeamsBotInstallation} where this member is created from.
798
+ *
799
+ * @beta
800
+ */
801
+ readonly parent: TeamsBotInstallation;
802
+ /**
803
+ * Detailed member account information.
804
+ *
805
+ * @beta
806
+ */
807
+ readonly account: TeamsChannelAccount;
808
+ /**
809
+ * Notification target type. For member it's always "Person".
810
+ *
811
+ * @beta
812
+ */
813
+ readonly type: NotificationTargetType;
814
+ /**
815
+ * Constuctor.
816
+ *
817
+ * @remarks
818
+ * It's recommended to get members from {@link TeamsBotInstallation.members()}, instead of using this constructor.
819
+ *
820
+ * @param parent - The parent {@link TeamsBotInstallation} where this member is created from.
821
+ * @param account - Detailed member account information.
822
+ *
823
+ * @beta
824
+ */
825
+ constructor(parent: TeamsBotInstallation, account: TeamsChannelAccount);
826
+ /**
827
+ * Send a plain text message.
828
+ *
829
+ * @param text - the plain text message.
830
+ * @returns A `Promise` representing the asynchronous operation.
831
+ *
832
+ * @beta
833
+ */
834
+ sendMessage(text: string): Promise<void>;
835
+ /**
836
+ * Send an adaptive card message.
837
+ *
838
+ * @param card - the adaptive card raw JSON.
839
+ * @returns A `Promise` representing the asynchronous operation.
840
+ *
841
+ * @beta
842
+ */
843
+ sendAdaptiveCard(card: unknown): Promise<void>;
844
+ /**
845
+ * @internal
846
+ */
847
+ private newConversation;
848
+ }
849
+
850
+ /**
851
+ * Provides utility method to build bot message with cards that supported in Teams.
852
+ */
853
+ export declare class MessageBuilder {
854
+ /**
855
+ * Build a bot message activity attached with adaptive card.
856
+ *
857
+ * @param getCardData Function to prepare your card data.
858
+ * @param cardTemplate The adaptive card template.
859
+ * @returns A bot message activity attached with an adaptive card.
860
+ *
861
+ * @example
862
+ * ```javascript
863
+ * const cardTemplate = {
864
+ * type: "AdaptiveCard",
865
+ * body: [
866
+ * {
867
+ * "type": "TextBlock",
868
+ * "text": "${title}",
869
+ * "size": "Large"
870
+ * },
871
+ * {
872
+ * "type": "TextBlock",
873
+ * "text": "${description}"
874
+ * }],
875
+ * $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
876
+ * version: "1.4"
877
+ * };
878
+ *
879
+ * type CardData = {
880
+ * title: string,
881
+ * description: string
882
+ * };
883
+ * const card = MessageBuilder.attachAdaptiveCard<CardData>(() => {
884
+ * return {
885
+ * title: "sample card title",
886
+ * description: "sample card description"
887
+ * }}, cardTemplate);
888
+ * ```
889
+ *
890
+ * @beta
891
+ */
892
+ static attachAdaptiveCard<TData>(getCardData: () => TData, cardTemplate: any): Partial<Activity_2>;
893
+ /**
894
+ * Build a bot message activity attached with an adaptive card.
895
+ *
896
+ * @param card The adaptive card content.
897
+ * @returns A bot message activity attached with an adaptive card.
898
+ *
899
+ * @beta
900
+ */
901
+ static attachAdaptiveCardWithoutData(card: any): Partial<Activity_2>;
902
+ /**
903
+ * Build a bot message activity attached with an hero card.
904
+ *
905
+ * @param title The card title.
906
+ * @param images Optional. The array of images to include on the card.
907
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
908
+ * is converted to an `imBack` button with a title and value set to the value of the string.
909
+ * @param other Optional. Any additional properties to include on the card.
910
+ *
911
+ * @returns A bot message activity attached with a hero card.
912
+ *
913
+ * @example
914
+ * ```javascript
915
+ * const message = MessageBuilder.attachHeroCard(
916
+ * 'sample title',
917
+ * ['https://example.com/sample.jpg'],
918
+ * ['action']
919
+ * );
920
+ * ```
921
+ *
922
+ * @beta
923
+ */
924
+ static attachHeroCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<HeroCard>): Partial<Activity_2>;
925
+ /**
926
+ * Returns an attachment for a sign-in card.
927
+ *
928
+ * @param title The title for the card's sign-in button.
929
+ * @param url The URL of the sign-in page to use.
930
+ * @param text Optional. Additional text to include on the card.
931
+ *
932
+ * @returns A bot message activity attached with a sign-in card.
933
+ *
934
+ * @remarks
935
+ * For channels that don't natively support sign-in cards, an alternative message is rendered.
936
+ *
937
+ * @beta
938
+ */
939
+ static attachSigninCard(title: string, url: string, text?: string): Partial<Activity_2>;
940
+ /**
941
+ * Build a bot message activity attached with an Office 365 connector card.
942
+ *
943
+ * @param card A description of the Office 365 connector card.
944
+ * @returns A bot message activity attached with an Office 365 connector card.
945
+ *
946
+ * @beta
947
+ */
948
+ static attachO365ConnectorCard(card: O365ConnectorCard): Partial<Activity_2>;
949
+ /**
950
+ * Build a message activity attached with a receipt card.
951
+ * @param card A description of the receipt card.
952
+ * @returns A message activity attached with a receipt card.
953
+ *
954
+ * @beta
955
+ */
956
+ static AttachReceiptCard(card: ReceiptCard): Partial<Activity_2>;
957
+ /**
958
+ *
959
+ * @param title The card title.
960
+ * @param images Optional. The array of images to include on the card.
961
+ * @param buttons Optional. The array of buttons to include on the card. Each `string` in the array
962
+ * is converted to an `imBack` button with a title and value set to the value of the string.
963
+ * @param other Optional. Any additional properties to include on the card.
964
+ * @returns A message activity attached with a thumbnail card
965
+ *
966
+ * @beta
967
+ */
968
+ static attachThumbnailCard(title: string, images?: (CardImage | string)[], buttons?: (CardAction | string)[], other?: Partial<ThumbnailCard>): Partial<Activity_2>;
969
+ /**
970
+ * Add an attachement to a bot activity.
971
+ * @param attachement The attachment object to attach.
972
+ * @returns A message activity with an attachment.
973
+ *
974
+ * @beta
975
+ */
976
+ static attachContent(attachement: Attachment): Partial<Activity_2>;
977
+ }
978
+
979
+ /**
980
+ * Microsoft Graph auth provider for Teams Framework
981
+ *
982
+ * @beta
983
+ */
984
+ export declare class MsGraphAuthProvider implements AuthenticationProvider {
985
+ private teamsfx;
986
+ private scopes;
987
+ /**
988
+ * Constructor of MsGraphAuthProvider.
989
+ *
990
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth.
991
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
992
+ *
993
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
994
+ *
995
+ * @returns An instance of MsGraphAuthProvider.
996
+ *
997
+ * @beta
998
+ */
999
+ constructor(teamsfx: TeamsFxConfiguration, scopes?: string | string[]);
1000
+ /**
1001
+ * Get access token for Microsoft Graph API requests.
1002
+ *
1003
+ * @throws {@link ErrorCode|InternalError} when get access token failed due to empty token or unknown other problems.
1004
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1005
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1006
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth or AAD server.
1007
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1008
+ *
1009
+ * @returns Access token from the credential.
1010
+ *
1011
+ */
1012
+ getAccessToken(): Promise<string>;
1013
+ }
1014
+
1015
+ /**
1016
+ * Provide utilities to send notification to varies targets (e.g., member, group, channel).
1017
+ *
1018
+ * @beta
1019
+ */
1020
+ export declare class NotificationBot {
1021
+ private readonly conversationReferenceStore;
1022
+ private readonly adapter;
1023
+ /**
1024
+ * constructor of the notification bot.
1025
+ *
1026
+ * @remarks
1027
+ * To ensure accuracy, it's recommended to initialize before handling any message.
1028
+ *
1029
+ * @param adapter - the bound `BotFrameworkAdapter`
1030
+ * @param options - initialize options
1031
+ *
1032
+ * @beta
1033
+ */
1034
+ constructor(adapter: BotFrameworkAdapter, options?: NotificationOptions_2);
1035
+ /**
1036
+ * Get all targets where the bot is installed.
1037
+ *
1038
+ * @remarks
1039
+ * The result is retrieving from the persisted storage.
1040
+ *
1041
+ * @returns - an array of {@link TeamsBotInstallation}.
1042
+ *
1043
+ * @beta
1044
+ */
1045
+ installations(): Promise<TeamsBotInstallation[]>;
1046
+ }
1047
+
1048
+ /**
1049
+ * Options to initialize {@link NotificationBot}.
1050
+ *
1051
+ * @beta
1052
+ */
1053
+ declare interface NotificationOptions_2 {
1054
+ /**
1055
+ * An optional storage to persist bot notification connections.
1056
+ *
1057
+ * @remarks
1058
+ * If `storage` is not provided, a default local file storage will be used,
1059
+ * which stores notification connections into:
1060
+ * - ".notification.localstore.json" if running locally
1061
+ * - "${process.env.TEMP}/.notification.localstore.json" if `process.env.RUNNING_ON_AZURE` is set to "1"
1062
+ *
1063
+ * It's recommended to use your own shared storage for production environment.
1064
+ *
1065
+ * @beta
1066
+ */
1067
+ storage?: NotificationTargetStorage;
1068
+ }
1069
+ export { NotificationOptions_2 as NotificationOptions }
1070
+
1071
+ /**
1072
+ * Represent a notification target.
1073
+ *
1074
+ * @beta
1075
+ */
1076
+ export declare interface NotificationTarget {
1077
+ /**
1078
+ * The type of target, could be "Channel" or "Group" or "Person".
1079
+ *
1080
+ * @beta
1081
+ */
1082
+ readonly type?: NotificationTargetType;
1083
+ /**
1084
+ * Send a plain text message.
1085
+ *
1086
+ * @param text - the plain text message.
1087
+ *
1088
+ * @beta
1089
+ */
1090
+ sendMessage(text: string): Promise<void>;
1091
+ /**
1092
+ * Send an adaptive card message.
1093
+ *
1094
+ * @param card - the adaptive card raw JSON.
1095
+ *
1096
+ * @beta
1097
+ */
1098
+ sendAdaptiveCard(card: unknown): Promise<void>;
1099
+ }
1100
+
1101
+ /**
1102
+ * Interface for a storage provider that stores and retrieves notification target references.
1103
+ *
1104
+ * @beta
1105
+ */
1106
+ export declare interface NotificationTargetStorage {
1107
+ /**
1108
+ * Read one notification target by its key.
1109
+ *
1110
+ * @param key - the key of a notification target.
1111
+ *
1112
+ * @returns - the notification target. Or undefined if not found.
1113
+ *
1114
+ * @beta
1115
+ */
1116
+ read(key: string): Promise<{
1117
+ [key: string]: unknown;
1118
+ } | undefined>;
1119
+ /**
1120
+ * List all stored notification targets.
1121
+ *
1122
+ * @returns - an array of notification target. Or an empty array if nothing is stored.
1123
+ *
1124
+ * @beta
1125
+ */
1126
+ list(): Promise<{
1127
+ [key: string]: unknown;
1128
+ }[]>;
1129
+ /**
1130
+ * Write one notification target by its key.
1131
+ *
1132
+ * @param key - the key of a notification target.
1133
+ * @param object - the notification target.
1134
+ *
1135
+ * @beta
1136
+ */
1137
+ write(key: string, object: {
1138
+ [key: string]: unknown;
1139
+ }): Promise<void>;
1140
+ /**
1141
+ * Delete one notificaton target by its key.
1142
+ *
1143
+ * @param key - the key of a notification target.
1144
+ *
1145
+ * @beta
1146
+ */
1147
+ delete(key: string): Promise<void>;
1148
+ }
1149
+
1150
+ /**
1151
+ * The target type where the notification will be sent to.
1152
+ *
1153
+ * @remarks
1154
+ * - "Channel" means to a team channel. (By default, notification to a team will be sent to its "General" channel.)
1155
+ * - "Group" means to a group chat.
1156
+ * - "Person" means to a personal chat.
1157
+ *
1158
+ * @beta
1159
+ */
1160
+ export declare type NotificationTargetType = "Channel" | "Group" | "Person";
1161
+
1162
+ /**
1163
+ * Represent on-behalf-of flow to get user identity, and it is designed to be used in server side.
1164
+ *
1165
+ * @example
1166
+ * ```typescript
1167
+ * const credential = new OnBehalfOfUserCredential(ssoToken);
1168
+ * ```
1169
+ *
1170
+ * @remarks
1171
+ * Can only be used in server side.
1172
+ *
1173
+ * @beta
1174
+ */
1175
+ export declare class OnBehalfOfUserCredential implements TokenCredential {
1176
+ private msalClient;
1177
+ private ssoToken;
1178
+ /**
1179
+ * Constructor of OnBehalfOfUserCredential
1180
+ *
1181
+ * @remarks
1182
+ * Only works in in server side.
1183
+ *
1184
+ * @param {string} ssoToken - User token provided by Teams SSO feature.
1185
+ * @param {AuthenticationConfiguration} config - The authentication configuration. Use environment variables if not provided.
1186
+ *
1187
+ * @throws {@link ErrorCode|InvalidConfiguration} when client id, client secret, certificate content, authority host or tenant id is not found in config.
1188
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1189
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1190
+ *
1191
+ * @beta
1192
+ */
1193
+ constructor(ssoToken: string, config: AuthenticationConfiguration);
1194
+ /**
1195
+ * Get access token from credential.
1196
+ *
1197
+ * @example
1198
+ * ```typescript
1199
+ * await credential.getToken([]) // Get SSO token using empty string array
1200
+ * await credential.getToken("") // Get SSO token using empty string
1201
+ * await credential.getToken([".default"]) // Get Graph access token with default scope using string array
1202
+ * await credential.getToken(".default") // Get Graph access token with default scope using string
1203
+ * await credential.getToken(["User.Read"]) // Get Graph access token for single scope using string array
1204
+ * await credential.getToken("User.Read") // Get Graph access token for single scope using string
1205
+ * await credential.getToken(["User.Read", "Application.Read.All"]) // Get Graph access token for multiple scopes using string array
1206
+ * await credential.getToken("User.Read Application.Read.All") // Get Graph access token for multiple scopes using space-separated string
1207
+ * await credential.getToken("https://graph.microsoft.com/User.Read") // Get Graph access token with full resource URI
1208
+ * await credential.getToken(["https://outlook.office.com/Mail.Read"]) // Get Outlook access token
1209
+ * ```
1210
+ *
1211
+ * @param {string | string[]} scopes - The list of scopes for which the token will have access.
1212
+ * @param {GetTokenOptions} options - The options used to configure any requests this TokenCredential implementation might make.
1213
+ *
1214
+ * @throws {@link ErrorCode|InternalError} when failed to acquire access token on behalf of user with unknown error.
1215
+ * @throws {@link ErrorCode|TokenExpiredError} when SSO token has already expired.
1216
+ * @throws {@link ErrorCode|UiRequiredError} when need user consent to get access token.
1217
+ * @throws {@link ErrorCode|ServiceError} when failed to get access token from simple auth server.
1218
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1219
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1220
+ *
1221
+ * @returns Access token with expected scopes.
1222
+ *
1223
+ * @remarks
1224
+ * If scopes is empty string or array, it returns SSO token.
1225
+ * If scopes is non-empty, it returns access token for target scope.
1226
+ *
1227
+ * @beta
1228
+ */
1229
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1230
+ /**
1231
+ * Get basic user info from SSO token.
1232
+ *
1233
+ * @example
1234
+ * ```typescript
1235
+ * const currentUser = getUserInfo();
1236
+ * ```
1237
+ *
1238
+ * @throws {@link ErrorCode|InternalError} when SSO token is not valid.
1239
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1240
+ *
1241
+ * @returns Basic user info with user displayName, objectId and preferredUserName.
1242
+ *
1243
+ * @beta
1244
+ */
1245
+ getUserInfo(): UserInfo;
1246
+ private generateAuthServerError;
1247
+ }
1248
+
1249
+ /**
1250
+ * Send an adaptive card message to a notification target.
1251
+ *
1252
+ * @param target - the notification target.
1253
+ * @param card - the adaptive card raw JSON.
1254
+ * @returns A `Promise` representing the asynchronous operation.
1255
+ *
1256
+ * @beta
1257
+ */
1258
+ export declare function sendAdaptiveCard(target: NotificationTarget, card: unknown): Promise<void>;
1259
+
1260
+ /**
1261
+ * Send a plain text message to a notification target.
1262
+ *
1263
+ * @param target - the notification target.
1264
+ * @param text - the plain text message.
1265
+ * @returns A `Promise` representing the asynchronous operation.
1266
+ *
1267
+ * @beta
1268
+ */
1269
+ export declare function sendMessage(target: NotificationTarget, text: string): Promise<void>;
1270
+
1271
+ /**
1272
+ * Set custom log function. Use the function if it's set. Priority is lower than setLogger.
1273
+ *
1274
+ * @param {LogFunction} logFunction - custom log function. If it's undefined, custom log function will be cleared.
1275
+ *
1276
+ * @example
1277
+ * ```typescript
1278
+ * setLogFunction((level: LogLevel, message: string) => {
1279
+ * if (level === LogLevel.Error) {
1280
+ * console.log(message);
1281
+ * }
1282
+ * });
1283
+ * ```
1284
+ *
1285
+ * @beta
1286
+ */
1287
+ export declare function setLogFunction(logFunction?: LogFunction): void;
1288
+
1289
+ /**
1290
+ * Set custom logger. Use the output functions if it's set. Priority is higher than setLogFunction.
1291
+ *
1292
+ * @param {Logger} logger - custom logger. If it's undefined, custom logger will be cleared.
1293
+ *
1294
+ * @example
1295
+ * ```typescript
1296
+ * setLogger({
1297
+ * verbose: console.debug,
1298
+ * info: console.info,
1299
+ * warn: console.warn,
1300
+ * error: console.error,
1301
+ * });
1302
+ * ```
1303
+ *
1304
+ * @beta
1305
+ */
1306
+ export declare function setLogger(logger?: Logger): void;
1307
+
1308
+ /**
1309
+ * Update log level helper.
1310
+ *
1311
+ * @param { LogLevel } level - log level in configuration
1312
+ *
1313
+ * @beta
1314
+ */
1315
+ export declare function setLogLevel(level: LogLevel): void;
1316
+
1317
+ /**
1318
+ * A {@link NotificationTarget} that represents a bot installation. Teams Bot could be installed into
1319
+ * - Personal chat
1320
+ * - Group chat
1321
+ * - Team (by default the `General` channel)
1322
+ *
1323
+ * @remarks
1324
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}.
1325
+ *
1326
+ * @beta
1327
+ */
1328
+ export declare class TeamsBotInstallation implements NotificationTarget {
1329
+ /**
1330
+ * The bound `BotFrameworkAdapter`.
1331
+ *
1332
+ * @beta
1333
+ */
1334
+ readonly adapter: BotFrameworkAdapter;
1335
+ /**
1336
+ * The bound `ConversationReference`.
1337
+ *
1338
+ * @beta
1339
+ */
1340
+ readonly conversationReference: Partial<ConversationReference>;
1341
+ /**
1342
+ * Notification target type.
1343
+ *
1344
+ * @remarks
1345
+ * - "Channel" means bot is installed into a team and notification will be sent to its "General" channel.
1346
+ * - "Group" means bot is installed into a group chat.
1347
+ * - "Person" means bot is installed into a personal scope and notification will be sent to personal chat.
1348
+ *
1349
+ * @beta
1350
+ */
1351
+ readonly type?: NotificationTargetType;
1352
+ /**
1353
+ * Constructor
1354
+ *
1355
+ * @remarks
1356
+ * It's recommended to get bot installations from {@link ConversationBot.installations()}, instead of using this constructor.
1357
+ *
1358
+ * @param adapter - the bound `BotFrameworkAdapter`.
1359
+ * @param conversationReference - the bound `ConversationReference`.
1360
+ *
1361
+ * @beta
1362
+ */
1363
+ constructor(adapter: BotFrameworkAdapter, conversationReference: Partial<ConversationReference>);
1364
+ /**
1365
+ * Send a plain text message.
1366
+ *
1367
+ * @param text - the plain text message.
1368
+ * @returns A `Promise` representing the asynchronous operation.
1369
+ *
1370
+ * @beta
1371
+ */
1372
+ sendMessage(text: string): Promise<void>;
1373
+ /**
1374
+ * Send an adaptive card message.
1375
+ *
1376
+ * @param card - the adaptive card raw JSON.
1377
+ * @returns A `Promise` representing the asynchronous operation.
1378
+ *
1379
+ * @beta
1380
+ */
1381
+ sendAdaptiveCard(card: unknown): Promise<void>;
1382
+ /**
1383
+ * Get channels from this bot installation.
1384
+ *
1385
+ * @returns an array of channels if bot is installed into a team, otherwise returns an empty array.
1386
+ *
1387
+ * @beta
1388
+ */
1389
+ channels(): Promise<Channel[]>;
1390
+ /**
1391
+ * Get members from this bot installation.
1392
+ *
1393
+ * @returns an array of members from where the bot is installed.
1394
+ *
1395
+ * @beta
1396
+ */
1397
+ members(): Promise<Member[]>;
1398
+ }
1399
+
1400
+ /**
1401
+ * Creates a new prompt that leverage Teams Single Sign On (SSO) support for bot to automatically sign in user and
1402
+ * help receive oauth token, asks the user to consent if needed.
1403
+ *
1404
+ * @remarks
1405
+ * The prompt will attempt to retrieve the users current token of the desired scopes and store it in
1406
+ * the token store.
1407
+ *
1408
+ * User will be automatically signed in leveraging Teams support of Bot Single Sign On(SSO):
1409
+ * https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots
1410
+ *
1411
+ * @example
1412
+ * When used with your bots `DialogSet` you can simply add a new instance of the prompt as a named
1413
+ * dialog using `DialogSet.add()`. You can then start the prompt from a waterfall step using either
1414
+ * `DialogContext.beginDialog()` or `DialogContext.prompt()`. The user will be prompted to sign in as
1415
+ * needed and their access token will be passed as an argument to the callers next waterfall step:
1416
+ *
1417
+ * ```JavaScript
1418
+ * const { ConversationState, MemoryStorage } = require('botbuilder');
1419
+ * const { DialogSet, WaterfallDialog } = require('botbuilder-dialogs');
1420
+ * const { TeamsBotSsoPrompt } = require('@microsoft/teamsfx');
1421
+ *
1422
+ * const convoState = new ConversationState(new MemoryStorage());
1423
+ * const dialogState = convoState.createProperty('dialogState');
1424
+ * const dialogs = new DialogSet(dialogState);
1425
+ *
1426
+ * dialogs.add(new TeamsBotSsoPrompt('TeamsBotSsoPrompt', {
1427
+ * scopes: ["User.Read"],
1428
+ * }));
1429
+ *
1430
+ * dialogs.add(new WaterfallDialog('taskNeedingLogin', [
1431
+ * async (step) => {
1432
+ * return await step.beginDialog('TeamsBotSsoPrompt');
1433
+ * },
1434
+ * async (step) => {
1435
+ * const token = step.result;
1436
+ * if (token) {
1437
+ *
1438
+ * // ... continue with task needing access token ...
1439
+ *
1440
+ * } else {
1441
+ * await step.context.sendActivity(`Sorry... We couldn't log you in. Try again later.`);
1442
+ * return await step.endDialog();
1443
+ * }
1444
+ * }
1445
+ * ]));
1446
+ * ```
1447
+ *
1448
+ * @beta
1449
+ */
1450
+ export declare class TeamsBotSsoPrompt extends Dialog {
1451
+ private teamsfx;
1452
+ private settings;
1453
+ /**
1454
+ * Constructor of TeamsBotSsoPrompt.
1455
+ *
1456
+ * @param {TeamsFx} teamsfx - Used to provide configuration and auth
1457
+ * @param dialogId Unique ID of the dialog within its parent `DialogSet` or `ComponentDialog`.
1458
+ * @param settings Settings used to configure the prompt.
1459
+ *
1460
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1461
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1462
+ *
1463
+ * @beta
1464
+ */
1465
+ constructor(teamsfx: TeamsFx, dialogId: string, settings: TeamsBotSsoPromptSettings);
1466
+ /**
1467
+ * Called when a prompt dialog is pushed onto the dialog stack and is being activated.
1468
+ * @remarks
1469
+ * If the task is successful, the result indicates whether the prompt is still
1470
+ * active after the turn has been processed by the prompt.
1471
+ *
1472
+ * @param dc The DialogContext for the current turn of the conversation.
1473
+ *
1474
+ * @throws {@link ErrorCode|InvalidParameter} when timeout property in teams bot sso prompt settings is not number or is not positive.
1475
+ * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
1476
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1477
+ *
1478
+ * @returns A `Promise` representing the asynchronous operation.
1479
+ *
1480
+ * @beta
1481
+ */
1482
+ beginDialog(dc: DialogContext): Promise<DialogTurnResult>;
1483
+ /**
1484
+ * Called when a prompt dialog is the active dialog and the user replied with a new activity.
1485
+ *
1486
+ * @remarks
1487
+ * If the task is successful, the result indicates whether the dialog is still
1488
+ * active after the turn has been processed by the dialog.
1489
+ * The prompt generally continues to receive the user's replies until it accepts the
1490
+ * user's reply as valid input for the prompt.
1491
+ *
1492
+ * @param dc The DialogContext for the current turn of the conversation.
1493
+ *
1494
+ * @returns A `Promise` representing the asynchronous operation.
1495
+ *
1496
+ * @throws {@link ErrorCode|ChannelNotSupported} when bot channel is not MS Teams.
1497
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is browser.
1498
+ *
1499
+ * @beta
1500
+ */
1501
+ continueDialog(dc: DialogContext): Promise<DialogTurnResult>;
1502
+ private loadAndValidateConfig;
1503
+ /**
1504
+ * Ensure bot is running in MS Teams since TeamsBotSsoPrompt is only supported in MS Teams channel.
1505
+ * @param dc dialog context
1506
+ * @throws {@link ErrorCode|ChannelNotSupported} if bot channel is not MS Teams
1507
+ * @internal
1508
+ */
1509
+ private ensureMsTeamsChannel;
1510
+ /**
1511
+ * Send OAuthCard that tells Teams to obtain an authentication token for the bot application.
1512
+ * For details see https://docs.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/auth-aad-sso-bots.
1513
+ *
1514
+ * @internal
1515
+ */
1516
+ private sendOAuthCardAsync;
1517
+ /**
1518
+ * Get sign in resource.
1519
+ *
1520
+ * @throws {@link ErrorCode|InvalidConfiguration} if client id, tenant id or initiate login endpoint is not found in config.
1521
+ *
1522
+ * @internal
1523
+ */
1524
+ private getSignInResource;
1525
+ /**
1526
+ * @internal
1527
+ */
1528
+ private recognizeToken;
1529
+ /**
1530
+ * @internal
1531
+ */
1532
+ private getTokenExchangeInvokeResponse;
1533
+ /**
1534
+ * @internal
1535
+ */
1536
+ private isTeamsVerificationInvoke;
1537
+ /**
1538
+ * @internal
1539
+ */
1540
+ private isTokenExchangeRequestInvoke;
1541
+ /**
1542
+ * @internal
1543
+ */
1544
+ private isTokenExchangeRequest;
1545
+ }
1546
+
1547
+ /**
1548
+ * Settings used to configure an TeamsBotSsoPrompt instance.
1549
+ *
1550
+ * @beta
1551
+ */
1552
+ export declare interface TeamsBotSsoPromptSettings {
1553
+ /**
1554
+ * The array of strings that declare the desired permissions and the resources requested.
1555
+ */
1556
+ scopes: string[];
1557
+ /**
1558
+ * (Optional) number of milliseconds the prompt will wait for the user to authenticate.
1559
+ * Defaults to a value `900,000` (15 minutes.)
1560
+ */
1561
+ timeout?: number;
1562
+ /**
1563
+ * (Optional) value indicating whether the TeamsBotSsoPrompt should end upon receiving an
1564
+ * invalid message. Generally the TeamsBotSsoPrompt will end the auth flow when receives user
1565
+ * message not related to the auth flow. Setting the flag to false ignores the user's message instead.
1566
+ * Defaults to value `true`
1567
+ */
1568
+ endOnInvalidMessage?: boolean;
1569
+ }
1570
+
1571
+ /**
1572
+ * Token response provided by Teams Bot SSO prompt
1573
+ *
1574
+ * @beta
1575
+ */
1576
+ export declare interface TeamsBotSsoPromptTokenResponse extends TokenResponse {
1577
+ /**
1578
+ * SSO token for user
1579
+ */
1580
+ ssoToken: string;
1581
+ /**
1582
+ * Expire time of SSO token
1583
+ */
1584
+ ssoTokenExpiration: string;
1585
+ }
1586
+
1587
+ /**
1588
+ * A class providing credential and configuration.
1589
+ * @beta
1590
+ */
1591
+ export declare class TeamsFx implements TeamsFxConfiguration {
1592
+ private configuration;
1593
+ private oboUserCredential?;
1594
+ private appCredential?;
1595
+ private identityType;
1596
+ /**
1597
+ * Constructor of TeamsFx
1598
+ *
1599
+ * @param {IdentityType} identityType - Choose user or app identity
1600
+ * @param customConfig - key/value pairs of customized configuration that overrides default ones.
1601
+ *
1602
+ * @throws {@link ErrorCode|IdentityTypeNotSupported} when setting app identity in browser.
1603
+ *
1604
+ * @beta
1605
+ */
1606
+ constructor(identityType?: IdentityType, customConfig?: Record<string, string>);
1607
+ /**
1608
+ * Identity type set by user.
1609
+ *
1610
+ * @returns identity type.
1611
+ * @beta
1612
+ */
1613
+ getIdentityType(): IdentityType;
1614
+ /**
1615
+ * Credential instance according to identity type choice.
1616
+ *
1617
+ * @remarks If user identity is chose, will return {@link TeamsUserCredential}
1618
+ * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
1619
+ * identity is chose, will return {@link AppCredential}.
1620
+ *
1621
+ * @returns instance implements TokenCredential interface.
1622
+ * @beta
1623
+ */
1624
+ getCredential(): TokenCredential;
1625
+ /**
1626
+ * Get user information.
1627
+ * @returns UserInfo object.
1628
+ * @beta
1629
+ */
1630
+ getUserInfo(): Promise<UserInfo>;
1631
+ /**
1632
+ * Popup login page to get user's access token with specific scopes.
1633
+ *
1634
+ * @remarks
1635
+ * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
1636
+ *
1637
+ * @example
1638
+ * ```typescript
1639
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
1640
+ * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
1641
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
1642
+ * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
1643
+ * ```
1644
+ * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
1645
+ *
1646
+ * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
1647
+ * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
1648
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1649
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1650
+ *
1651
+ * @beta
1652
+ */
1653
+ login(scopes: string | string[]): Promise<void>;
1654
+ /**
1655
+ * Set SSO token when using user identity in NodeJS.
1656
+ * @param {string} ssoToken - used for on behalf of user flow.
1657
+ * @returns self instance.
1658
+ * @beta
1659
+ */
1660
+ setSsoToken(ssoToken: string): TeamsFx;
1661
+ /**
1662
+ * Usually used by service plugins to retrieve specific config
1663
+ * @param {string} key - configuration key.
1664
+ * @returns value in configuration.
1665
+ * @beta
1666
+ */
1667
+ getConfig(key: string): string;
1668
+ /**
1669
+ * Check the value of specific key.
1670
+ * @param {string} key - configuration key.
1671
+ * @returns true if corresponding value is not empty string.
1672
+ * @beta
1673
+ */
1674
+ hasConfig(key: string): boolean;
1675
+ /**
1676
+ * Get all configurations.
1677
+ * @returns key value mappings.
1678
+ * @beta
1679
+ */
1680
+ getConfigs(): Record<string, string>;
1681
+ /**
1682
+ * Load configuration from environment variables.
1683
+ */
1684
+ private loadFromEnv;
1685
+ }
1686
+
1687
+ /**
1688
+ * Interface for a command handler that can process command to a TeamsFx bot and return a response.
1689
+ *
1690
+ * @beta
1691
+ */
1692
+ export declare interface TeamsFxBotCommandHandler {
1693
+ /**
1694
+ * The string or regular expression patterns that can trigger this handler.
1695
+ */
1696
+ triggerPatterns: TriggerPatterns;
1697
+ /**
1698
+ * Handles a bot command received activity.
1699
+ *
1700
+ * @param context The bot context.
1701
+ * @param message The command message the user types from Teams.
1702
+ * @returns A `Promise` representing an activity or text to send as the command response.
1703
+ */
1704
+ handleCommandReceived(context: TurnContext, message: CommandMessage): Promise<string | Partial<Activity>>;
1705
+ }
1706
+
1707
+ /**
1708
+ * TeamsFx interface that provides credential and configuration.
1709
+ * @beta
1710
+ */
1711
+ declare interface TeamsFxConfiguration {
1712
+ /**
1713
+ * Identity type set by user.
1714
+ *
1715
+ * @returns identity type.
1716
+ * @beta
1717
+ */
1718
+ getIdentityType(): IdentityType;
1719
+ /**
1720
+ * Credential instance according to identity type choice.
1721
+ *
1722
+ * @remarks If user identity is chose, will return {@link TeamsUserCredential}
1723
+ * in browser environment and {@link OnBehalfOfUserCredential} in NodeJS. If app
1724
+ * identity is chose, will return {@link AppCredential}.
1725
+ *
1726
+ * @returns instance implements TokenCredential interface.
1727
+ * @beta
1728
+ */
1729
+ getCredential(): TokenCredential;
1730
+ /**
1731
+ * Get user information.
1732
+ * @returns UserInfo object.
1733
+ * @beta
1734
+ */
1735
+ getUserInfo(): Promise<UserInfo>;
1736
+ /**
1737
+ * Popup login page to get user's access token with specific scopes.
1738
+ *
1739
+ * @remarks
1740
+ * Only works in Teams client APP. User will be redirected to the authorization page to login and consent.
1741
+ *
1742
+ * @example
1743
+ * ```typescript
1744
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read"]); // single scope using string array
1745
+ * await teamsfx.login("https://graph.microsoft.com/User.Read"); // single scopes using string
1746
+ * await teamsfx.login(["https://graph.microsoft.com/User.Read", "Calendars.Read"]); // multiple scopes using string array
1747
+ * await teamsfx.login("https://graph.microsoft.com/User.Read Calendars.Read"); // multiple scopes using string
1748
+ * ```
1749
+ * @param scopes - The list of scopes for which the token will have access, before that, we will request user to consent.
1750
+ *
1751
+ * @throws {@link ErrorCode|InternalError} when failed to login with unknown error.
1752
+ * @throws {@link ErrorCode|ConsentFailed} when user canceled or failed to consent.
1753
+ * @throws {@link ErrorCode|InvalidParameter} when scopes is not a valid string or string array.
1754
+ * @throws {@link ErrorCode|RuntimeNotSupported} when runtime is nodeJS.
1755
+ *
1756
+ * @beta
1757
+ */
1758
+ login(scopes: string | string[]): Promise<void>;
1759
+ /**
1760
+ * Set SSO token when using user identity in NodeJS.
1761
+ * @param {string} ssoToken - used for on behalf of user flow.
1762
+ * @returns self instance.
1763
+ * @beta
1764
+ */
1765
+ setSsoToken(ssoToken: string): TeamsFxConfiguration;
1766
+ /**
1767
+ * Usually used by service plugins to retrieve specific config
1768
+ * @param {string} key - configuration key.
1769
+ * @returns value in configuration.
1770
+ * @beta
1771
+ */
1772
+ getConfig(key: string): string;
1773
+ /**
1774
+ * Check the value of specific key.
1775
+ * @param {string} key - configuration key.
1776
+ * @returns true if corresponding value is not empty string.
1777
+ * @beta
1778
+ */
1779
+ hasConfig(key: string): boolean;
1780
+ /**
1781
+ * Get all configurations.
1782
+ * @returns key value mappings.
1783
+ * @beta
1784
+ */
1785
+ getConfigs(): Record<string, string>;
1786
+ }
1787
+
1788
+ /**
1789
+ * Represent Teams current user's identity, and it is used within Teams client applications.
1790
+ *
1791
+ * @remarks
1792
+ * Can only be used within Teams.
1793
+ *
1794
+ * @beta
1795
+ */
1796
+ export declare class TeamsUserCredential implements TokenCredential {
1797
+ /**
1798
+ * Constructor of TeamsUserCredential.
1799
+ * @remarks
1800
+ * Can only be used within Teams.
1801
+ * @beta
1802
+ */
1803
+ constructor(authConfig: AuthenticationConfiguration);
1804
+ /**
1805
+ * Popup login page to get user's access token with specific scopes.
1806
+ * @remarks
1807
+ * Can only be used within Teams.
1808
+ * @beta
1809
+ */
1810
+ login(scopes: string | string[]): Promise<void>;
1811
+ /**
1812
+ * Get access token from credential.
1813
+ * @remarks
1814
+ * Can only be used within Teams.
1815
+ * @beta
1816
+ */
1817
+ getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
1818
+ /**
1819
+ * Get basic user info from SSO token
1820
+ * @remarks
1821
+ * Can only be used within Teams.
1822
+ * @beta
1823
+ */
1824
+ getUserInfo(): Promise<UserInfo>;
1825
+ }
1826
+
1827
+ /**
1828
+ * The trigger pattern used to trigger a {@link TeamsFxBotCommandHandler} instance.
1829
+ */
1830
+ export declare type TriggerPatterns = string | RegExp | (string | RegExp)[];
1831
+
1832
+ /**
1833
+ * UserInfo with user displayName, objectId and preferredUserName.
1834
+ *
1835
+ * @beta
1836
+ */
1837
+ export declare interface UserInfo {
1838
+ /**
1839
+ * User Display Name.
1840
+ *
1841
+ * @readonly
1842
+ */
1843
+ displayName: string;
1844
+ /**
1845
+ * User unique reference within the Azure Active Directory domain.
1846
+ *
1847
+ * @readonly
1848
+ */
1849
+ objectId: string;
1850
+ /**
1851
+ * Usually be the email address.
1852
+ *
1853
+ * @readonly
1854
+ */
1855
+ preferredUserName: string;
1856
+ }
957
1857
 
958
- export { }
1858
+ export { }