1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | /**
|
4 | * @module botkit
|
5 | */
|
6 | /**
|
7 | * Copyright (c) Microsoft Corporation. All rights reserved.
|
8 | * Licensed under the MIT License.
|
9 | */
|
10 | const botbuilder_1 = require("botbuilder");
|
11 | /**
|
12 | * A customized version of [ConversationState](https://docs.microsoft.com/en-us/javascript/api/botbuilder-core/conversationstate?view=botbuilder-ts-latest) that overide the [getStorageKey](#getStorageKey) method to create a more complex key value.
|
13 | * This allows Botkit to automatically track conversation state in scenarios where multiple users are present in a single channel,
|
14 | * or when threads or sub-channels parent channel that would normally collide based on the information defined in the conversation address field.
|
15 | * Note: This is used automatically inside Botkit and developers should not need to directly interact with it.
|
16 | * @ignore
|
17 | */
|
18 | class BotkitConversationState extends botbuilder_1.ConversationState {
|
19 | getStorageKey(context) {
|
20 | const activity = context.activity;
|
21 | const channelId = activity.channelId;
|
22 | if (!activity.conversation || !activity.conversation.id) {
|
23 | throw new Error('missing activity.conversation');
|
24 | }
|
25 | // create a combo key by sorting all the fields in the conversation address and combining them all
|
26 | // mix in user id as well, because conversations are between the bot and a single user
|
27 | const conversationId = Object.keys(activity.conversation).filter((key) => { return key !== 'properties'; }).sort().map((key) => activity.conversation[key]).filter((val) => val !== '' && val !== null && typeof val !== 'undefined').join('-') + '-' + activity.from.id;
|
28 | if (!channelId) {
|
29 | throw new Error('missing activity.channelId');
|
30 | }
|
31 | if (!conversationId) {
|
32 | throw new Error('missing activity.conversation.id');
|
33 | }
|
34 | // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
35 | // @ts-ignore namespace is technically private
|
36 | return `${channelId}/conversations/${conversationId}/${this.namespace}`;
|
37 | }
|
38 | }
|
39 | exports.BotkitConversationState = BotkitConversationState;
|
40 | //# sourceMappingURL=conversationState.js.map |
\ | No newline at end of file |