UNPKG

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