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