UNPKG

botbuilder

Version:

Bot Builder is a framework for building rich bots on virtually any platform.

92 lines 5.36 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SkillHttpClient = void 0; /** * @module botbuilder */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ const botbuilder_core_1 = require("botbuilder-core"); const botframework_connector_1 = require("botframework-connector"); const botFrameworkHttpClient_1 = require("../botFrameworkHttpClient"); /** * A BotFrameworkHttpClient specialized for Skills that encapsulates Conversation ID generation. */ class SkillHttpClient extends botFrameworkHttpClient_1.BotFrameworkHttpClient { /** * Creates a new instance of the [SkillHttpClient](xref:botbuilder-core.SkillHttpClient) class. * * @param credentialProvider An instance of [ICredentialProvider](xref:botframework-connector.ICredentialProvider). * @param conversationIdFactory An instance of a class derived from [SkillConversationIdFactoryBase](xref:botbuilder-core.SkillConversationIdFactoryBase). * @param channelService Optional. The channel service. */ constructor(credentialProvider, conversationIdFactory, channelService) { super(credentialProvider, channelService); if (!conversationIdFactory) { throw new Error('conversationIdFactory missing'); } this.conversationIdFactory = conversationIdFactory; } /** * Uses the `SkillConversationIdFactory` to create or retrieve a Skill Conversation Id, and sends the [Activity](xref:botframework-schema.Activity). * * @param audienceOrFromBotId The OAuth audience scope, used during token retrieval or the AppId of the bot sending the [Activity](xref:botframework-schema.Activity). * @param fromBotIdOrSkill The AppId of the bot sending the [Activity](xref:botframework-schema.Activity) or the skill to create the Conversation Id for. * @param toSkillOrCallbackUrl The skill to create the Conversation Id for or the callback Url for the skill host. * @param callbackUrlOrActivity The callback Url for the skill host or the [Activity](xref:botframework-schema.Activity) to send. * @param activityToForward Optional. The [Activity](xref:botframework-schema.Activity) to forward. * @returns A `Promise` representing the [InvokeResponse](xref:botbuilder-core.InvokeResponse) for the operation. */ postToSkill(audienceOrFromBotId, fromBotIdOrSkill, toSkillOrCallbackUrl, callbackUrlOrActivity, activityToForward) { return __awaiter(this, void 0, void 0, function* () { let originatingAudience; let fromBotId; if (typeof fromBotIdOrSkill === 'string') { fromBotId = fromBotIdOrSkill; // If fromBotIdOrSkill is a string, then audienceOrFromBotId should be a string per the overload. originatingAudience = audienceOrFromBotId; } else { fromBotId = audienceOrFromBotId; originatingAudience = botframework_connector_1.JwtTokenValidation.isGovernment(this.channelService) ? botframework_connector_1.GovernmentConstants.ToChannelFromBotOAuthScope : botframework_connector_1.AuthenticationConstants.ToChannelFromBotOAuthScope; } const toSkill = typeof toSkillOrCallbackUrl === 'object' ? toSkillOrCallbackUrl : fromBotIdOrSkill; const callbackUrl = typeof callbackUrlOrActivity === 'string' ? callbackUrlOrActivity : toSkillOrCallbackUrl; const activity = typeof activityToForward === 'object' ? activityToForward : callbackUrlOrActivity; let skillConversationId; try { const createIdOptions = { activity, botFrameworkSkill: toSkill, fromBotId: fromBotId, fromBotOAuthScope: originatingAudience, }; skillConversationId = yield this.conversationIdFactory.createSkillConversationIdWithOptions(createIdOptions); } catch (err) { if (err.message === 'Not Implemented') { skillConversationId = yield this.conversationIdFactory.createSkillConversationId(botbuilder_core_1.TurnContext.getConversationReference(activity)); } else { throw err; } } return yield this.postActivity(fromBotId, toSkill.appId, toSkill.skillEndpoint, callbackUrl, skillConversationId, activity); }); } } exports.SkillHttpClient = SkillHttpClient; //# sourceMappingURL=skillHttpClient.js.map