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