1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | import { BotFrameworkHttpAdapter } from './botFrameworkHttpAdapter';
|
9 | import { ConnectorClientBuilder, Request, Response, WebRequest, WebResponse } from './interfaces';
|
10 | import { Activity, BotAdapter, ChannelAccount, ConversationParameters, ConversationReference, ConversationsResult, CoreAppCredentials, ExtendedUserTokenProvider, ResourceResponse, TokenResponse, TurnContext } from 'botbuilder-core';
|
11 | import { AppCredentials, AuthenticationConfiguration, ClaimsIdentity, ConnectorClient, ConnectorClientOptions, SignInUrlResponse, SimpleCredentialProvider, TokenApiClient, TokenExchangeRequest, TokenStatus } from 'botframework-connector';
|
12 | import { INodeBuffer, INodeSocket, IReceiveRequest, NodeWebSocketFactoryBase, RequestHandler, StreamingResponse } from 'botframework-streaming';
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | export interface BotFrameworkAdapterSettings {
|
18 | |
19 |
|
20 |
|
21 | appId: string;
|
22 | |
23 |
|
24 |
|
25 | appPassword: string;
|
26 | |
27 |
|
28 |
|
29 | channelAuthTenant?: string;
|
30 | |
31 |
|
32 |
|
33 | oAuthEndpoint?: string;
|
34 | |
35 |
|
36 |
|
37 | openIdMetadata?: string;
|
38 | |
39 |
|
40 |
|
41 | channelService?: string;
|
42 | |
43 |
|
44 |
|
45 | webSocketFactory?: NodeWebSocketFactoryBase;
|
46 | |
47 |
|
48 |
|
49 | certificateThumbprint?: string;
|
50 | |
51 |
|
52 |
|
53 | certificatePrivateKey?: string;
|
54 | |
55 |
|
56 |
|
57 | authConfig?: AuthenticationConfiguration;
|
58 | |
59 |
|
60 |
|
61 | clientOptions?: ConnectorClientOptions;
|
62 | }
|
63 | export declare const USER_AGENT: string;
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | export declare class BotFrameworkAdapter extends BotAdapter implements BotFrameworkHttpAdapter, ConnectorClientBuilder, ExtendedUserTokenProvider, RequestHandler {
|
102 | readonly TokenApiClientCredentialsKey: symbol;
|
103 | protected readonly credentials: AppCredentials;
|
104 | protected readonly credentialsProvider: SimpleCredentialProvider;
|
105 | protected readonly settings: BotFrameworkAdapterSettings;
|
106 | private isEmulatingOAuthCards;
|
107 | private logic;
|
108 | private streamingServer;
|
109 | private webSocketFactory;
|
110 | private authConfiguration;
|
111 | private namedPipeName?;
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | constructor(settings?: Partial<BotFrameworkAdapterSettings>);
|
129 | /**
|
130 | * Used in streaming contexts to check if the streaming connection is still open for the bot to send activities.
|
131 | *
|
132 | * @returns True if the streaming connection is open, otherwise false.
|
133 | */
|
134 | get isStreamingConnectionOpen(): boolean;
|
135 | /**
|
136 | * Asynchronously resumes a conversation with a user, possibly after some time has gone by.
|
137 | *
|
138 | * @param reference A reference to the conversation to continue.
|
139 | * @param oAuthScope The intended recipient of any sent activities.
|
140 | * @param logic The asynchronous method to call after the adapter middleware runs.
|
141 | *
|
142 | * @remarks
|
143 | * This is often referred to as a _proactive notification_, the bot can proactively
|
144 | * send a message to a conversation or user without waiting for an incoming message.
|
145 | * For example, a bot can use this method to send notifications or coupons to a user.
|
146 | *
|
147 | * To send a proactive message:
|
148 | * 1. Save a copy of a [ConversationReference](xref:botframework-schema.ConversationReference)
|
149 | * from an incoming activity. For example, you can store the conversation reference in a database.
|
150 | * 1. Call this method to resume the conversation at a later time. Use the saved reference to access the conversation.
|
151 | * 1. On success, the adapter generates a [TurnContext](xref:botbuilder-core.TurnContext) object and calls the `logic` function handler.
|
152 | * Use the `logic` function to send the proactive message.
|
153 | *
|
154 | * To copy the reference from any incoming activity in the conversation, use the
|
155 | * [TurnContext.getConversationReference](xref:botbuilder-core.TurnContext.getConversationReference) method.
|
156 | *
|
157 | * This method is similar to the [processActivity](xref:botbuilder.BotFrameworkAdapter.processActivity) method.
|
158 | * The adapter creates a [TurnContext](xref:botbuilder-core.TurnContext) and routes it through
|
159 | * its middleware before calling the `logic` handler. The created activity will have a
|
160 | * [type](xref:botframework-schema.Activity.type) of 'event' and a
|
161 | * [name](xref:botframework-schema.Activity.name) of 'continueConversation'.
|
162 | *
|
163 | * For example:
|
164 | * ```JavaScript
|
165 | * server.post('/api/notifyUser', async (req, res) => {
|
166 | *
|
167 | * const reference = await findReference(req.body.refId);
|
168 | *
|
169 | *
|
170 | * if (reference) {
|
171 | * await adapter.continueConversation(reference, async (context) => {
|
172 | * await context.sendActivity(req.body.message);
|
173 | * });
|
174 | * res.send(200);
|
175 | * } else {
|
176 | * res.send(404);
|
177 | * }
|
178 | * });
|
179 | * ```
|
180 | */
|
181 | continueConversation(reference: Partial<ConversationReference>, logic: (context: TurnContext) => Promise<void>): Promise<void>;
|
182 | /**
|
183 | * Asynchronously resumes a conversation with a user, possibly after some time has gone by.
|
184 | *
|
185 | * @param reference [ConversationReference](xref:botframework-schema.ConversationReference) of the conversation to continue.
|
186 | * @param oAuthScope The intended recipient of any sent activities or the function to call to continue the conversation.
|
187 | * @param logic Optional. The asynchronous method to call after the adapter middleware runs.
|
188 | */
|
189 | continueConversation(reference: Partial<ConversationReference>, oAuthScope: string, logic: (context: TurnContext) => Promise<void>): Promise<void>;
|
190 | /**
|
191 | * Asynchronously creates and starts a conversation with a user on a channel.
|
192 | *
|
193 | * @param {Partial<ConversationReference>} reference A reference for the conversation to create.
|
194 | * @param {(context: TurnContext) => Promise<void>} logic The asynchronous method to call after the adapter middleware runs.
|
195 | * @returns {Promise<void>} a promise representing the asynchronous operation
|
196 | *
|
197 | * @summary
|
198 | * To use this method, you need both the bot's and the user's account information on a channel.
|
199 | * The Bot Connector service supports the creating of group conversations; however, this
|
200 | * method and most channels only support initiating a direct message (non-group) conversation.
|
201 | *
|
202 | * To create and start a new conversation:
|
203 | * 1. Get a copy of a [ConversationReference](xref:botframework-schema.ConversationReference) from an incoming activity.
|
204 | * 1. Set the [user](xref:botframework-schema.ConversationReference.user) property to the
|
205 | * [ChannelAccount](xref:botframework-schema.ChannelAccount) value for the intended recipient.
|
206 | * 1. Call this method to request that the channel create a new conversation with the specified user.
|
207 | * 1. On success, the adapter generates a turn context and calls the `logic` function handler.
|
208 | *
|
209 | * To get the initial reference, use the
|
210 | * [TurnContext.getConversationReference](xref:botbuilder-core.TurnContext.getConversationReference)
|
211 | * method on any incoming activity in the conversation.
|
212 | *
|
213 | * If the channel establishes the conversation, the generated event activity's
|
214 | * [conversation](xref:botframework-schema.Activity.conversation) property will contain the
|
215 | * ID of the new conversation.
|
216 | *
|
217 | * This method is similar to the [processActivity](xref:botbuilder.BotFrameworkAdapter.processActivity) method.
|
218 | * The adapter creates a [TurnContext](xref:botbuilder-core.TurnContext) and routes it through
|
219 | * middleware before calling the `logic` handler. The created activity will have a
|
220 | * [type](xref:botframework-schema.Activity.type) of 'event' and a
|
221 | * [name](xref:botframework-schema.Activity.name) of 'createConversation'.
|
222 | *
|
223 | * For example:
|
224 | * ```JavaScript
|
225 | * // Get group members conversation reference
|
226 | * const reference = TurnContext.getConversationReference(context.activity);
|
227 | *
|
228 | *
|
229 | *
|
230 | * await adapter.createConversation(reference, async (ctx) => {
|
231 | * await ctx.sendActivity(`Hi (in private)`);
|
232 | * });
|
233 | * ```
|
234 | */
|
235 | createConversation(reference: Partial<ConversationReference>, logic: (context: TurnContext) => Promise<void>): Promise<void>;
|
236 | /**
|
237 | * Asynchronously creates and starts a conversation with a user on a channel.
|
238 | *
|
239 | * @param {Partial<ConversationReference>} reference A reference for the conversation to create.
|
240 | * @param {Partial<ConversationParameters>} parameters Parameters used when creating the conversation
|
241 | * @param {(context: TurnContext) => Promise<void>} logic The asynchronous method to call after the adapter middleware runs.
|
242 | * @returns {Promise<void>} a promise representing the asynchronous operation
|
243 | */
|
244 | createConversation(reference: Partial<ConversationReference>, parameters: Partial<ConversationParameters>, logic: (context: TurnContext) => Promise<void>): Promise<void>;
|
245 | /**
|
246 | * Asynchronously deletes an existing activity.
|
247 | *
|
248 | * This interface supports the framework and is not intended to be called directly for your code.
|
249 | * Use [TurnContext.deleteActivity](xref:botbuilder-core.TurnContext.deleteActivity) to delete
|
250 | * an activity from your bot code.
|
251 | *
|
252 | * @param context The context object for the turn.
|
253 | * @param reference Conversation reference information for the activity to delete.
|
254 | *
|
255 | * @remarks
|
256 | * Not all channels support this operation. For channels that don't, this call may throw an exception.
|
257 | */
|
258 | deleteActivity(context: TurnContext, reference: Partial<ConversationReference>): Promise<void>;
|
259 | /**
|
260 | * Asynchronously removes a member from the current conversation.
|
261 | *
|
262 | * @param context The context object for the turn.
|
263 | * @param memberId The ID of the member to remove from the conversation.
|
264 | *
|
265 | * @remarks
|
266 | * Remove a member's identity information from the conversation.
|
267 | *
|
268 | * Not all channels support this operation. For channels that don't, this call may throw an exception.
|
269 | */
|
270 | deleteConversationMember(context: TurnContext, memberId: string): Promise<void>;
|
271 | /**
|
272 | * Asynchronously lists the members of a given activity.
|
273 | *
|
274 | * @param context The context object for the turn.
|
275 | * @param activityId Optional. The ID of the activity to get the members of. If not specified, the current activity ID is used.
|
276 | *
|
277 | * @returns An array of [ChannelAccount](xref:botframework-schema.ChannelAccount) objects for
|
278 | * the users involved in a given activity.
|
279 | *
|
280 | * @remarks
|
281 | * Returns an array of [ChannelAccount](xref:botframework-schema.ChannelAccount) objects for
|
282 | * the users involved in a given activity.
|
283 | *
|
284 | * This is different from [getConversationMembers](xref:botbuilder.BotFrameworkAdapter.getConversationMembers)
|
285 | * in that it will return only those users directly involved in the activity, not all members of the conversation.
|
286 | */
|
287 | getActivityMembers(context: TurnContext, activityId?: string): Promise<ChannelAccount[]>;
|
288 | /**
|
289 | * Asynchronously lists the members of the current conversation.
|
290 | *
|
291 | * @param context The context object for the turn.
|
292 | *
|
293 | * @returns An array of [ChannelAccount](xref:botframework-schema.ChannelAccount) objects for
|
294 | * all users currently involved in a conversation.
|
295 | *
|
296 | * @remarks
|
297 | * Returns an array of [ChannelAccount](xref:botframework-schema.ChannelAccount) objects for
|
298 | * all users currently involved in a conversation.
|
299 | *
|
300 | * This is different from [getActivityMembers](xref:botbuilder.BotFrameworkAdapter.getActivityMembers)
|
301 | * in that it will return all members of the conversation, not just those directly involved in a specific activity.
|
302 | */
|
303 | getConversationMembers(context: TurnContext): Promise<ChannelAccount[]>;
|
304 | /**
|
305 | * For the specified channel, asynchronously gets a page of the conversations in which this bot has participated.
|
306 | *
|
307 | * @param contextOrServiceUrl The URL of the channel server to query or a
|
308 | * [TurnContext](xref:botbuilder-core.TurnContext) object from a conversation on the channel.
|
309 | * @param continuationToken Optional. The continuation token from the previous page of results.
|
310 | * Omit this parameter or use `undefined` to retrieve the first page of results.
|
311 | *
|
312 | * @returns A [ConversationsResult](xref:botframework-schema.ConversationsResult) object containing a page of results
|
313 | * and a continuation token.
|
314 | *
|
315 | * @remarks
|
316 | * The the return value's [conversations](xref:botframework-schema.ConversationsResult.conversations) property contains a page of
|
317 | * [ConversationMembers](xref:botframework-schema.ConversationMembers) objects. Each object's
|
318 | * [id](xref:botframework-schema.ConversationMembers.id) is the ID of a conversation in which the bot has participated on this channel.
|
319 | * This method can be called from outside the context of a conversation, as only the bot's service URL and credentials are required.
|
320 | *
|
321 | * The channel batches results in pages. If the result's
|
322 | * [continuationToken](xref:botframework-schema.ConversationsResult.continuationToken) property is not empty, then
|
323 | * there are more pages to get. Use the returned token to get the next page of results.
|
324 | * If the `contextOrServiceUrl` parameter is a [TurnContext](xref:botbuilder-core.TurnContext), the URL of the channel server is
|
325 | * retrieved from
|
326 | * `contextOrServiceUrl`.[activity](xref:botbuilder-core.TurnContext.activity).[serviceUrl](xref:botframework-schema.Activity.serviceUrl).
|
327 | */
|
328 | getConversations(contextOrServiceUrl: TurnContext | string, continuationToken?: string): Promise<ConversationsResult>;
|
329 | /**
|
330 | * Asynchronously attempts to retrieve the token for a user that's in a login flow.
|
331 | *
|
332 | * @param context The context object for the turn.
|
333 | * @param connectionName The name of the auth connection to use.
|
334 | * @param magicCode Optional. The validation code the user entered.
|
335 | * @param oAuthAppCredentials AppCredentials for OAuth.
|
336 | *
|
337 | * @returns A [TokenResponse](xref:botframework-schema.TokenResponse) object that contains the user token.
|
338 | */
|
339 | getUserToken(context: TurnContext, connectionName: string, magicCode?: string): Promise<TokenResponse>;
|
340 | getUserToken(context: TurnContext, connectionName: string, magicCode?: string, oAuthAppCredentials?: CoreAppCredentials): Promise<TokenResponse>;
|
341 | /**
|
342 | * Asynchronously signs out the user from the token server.
|
343 | *
|
344 | * @param context The context object for the turn.
|
345 | * @param connectionName The name of the auth connection to use.
|
346 | * @param userId The ID of user to sign out.
|
347 | * @param oAuthAppCredentials AppCredentials for OAuth.
|
348 | */
|
349 | signOutUser(context: TurnContext, connectionName?: string, userId?: string): Promise<void>;
|
350 | signOutUser(context: TurnContext, connectionName?: string, userId?: string, oAuthAppCredentials?: CoreAppCredentials): Promise<void>;
|
351 | /**
|
352 | * Asynchronously gets a sign-in link from the token server that can be sent as part
|
353 | * of a [SigninCard](xref:botframework-schema.SigninCard).
|
354 | *
|
355 | * @param context The context object for the turn.
|
356 | * @param connectionName The name of the auth connection to use.
|
357 | * @param oAuthAppCredentials AppCredentials for OAuth.
|
358 | * @param userId The user id that will be associated with the token.
|
359 | * @param finalRedirect The final URL that the OAuth flow will redirect to.
|
360 | */
|
361 | getSignInLink(context: TurnContext, connectionName: string, oAuthAppCredentials?: AppCredentials, userId?: string, finalRedirect?: string): Promise<string>;
|
362 | getSignInLink(context: TurnContext, connectionName: string, oAuthAppCredentials?: CoreAppCredentials, userId?: string, finalRedirect?: string): Promise<string>;
|
363 | /**
|
364 | * Asynchronously retrieves the token status for each configured connection for the given user.
|
365 | *
|
366 | * @param context The context object for the turn.
|
367 | * @param userId Optional. If present, the ID of the user to retrieve the token status for.
|
368 | * Otherwise, the ID of the user who sent the current activity is used.
|
369 | * @param includeFilter Optional. A comma-separated list of connection's to include. If present,
|
370 | * the `includeFilter` parameter limits the tokens this method returns.
|
371 | * @param oAuthAppCredentials AppCredentials for OAuth.
|
372 | *
|
373 | * @returns The [TokenStatus](xref:botframework-connector.TokenStatus) objects retrieved.
|
374 | */
|
375 | getTokenStatus(context: TurnContext, userId?: string, includeFilter?: string): Promise<TokenStatus[]>;
|
376 | getTokenStatus(context: TurnContext, userId?: string, includeFilter?: string, oAuthAppCredentials?: CoreAppCredentials): Promise<TokenStatus[]>;
|
377 | /**
|
378 | * Asynchronously signs out the user from the token server.
|
379 | *
|
380 | * @param context The context object for the turn.
|
381 | * @param connectionName The name of the auth connection to use.
|
382 | * @param resourceUrls The list of resource URLs to retrieve tokens for.
|
383 | * @param oAuthAppCredentials AppCredentials for OAuth.
|
384 | *
|
385 | * @returns A map of the [TokenResponse](xref:botframework-schema.TokenResponse) objects by resource URL.
|
386 | */
|
387 | getAadTokens(context: TurnContext, connectionName: string, resourceUrls: string[]): Promise<{
|
388 | [propertyName: string]: TokenResponse;
|
389 | }>;
|
390 | getAadTokens(context: TurnContext, connectionName: string, resourceUrls: string[], oAuthAppCredentials?: CoreAppCredentials): Promise<{
|
391 | [propertyName: string]: TokenResponse;
|
392 | }>;
|
393 | /**
|
394 | * Asynchronously Get the raw signin resource to be sent to the user for signin.
|
395 | *
|
396 | * @param context The context object for the turn.
|
397 | * @param connectionName The name of the auth connection to use.
|
398 | * @param userId The user id that will be associated with the token.
|
399 | * @param finalRedirect The final URL that the OAuth flow will redirect to.
|
400 | * @param appCredentials Optional. The CoreAppCredentials for OAuth.
|
401 | * @returns The [BotSignInGetSignInResourceResponse](xref:botframework-connector.BotSignInGetSignInResourceResponse) object.
|
402 | */
|
403 | getSignInResource(context: TurnContext, connectionName: string, userId?: string, finalRedirect?: string, appCredentials?: CoreAppCredentials): Promise<SignInUrlResponse>;
|
404 | /**
|
405 | * Asynchronously Performs a token exchange operation such as for single sign-on.
|
406 | *
|
407 | * @param context Context for the current turn of conversation with the user.
|
408 | * @param connectionName Name of the auth connection to use.
|
409 | * @param userId The user id that will be associated with the token.
|
410 | * @param tokenExchangeRequest The exchange request details, either a token to exchange or a uri to exchange.
|
411 | * @param appCredentials Optional. The CoreAppCredentials for OAuth.
|
412 | */
|
413 | exchangeToken(context: TurnContext, connectionName: string, userId: string, tokenExchangeRequest: TokenExchangeRequest, appCredentials?: CoreAppCredentials): Promise<TokenResponse>;
|
414 | /**
|
415 | * Asynchronously sends an emulated OAuth card for a channel.
|
416 | *
|
417 | * This method supports the framework and is not intended to be called directly for your code.
|
418 | *
|
419 | * @param contextOrServiceUrl The URL of the emulator.
|
420 | * @param emulate `true` to send an emulated OAuth card to the emulator; or `false` to not send the card.
|
421 | *
|
422 | * @remarks
|
423 | * When testing a bot in the Bot Framework Emulator, this method can emulate the OAuth card interaction.
|
424 | */
|
425 | emulateOAuthCards(contextOrServiceUrl: TurnContext | string, emulate: boolean): Promise<void>;
|
426 | /**
|
427 | * Asynchronously creates a turn context and runs the middleware pipeline for an incoming activity.
|
428 | *
|
429 | * @param req An Express or Restify style request object.
|
430 | * @param res An Express or Restify style response object.
|
431 | * @param logic The function to call at the end of the middleware pipeline.
|
432 | *
|
433 | * @remarks
|
434 | * This is the main way a bot receives incoming messages and defines a turn in the conversation. This method:
|
435 | *
|
436 | * 1. Parses and authenticates an incoming request.
|
437 | * - The activity is read from the body of the incoming request. An error will be returned
|
438 | * if the activity can't be parsed.
|
439 | * - The identity of the sender is authenticated as either the Emulator or a valid Microsoft
|
440 | * server, using the bot's `appId` and `appPassword`. The request is rejected if the sender's
|
441 | * identity is not verified.
|
442 | * 1. Creates a [TurnContext](xref:botbuilder-core.TurnContext) object for the received activity.
|
443 | * - This object is wrapped with a [revocable proxy](https://www.ecma-international.org/ecma-262/6.0/#sec-proxy.revocable).
|
444 | * - When this method completes, the proxy is revoked.
|
445 | * 1. Sends the turn context through the adapter's middleware pipeline.
|
446 | * 1. Sends the turn context to the `logic` function.
|
447 | * - The bot may perform additional routing or processing at this time.
|
448 | * Returning a promise (or providing an `async` handler) will cause the adapter to wait for any asynchronous operations to complete.
|
449 | * - After the `logic` function completes, the promise chain set up by the middleware is resolved.
|
450 | *
|
451 | * > [!TIP]
|
452 | * > If you see the error `TypeError: Cannot perform 'set' on a proxy that has been revoked`
|
453 | * > in your bot's console output, the likely cause is that an async function was used
|
454 | * > without using the `await` keyword. Make sure all async functions use await!
|
455 | *
|
456 | * Middleware can _short circuit_ a turn. When this happens, subsequent middleware and the
|
457 | * `logic` function is not called; however, all middleware prior to this point still run to completion.
|
458 | * For more information about the middleware pipeline, see the
|
459 | * [how bots work](https://docs.microsoft.com/azure/bot-service/bot-builder-basics) and
|
460 | * [middleware](https://docs.microsoft.com/azure/bot-service/bot-builder-concept-middleware) articles.
|
461 | * Use the adapter's [use](xref:botbuilder-core.BotAdapter.use) method to add middleware to the adapter.
|
462 | *
|
463 | * For example:
|
464 | * ```JavaScript
|
465 | * server.post('/api/messages', (req, res) => {
|
466 | *
|
467 | * adapter.processActivity(req, res, async (context) => {
|
468 | *
|
469 | * if (context.activity.type === ActivityTypes.Message) {
|
470 | * await context.sendActivity(`Hello World`);
|
471 | * }
|
472 | * });
|
473 | * });
|
474 | * ```
|
475 | */
|
476 | processActivity(req: WebRequest, res: WebResponse, logic: (context: TurnContext) => Promise<any>): Promise<void>;
|
477 | /**
|
478 | * Asynchronously creates a turn context and runs the middleware pipeline for an incoming activity.
|
479 | *
|
480 | * Use [CloudAdapter.processActivityDirect] instead.
|
481 | *
|
482 | * @param activity The activity to process.
|
483 | * @param logic The function to call at the end of the middleware pipeline.
|
484 | *
|
485 | * @remarks
|
486 | * This is the main way a bot receives incoming messages and defines a turn in the conversation. This method:
|
487 | *
|
488 | * 1. Creates a [TurnContext](xref:botbuilder-core.TurnContext) object for the received activity.
|
489 | * - This object is wrapped with a [revocable proxy](https://www.ecma-international.org/ecma-262/6.0/#sec-proxy.revocable).
|
490 | * - When this method completes, the proxy is revoked.
|
491 | * 1. Sends the turn context through the adapter's middleware pipeline.
|
492 | * 1. Sends the turn context to the `logic` function.
|
493 | * - The bot may perform additional routing or processing at this time.
|
494 | * Returning a promise (or providing an `async` handler) will cause the adapter to wait for any asynchronous operations to complete.
|
495 | * - After the `logic` function completes, the promise chain set up by the middleware is resolved.
|
496 | *
|
497 | * Middleware can _short circuit_ a turn. When this happens, subsequent middleware and the
|
498 | * `logic` function is not called; however, all middleware prior to this point still run to completion.
|
499 | * For more information about the middleware pipeline, see the
|
500 | * [how bots work](https://docs.microsoft.com/azure/bot-service/bot-builder-basics) and
|
501 | * [middleware](https://docs.microsoft.com/azure/bot-service/bot-builder-concept-middleware) articles.
|
502 | * Use the adapter's [use](xref:botbuilder-core.BotAdapter.use) method to add middleware to the adapter.
|
503 | */
|
504 | processActivityDirect(activity: Activity, logic: (context: TurnContext) => Promise<any>): Promise<void>;
|
505 | /**
|
506 | * Asynchronously sends a set of outgoing activities to a channel server.
|
507 | *
|
508 | * This method supports the framework and is not intended to be called directly for your code.
|
509 | * Use the turn context's [sendActivity](xref:botbuilder-core.TurnContext.sendActivity) or
|
510 | * [sendActivities](xref:botbuilder-core.TurnContext.sendActivities) method from your bot code.
|
511 | *
|
512 | * @param context The context object for the turn.
|
513 | * @param activities The activities to send.
|
514 | *
|
515 | * @returns An array of [ResourceResponse](xref:)
|
516 | *
|
517 | * @remarks
|
518 | * The activities will be sent one after another in the order in which they're received. A
|
519 | * response object will be returned for each sent activity. For `message` activities this will
|
520 | * contain the ID of the delivered message.
|
521 | */
|
522 | sendActivities(context: TurnContext, activities: Partial<Activity>[]): Promise<ResourceResponse[]>;
|
523 | /**
|
524 | * Asynchronously replaces a previous activity with an updated version.
|
525 | *
|
526 | * This interface supports the framework and is not intended to be called directly for your code.
|
527 | * Use [TurnContext.updateActivity](xref:botbuilder-core.TurnContext.updateActivity) to update
|
528 | * an activity from your bot code.
|
529 | *
|
530 | * @param context The context object for the turn.
|
531 | * @param activity The updated version of the activity to replace.
|
532 | * @returns A `Promise` representing the [ResourceResponse](xref:botframework-schema.ResourceResponse) for the operation.
|
533 | * @remarks
|
534 | * Not all channels support this operation. For channels that don't, this call may throw an exception.
|
535 | */
|
536 | updateActivity(context: TurnContext, activity: Partial<Activity>): Promise<ResourceResponse | void>;
|
537 | /**
|
538 | * Creates a connector client.
|
539 | *
|
540 | * @param serviceUrl The client's service URL.
|
541 | * @returns The [ConnectorClient](xref:botbuilder-connector.ConnectorClient) instance.
|
542 | * @remarks
|
543 | * Override this in a derived class to create a mock connector client for unit testing.
|
544 | */
|
545 | createConnectorClient(serviceUrl: string): ConnectorClient;
|
546 | /**
|
547 | * Create a ConnectorClient with a ClaimsIdentity.
|
548 | *
|
549 | * @remarks
|
550 | * If the ClaimsIdentity contains the claims for a Skills request, create a ConnectorClient for use with Skills.
|
551 | * Derives the correct audience from the ClaimsIdentity, or the instance's credentials property.
|
552 | * @param serviceUrl The client's service URL.
|
553 | * @param identity ClaimsIdentity
|
554 | */
|
555 | createConnectorClientWithIdentity(serviceUrl: string, identity: ClaimsIdentity): Promise<ConnectorClient>;
|
556 | /**
|
557 | * Create a ConnectorClient with a ClaimsIdentity and an explicit audience.
|
558 | *
|
559 | * @remarks
|
560 | * If the trimmed audience is not a non-zero length string, the audience will be derived from the ClaimsIdentity or
|
561 | * the instance's credentials property.
|
562 | * @param serviceUrl The client's service URL.
|
563 | * @param identity ClaimsIdentity
|
564 | * @param audience The recipient of the ConnectorClient's messages. Normally the Bot Framework Channel Service or the AppId of another bot.
|
565 | */
|
566 | createConnectorClientWithIdentity(serviceUrl: string, identity: ClaimsIdentity, audience: string): Promise<ConnectorClient>;
|
567 | private createConnectorClientInternal;
|
568 | private getClientOptions;
|
569 | private getOrCreateConnectorClient;
|
570 | /**
|
571 | * Returns the correct [OAuthScope](xref:botframework-connector.AppCredentials.OAuthScope) for [AppCredentials](xref:botframework-connector.AppCredentials).
|
572 | *
|
573 | * @param botAppId The bot's AppId.
|
574 | * @param claims The [Claim](xref:botbuilder-connector.Claim) list to check.
|
575 | *
|
576 | * @returns The current credentials' OAuthScope.
|
577 | */
|
578 | private getOAuthScope;
|
579 | /**
|
580 | *
|
581 | * @remarks
|
582 | * When building credentials for bot-to-bot communication, oAuthScope must be passed in.
|
583 | * @param appId The application id.
|
584 | * @param oAuthScope The optional OAuth scope.
|
585 | * @returns The app credentials to be used to acquire tokens.
|
586 | */
|
587 | protected buildCredentials(appId: string, oAuthScope?: string): Promise<AppCredentials>;
|
588 | /**
|
589 | * Creates an OAuth API client.
|
590 | *
|
591 | * @param serviceUrl The client's service URL.
|
592 | * @param oAuthAppCredentials AppCredentials for OAuth.
|
593 | *
|
594 | * @remarks
|
595 | * Override this in a derived class to create a mock OAuth API client for unit testing.
|
596 | */
|
597 | protected createTokenApiClient(serviceUrl: string, oAuthAppCredentials?: CoreAppCredentials): TokenApiClient;
|
598 | /**
|
599 | * Allows for the overriding of authentication in unit tests.
|
600 | *
|
601 | * @param request Received request.
|
602 | * @param authHeader Received authentication header.
|
603 | */
|
604 | protected authenticateRequest(request: Partial<Activity>, authHeader: string): Promise<void>;
|
605 | /**
|
606 | * @ignore
|
607 | * @private
|
608 | * Returns the actual ClaimsIdentity from the JwtTokenValidation.authenticateRequest() call.
|
609 | * @remarks
|
610 | * This method is used instead of authenticateRequest() in processActivity() to obtain the ClaimsIdentity for caching in the TurnContext.turnState.
|
611 | *
|
612 | * @param request Received request.
|
613 | * @param authHeader Received authentication header.
|
614 | */
|
615 | private authenticateRequestInternal;
|
616 | /**
|
617 | * Generates the CallerId property for the activity based on
|
618 | * https://github.com/microsoft/botframework-obi/blob/main/protocols/botframework-activity/botframework-activity.md#appendix-v---caller-id-values.
|
619 | *
|
620 | * @param identity The inbound claims.
|
621 | * @returns {Promise<string>} a promise representing the generated callerId.
|
622 | */
|
623 | private generateCallerId;
|
624 | /**
|
625 | * Gets the OAuth API endpoint.
|
626 | *
|
627 | * @param contextOrServiceUrl The URL of the channel server to query or
|
628 | * a [TurnContext](xref:botbuilder-core.TurnContext). For a turn context, the context's
|
629 | * [activity](xref:botbuilder-core.TurnContext.activity).[serviceUrl](xref:botframework-schema.Activity.serviceUrl)
|
630 | * is used for the URL.
|
631 | * @returns The endpoint used for the API requests.
|
632 | * @remarks
|
633 | * Override this in a derived class to create a mock OAuth API endpoint for unit testing.
|
634 | */
|
635 | protected oauthApiUrl(contextOrServiceUrl: TurnContext | string): string;
|
636 | /**
|
637 | * Checks the environment and can set a flag to emulate OAuth cards.
|
638 | *
|
639 | * @param context The context object for the turn.
|
640 | *
|
641 | * @remarks
|
642 | * Override this in a derived class to control how OAuth cards are emulated for unit testing.
|
643 | */
|
644 | protected checkEmulatingOAuthCards(context: TurnContext): void;
|
645 | /**
|
646 | * Creates a turn context.
|
647 | *
|
648 | * @param request An incoming request body.
|
649 | * @returns A new [TurnContext](xref:botbuilder-core.TurnContext) instance.
|
650 | * @remarks
|
651 | * Override this in a derived class to modify how the adapter creates a turn context.
|
652 | */
|
653 | protected createContext(request: Partial<Activity>): TurnContext;
|
654 | /**
|
655 | * Checks the validity of the request and attempts to map it the correct virtual endpoint,
|
656 | * then generates and returns a response if appropriate.
|
657 | *
|
658 | * @param request A ReceiveRequest from the connected channel.
|
659 | * @returns A response created by the BotAdapter to be sent to the client that originated the request.
|
660 | */
|
661 | processRequest(request: IReceiveRequest): Promise<StreamingResponse>;
|
662 | /**
|
663 | * Process a web request by applying a logic function.
|
664 | *
|
665 | * @param req An incoming HTTP [Request](xref:botbuilder.Request)
|
666 | * @param res The corresponding HTTP [Response](xref:botbuilder.Response)
|
667 | * @param logic The logic function to apply
|
668 | * @returns a promise representing the asynchronous operation.
|
669 | */
|
670 | process(req: Request, res: Response, logic: (context: TurnContext) => Promise<void>): Promise<void>;
|
671 | /**
|
672 | * Handle a web socket connection by applying a logic function to
|
673 | * each streaming request.
|
674 | *
|
675 | * @param req An incoming HTTP [Request](xref:botbuilder.Request)
|
676 | * @param socket The corresponding [INodeSocket](xref:botframework-streaming.INodeSocket)
|
677 | * @param head The corresponding [INodeBuffer](xref:botframework-streaming.INodeBuffer)
|
678 | * @param logic The logic function to apply
|
679 | * @returns a promise representing the asynchronous operation.
|
680 | */
|
681 | process(req: Request, socket: INodeSocket, head: INodeBuffer, logic: (context: TurnContext) => Promise<void>): Promise<void>;
|
682 | /**
|
683 | * Connects the handler to a Named Pipe server and begins listening for incoming requests.
|
684 | *
|
685 | * @param logic The logic that will handle incoming requests.
|
686 | * @param pipeName The name of the named pipe to use when creating the server.
|
687 | * @param retryCount Number of times to attempt to bind incoming and outgoing pipe
|
688 | * @param onListen Optional callback that fires once when server is listening on both incoming and outgoing pipe
|
689 | */
|
690 | useNamedPipe(logic: (context: TurnContext) => Promise<any>, pipeName?: string, retryCount?: number, onListen?: () => void): Promise<void>;
|
691 | /**
|
692 | * Process the initial request to establish a long lived connection via a streaming server.
|
693 | *
|
694 | * @param req The connection request.
|
695 | * @param socket The raw socket connection between the bot (server) and channel/caller (client).
|
696 | * @param head The first packet of the upgraded stream.
|
697 | * @param logic The logic that handles incoming streaming requests for the lifetime of the WebSocket connection.
|
698 | */
|
699 | useWebSocket(req: WebRequest, socket: INodeSocket, head: INodeBuffer, logic: (context: TurnContext) => Promise<any>): Promise<void>;
|
700 | private startNamedPipeServer;
|
701 | private authenticateConnection;
|
702 | /**
|
703 | * Connects the handler to a WebSocket server and begins listening for incoming requests.
|
704 | *
|
705 | * @param socket The socket to use when creating the server.
|
706 | */
|
707 | private startWebSocket;
|
708 | private readRequestBodyAsString;
|
709 | private handleVersionRequest;
|
710 | /**
|
711 | * Determine if the serviceUrl was sent via an Http/Https connection or Streaming
|
712 | * This can be determined by looking at the ServiceUrl property:
|
713 | * (1) All channels that send messages via http/https are not streaming
|
714 | * (2) Channels that send messages via streaming have a ServiceUrl that does not begin with http/https.
|
715 | *
|
716 | * @param serviceUrl the serviceUrl provided in the resquest.
|
717 | * @returns True if the serviceUrl is a streaming url, otherwise false.
|
718 | */
|
719 | private static isStreamingServiceUrl;
|
720 | }
|
721 | //# sourceMappingURL=botFrameworkAdapter.d.ts.map |
\ | No newline at end of file |