1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4 | return new (P || (P = Promise))(function (resolve, reject) {
|
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9 | });
|
10 | };
|
11 | Object.defineProperty(exports, "__esModule", { value: true });
|
12 | exports.SkillHttpClient = void 0;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | const botbuilder_core_1 = require("botbuilder-core");
|
21 | const botframework_connector_1 = require("botframework-connector");
|
22 | const botFrameworkHttpClient_1 = require("../botFrameworkHttpClient");
|
23 |
|
24 |
|
25 |
|
26 | class SkillHttpClient extends botFrameworkHttpClient_1.BotFrameworkHttpClient {
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | constructor(credentialProvider, conversationIdFactory, channelService) {
|
34 | super(credentialProvider, channelService);
|
35 | if (!conversationIdFactory) {
|
36 | throw new Error('conversationIdFactory missing');
|
37 | }
|
38 | this.conversationIdFactory = conversationIdFactory;
|
39 | }
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | postToSkill(audienceOrFromBotId, fromBotIdOrSkill, toSkillOrCallbackUrl, callbackUrlOrActivity, activityToForward) {
|
50 | return __awaiter(this, void 0, void 0, function* () {
|
51 | let originatingAudience;
|
52 | let fromBotId;
|
53 | if (typeof fromBotIdOrSkill === 'string') {
|
54 | fromBotId = fromBotIdOrSkill;
|
55 |
|
56 | originatingAudience = audienceOrFromBotId;
|
57 | }
|
58 | else {
|
59 | fromBotId = audienceOrFromBotId;
|
60 | originatingAudience = botframework_connector_1.JwtTokenValidation.isGovernment(this.channelService)
|
61 | ? botframework_connector_1.GovernmentConstants.ToChannelFromBotOAuthScope
|
62 | : botframework_connector_1.AuthenticationConstants.ToChannelFromBotOAuthScope;
|
63 | }
|
64 | const toSkill = typeof toSkillOrCallbackUrl === 'object' ? toSkillOrCallbackUrl : fromBotIdOrSkill;
|
65 | const callbackUrl = typeof callbackUrlOrActivity === 'string' ? callbackUrlOrActivity : toSkillOrCallbackUrl;
|
66 | const activity = typeof activityToForward === 'object' ? activityToForward : callbackUrlOrActivity;
|
67 | let skillConversationId;
|
68 | try {
|
69 | const createIdOptions = {
|
70 | activity,
|
71 | botFrameworkSkill: toSkill,
|
72 | fromBotId: fromBotId,
|
73 | fromBotOAuthScope: originatingAudience,
|
74 | };
|
75 | skillConversationId = yield this.conversationIdFactory.createSkillConversationIdWithOptions(createIdOptions);
|
76 | }
|
77 | catch (err) {
|
78 | if (err.message === 'Not Implemented') {
|
79 | skillConversationId = yield this.conversationIdFactory.createSkillConversationId(botbuilder_core_1.TurnContext.getConversationReference(activity));
|
80 | }
|
81 | else {
|
82 | throw err;
|
83 | }
|
84 | }
|
85 | return yield this.postActivity(fromBotId, toSkill.appId, toSkill.skillEndpoint, callbackUrl, skillConversationId, activity);
|
86 | });
|
87 | }
|
88 | }
|
89 | exports.SkillHttpClient = SkillHttpClient;
|
90 |
|
\ | No newline at end of file |