UNPKG

23.6 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Microsoft Corporation.
3// Licensed under the MIT License.
4var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6 return new (P || (P = Promise))(function (resolve, reject) {
7 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10 step((generator = generator.apply(thisArg, _arguments || [])).next());
11 });
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.ChannelServiceHandlerBase = void 0;
15const http_1 = require("http");
16const statusCodeError_1 = require("./statusCodeError");
17const botbuilder_core_1 = require("botbuilder-core");
18/**
19 * The ChannelServiceHandlerBase implements API to forward activity to a skill and
20 * implements routing ChannelAPI calls from the Skill up through the bot/adapter.
21 */
22class ChannelServiceHandlerBase {
23 /**
24 * Sends an [Activity](xref:botframework-schema.Activity) to the end of a conversation.
25 *
26 * @param authHeader The authentication header.
27 * @param conversationId The conversation Id.
28 * @param activity The [Activity](xref:botframework-schema.Activity) to send.
29 * @returns A `Promise` representing the [ResourceResponse](xref:botframework-schema.ResourceResponse) for the operation.
30 */
31 handleSendToConversation(authHeader, conversationId, activity) {
32 return __awaiter(this, void 0, void 0, function* () {
33 const claimsIdentity = yield this.authenticate(authHeader);
34 return this.onSendToConversation(claimsIdentity, conversationId, activity);
35 });
36 }
37 /**
38 * Sends a reply to an [Activity](xref:botframework-schema.Activity).
39 *
40 * @param authHeader The authentication header.
41 * @param conversationId The conversation Id.
42 * @param activityId The activity Id the reply is to.
43 * @param activity The [Activity](xref:botframework-schema.Activity) to send.
44 * @returns A `Promise` representing the [ResourceResponse](xref:botframework-schema.ResourceResponse) for the operation.
45 */
46 handleReplyToActivity(authHeader, conversationId, activityId, activity) {
47 return __awaiter(this, void 0, void 0, function* () {
48 const claimsIdentity = yield this.authenticate(authHeader);
49 return this.onReplyToActivity(claimsIdentity, conversationId, activityId, activity);
50 });
51 }
52 /**
53 * Edits a previously sent existing [Activity](xref:botframework-schema.Activity).
54 *
55 * @param authHeader The authentication header.
56 * @param conversationId The conversation Id.
57 * @param activityId The activity Id to update.
58 * @param activity The replacement [Activity](xref:botframework-schema.Activity).
59 * @returns A `Promise` representing the [ResourceResponse](xref:botframework-schema.ResourceResponse) for the operation.
60 */
61 handleUpdateActivity(authHeader, conversationId, activityId, activity) {
62 return __awaiter(this, void 0, void 0, function* () {
63 const claimsIdentity = yield this.authenticate(authHeader);
64 return this.onUpdateActivity(claimsIdentity, conversationId, activityId, activity);
65 });
66 }
67 /**
68 * Deletes an existing [Activity](xref:botframework-schema.Activity).
69 *
70 * @param authHeader The authentication header.
71 * @param conversationId The conversation Id.
72 * @param activityId The activity Id to delete.
73 */
74 handleDeleteActivity(authHeader, conversationId, activityId) {
75 return __awaiter(this, void 0, void 0, function* () {
76 const claimsIdentity = yield this.authenticate(authHeader);
77 yield this.onDeleteActivity(claimsIdentity, conversationId, activityId);
78 });
79 }
80 /**
81 * Enumerates the members of an [Activity](xref:botframework-schema.Activity).
82 *
83 * @param authHeader The authentication header.
84 * @param conversationId The conversation Id.
85 * @param activityId The activity Id.
86 * @returns The enumerated [ChannelAccount](xref:botframework-schema.ChannelAccount) list.
87 */
88 handleGetActivityMembers(authHeader, conversationId, activityId) {
89 return __awaiter(this, void 0, void 0, function* () {
90 const claimsIdentity = yield this.authenticate(authHeader);
91 return this.onGetActivityMembers(claimsIdentity, conversationId, activityId);
92 });
93 }
94 /**
95 * Creates a new Conversation.
96 *
97 * @param authHeader The authentication header.
98 * @param parameters [ConversationParameters](xref:botbuilder-core.ConversationParameters) to create the conversation from.
99 * @returns A `Promise` representation for the operation.
100 */
101 handleCreateConversation(authHeader, parameters) {
102 return __awaiter(this, void 0, void 0, function* () {
103 const claimsIdentity = yield this.authenticate(authHeader);
104 return this.onCreateConversation(claimsIdentity, parameters);
105 });
106 }
107 /**
108 * Lists the Conversations in which the bot has participated.
109 *
110 * @param authHeader The authentication header.
111 * @param conversationId The conversation Id.
112 * @param continuationToken A skip or continuation token.
113 * @returns A `Promise` representation for the operation.
114 */
115 handleGetConversations(authHeader, conversationId, continuationToken /* some default */) {
116 return __awaiter(this, void 0, void 0, function* () {
117 const claimsIdentity = yield this.authenticate(authHeader);
118 return this.onGetConversations(claimsIdentity, conversationId, continuationToken);
119 });
120 }
121 /**
122 * Enumerates the members of a conversation.
123 *
124 * @param authHeader The authentication header.
125 * @param conversationId The conversation Id.
126 * @returns The enumerated [ChannelAccount](xref:botframework-schema.ChannelAccount) list.
127 */
128 handleGetConversationMembers(authHeader, conversationId) {
129 return __awaiter(this, void 0, void 0, function* () {
130 const claimsIdentity = yield this.authenticate(authHeader);
131 return this.onGetConversationMembers(claimsIdentity, conversationId);
132 });
133 }
134 /**
135 * Enumerates the members of a conversation one page at a time.
136 *
137 * @param authHeader The authentication header.
138 * @param conversationId The conversation Id.
139 * @param pageSize Suggested page size.
140 * @param continuationToken A continuation token.
141 * @returns A `Promise` representing the [PagedMembersResult](xref:botframework-schema.PagedMembersResult) for the operation.
142 */
143 handleGetConversationPagedMembers(authHeader, conversationId, pageSize = -1, continuationToken) {
144 return __awaiter(this, void 0, void 0, function* () {
145 const claimsIdentity = yield this.authenticate(authHeader);
146 return this.onGetConversationPagedMembers(claimsIdentity, conversationId, pageSize, continuationToken);
147 });
148 }
149 /**
150 * Deletes a member from a conversation.
151 *
152 * @param authHeader The authentication header.
153 * @param conversationId The conversation Id.
154 * @param memberId Id of the member to delete from this conversation.
155 */
156 handleDeleteConversationMember(authHeader, conversationId, memberId) {
157 return __awaiter(this, void 0, void 0, function* () {
158 const claimsIdentity = yield this.authenticate(authHeader);
159 yield this.onDeleteConversationMember(claimsIdentity, conversationId, memberId);
160 });
161 }
162 /**
163 * Uploads the historic activities of the conversation.
164 *
165 * @param authHeader The authentication header.
166 * @param conversationId The conversation Id.
167 * @param transcript [Transcript](xref:botframework-schema.Transcript) of activities.
168 * @returns A `Promise` representing the [ResourceResponse](xref:botframework-schema.ResourceResponse) for the operation.
169 */
170 handleSendConversationHistory(authHeader, conversationId, transcript) {
171 return __awaiter(this, void 0, void 0, function* () {
172 const claimsIdentity = yield this.authenticate(authHeader);
173 return this.onSendConversationHistory(claimsIdentity, conversationId, transcript);
174 });
175 }
176 /**
177 * Stores data in a compliant store when dealing with enterprises.
178 *
179 * @param authHeader The authentication header.
180 * @param conversationId The conversation Id.
181 * @param attachmentUpload [AttachmentData](xref:botframework-schema.AttachmentData).
182 * @returns A `Promise` representing the [ResourceResponse](xref:botframework-schema.ResourceResponse) for the operation.
183 */
184 handleUploadAttachment(authHeader, conversationId, attachmentUpload) {
185 return __awaiter(this, void 0, void 0, function* () {
186 const claimsIdentity = yield this.authenticate(authHeader);
187 return this.onUploadAttachment(claimsIdentity, conversationId, attachmentUpload);
188 });
189 }
190 /**
191 * SendToConversation() API for Skill.
192 *
193 * @remarks
194 * This method allows you to send an activity to the end of a conversation.
195 * This is slightly different from ReplyToActivity().
196 * * SendToConversation(conversationId) - will append the activity to the end
197 * of the conversation according to the timestamp or semantics of the channel.
198 * * ReplyToActivity(conversationId,ActivityId) - adds the activity as a reply
199 * to another activity, if the channel supports it. If the channel does not
200 * support nested replies, ReplyToActivity falls back to SendToConversation.
201 *
202 * Use ReplyToActivity when replying to a specific activity in the
203 * conversation.
204 *
205 * Use SendToConversation in all other cases.
206 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
207 * @param conversationId Conversation identifier
208 * @param activity Activity to send
209 */
210 onSendToConversation(claimsIdentity, conversationId, activity) {
211 return __awaiter(this, void 0, void 0, function* () {
212 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onSendToConversation(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
213 });
214 }
215 /**
216 * ReplyToActivity() API for Skill.
217 *
218 * @remarks
219 * This method allows you to reply to an activity.
220 *
221 * This is slightly different from SendToConversation().
222 * * SendToConversation(conversationId) - will append the activity to the end
223 * of the conversation according to the timestamp or semantics of the channel.
224 * * ReplyToActivity(conversationId,ActivityId) - adds the activity as a reply
225 * to another activity, if the channel supports it. If the channel does not
226 * support nested replies, ReplyToActivity falls back to SendToConversation.
227 *
228 * Use ReplyToActivity when replying to a specific activity in the
229 * conversation.
230 *
231 * Use SendToConversation in all other cases.
232 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
233 * @param conversationId Conversation ID.
234 * @param activityId activityId the reply is to (OPTIONAL).
235 * @param activity Activity to send.
236 */
237 onReplyToActivity(claimsIdentity, conversationId, activityId, activity) {
238 return __awaiter(this, void 0, void 0, function* () {
239 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onReplyToActivity(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
240 });
241 }
242 /**
243 * UpdateActivity() API for Skill.
244 * @remarks
245 * Edit an existing activity.
246 *
247 * Some channels allow you to edit an existing activity to reflect the new
248 * state of a bot conversation.
249 *
250 * For example, you can remove buttons after someone has clicked "Approve" button.
251 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
252 * @param conversationId Conversation ID.
253 * @param activityId activityId to update.
254 * @param activity replacement Activity.
255 */
256 onUpdateActivity(claimsIdentity, conversationId, activityId, activity) {
257 return __awaiter(this, void 0, void 0, function* () {
258 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onUpdateActivity(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
259 });
260 }
261 /**
262 * DeleteActivity() API for Skill.
263 *
264 * @remarks
265 * Delete an existing activity.
266 *
267 * Some channels allow you to delete an existing activity, and if successful
268 * this method will remove the specified activity.
269 *
270 *
271 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
272 * @param conversationId Conversation ID.
273 * @param activityId activityId to delete.
274 */
275 onDeleteActivity(claimsIdentity, conversationId, activityId) {
276 return __awaiter(this, void 0, void 0, function* () {
277 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onDeleteActivity(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
278 });
279 }
280 /**
281 * GetActivityMembers() API for Skill.
282 *
283 * @remarks
284 * Enumerate the members of an activity.
285 *
286 * This REST API takes a ConversationId and a ActivityId, returning an array
287 * of ChannelAccount objects representing the members of the particular
288 * activity in the conversation.
289 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
290 * @param conversationId Conversation ID.
291 * @param activityId Activity ID.
292 */
293 onGetActivityMembers(claimsIdentity, conversationId, activityId) {
294 return __awaiter(this, void 0, void 0, function* () {
295 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onGetActivityMembers(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
296 });
297 }
298 /**
299 * CreateConversation() API for Skill.
300 *
301 * @remarks
302 * Create a new Conversation.
303 *
304 * POST to this method with a
305 * * Bot being the bot creating the conversation
306 * * IsGroup set to true if this is not a direct message (default is false)
307 * * Array containing the members to include in the conversation
308 *
309 * The return value is a ResourceResponse which contains a conversation id
310 * which is suitable for use in the message payload and REST API uris.
311 *
312 * Most channels only support the semantics of bots initiating a direct
313 * message conversation.
314 *
315 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
316 * @param parameters Parameters to create the conversation from.
317 */
318 onCreateConversation(claimsIdentity, parameters) {
319 return __awaiter(this, void 0, void 0, function* () {
320 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onCreateConversation(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
321 });
322 }
323 /**
324 * onGetConversations() API for Skill.
325 *
326 * @remarks
327 * List the Conversations in which this bot has participated.
328 *
329 * GET from this method with a skip token
330 *
331 * The return value is a ConversationsResult, which contains an array of
332 * ConversationMembers and a skip token. If the skip token is not empty, then
333 * there are further values to be returned. Call this method again with the
334 * returned token to get more values.
335 *
336 * Each ConversationMembers object contains the ID of the conversation and an
337 * array of ChannelAccounts that describe the members of the conversation.
338 *
339 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
340 * @param conversationId Conversation ID.
341 * @param continuationToken Skip or continuation token.
342 */
343 onGetConversations(claimsIdentity, conversationId, continuationToken) {
344 return __awaiter(this, void 0, void 0, function* () {
345 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onGetConversations(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
346 });
347 }
348 /**
349 * getConversationMembers() API for Skill.
350 *
351 * @remarks
352 * Enumerate the members of a conversation.
353 *
354 * This REST API takes a ConversationId and returns an array of ChannelAccount
355 * objects representing the members of the conversation.
356 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
357 * @param conversationId Conversation ID.
358 */
359 onGetConversationMembers(claimsIdentity, conversationId) {
360 return __awaiter(this, void 0, void 0, function* () {
361 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onGetConversationMembers(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
362 });
363 }
364 /**
365 * getConversationPagedMembers() API for Skill.
366 *
367 * @remarks
368 * Enumerate the members of a conversation one page at a time.
369 *
370 * This REST API takes a ConversationId. Optionally a pageSize and/or
371 * continuationToken can be provided. It returns a PagedMembersResult, which
372 * contains an array
373 * of ChannelAccounts representing the members of the conversation and a
374 * continuation token that can be used to get more values.
375 *
376 * One page of ChannelAccounts records are returned with each call. The number
377 * of records in a page may vary between channels and calls. The pageSize
378 * parameter can be used as
379 * a suggestion. If there are no additional results the response will not
380 * contain a continuation token. If there are no members in the conversation
381 * the Members will be empty or not present in the response.
382 *
383 * A response to a request that has a continuation token from a prior request
384 * may rarely return members from a previous request.
385 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
386 * @param conversationId Conversation ID.
387 * @param pageSize Suggested page size.
388 * @param continuationToken Continuation Token.
389 */
390 onGetConversationPagedMembers(claimsIdentity, conversationId, pageSize = -1, continuationToken) {
391 return __awaiter(this, void 0, void 0, function* () {
392 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onGetConversationPagedMembers(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
393 });
394 }
395 /**
396 * DeleteConversationMember() API for Skill.
397 * @remarks
398 * Deletes a member from a conversation.
399 *
400 * This REST API takes a ConversationId and a memberId (of type string) and
401 * removes that member from the conversation. If that member was the last member
402 * of the conversation, the conversation will also be deleted.
403 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
404 * @param conversationId Conversation ID.
405 * @param memberId ID of the member to delete from this conversation.
406 */
407 onDeleteConversationMember(claimsIdentity, conversationId, memberId) {
408 return __awaiter(this, void 0, void 0, function* () {
409 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onDeleteConversationMember(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
410 });
411 }
412 /**
413 * SendConversationHistory() API for Skill.
414 * @remarks
415 * This method allows you to upload the historic activities to the
416 * conversation.
417 *
418 * Sender must ensure that the historic activities have unique ids and
419 * appropriate timestamps. The ids are used by the client to deal with
420 * duplicate activities and the timestamps are used by the client to render
421 * the activities in the right order.
422 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
423 * @param conversationId Conversation ID.
424 * @param transcript Transcript of activities.
425 */
426 onSendConversationHistory(claimsIdentity, conversationId, transcript) {
427 return __awaiter(this, void 0, void 0, function* () {
428 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onSendConversationHistory(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
429 });
430 }
431 /**
432 * UploadAttachment() API for Skill.
433 * @remarks
434 * Upload an attachment directly into a channel's blob storage.
435 *
436 * This is useful because it allows you to store data in a compliant store
437 * when dealing with enterprises.
438 *
439 * The response is a ResourceResponse which contains an AttachmentId which is
440 * suitable for using with the attachments API.
441 * @param claimsIdentity ClaimsIdentity for the bot, should have AudienceClaim, AppIdClaim and ServiceUrlClaim.
442 * @param conversationId Conversation ID.
443 * @param attachmentUpload Attachment data.
444 */
445 onUploadAttachment(claimsIdentity, conversationId, attachmentUpload) {
446 return __awaiter(this, void 0, void 0, function* () {
447 throw new statusCodeError_1.StatusCodeError(botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED, `ChannelServiceHandler.onUploadAttachment(): ${botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED}: ${http_1.STATUS_CODES[botbuilder_core_1.StatusCodes.NOT_IMPLEMENTED]}`);
448 });
449 }
450}
451exports.ChannelServiceHandlerBase = ChannelServiceHandlerBase;
452//# sourceMappingURL=channelServiceHandlerBase.js.map
\No newline at end of file