forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskillConversationIdFactory.js
36 lines (30 loc) · 1.43 KB
/
skillConversationIdFactory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { SkillConversationIdFactoryBase, TurnContext } = require('botbuilder');
/**
* A SkillConversationIdFactory that uses an in memory dictionary
* to store and retrieve ConversationReference instances.
*/
class SkillConversationIdFactory extends SkillConversationIdFactoryBase {
constructor() {
super();
this.refs = {};
}
async createSkillConversationIdWithOptions(options) {
const skillConversationReference = {
conversationReference: TurnContext.getConversationReference(options.activity),
oAuthScope: options.fromBotOAuthScope
};
// This key has a 100 character limit by default. Increase with `restify.createServer({ maxParamLength: 1000 });` in index.js.
const key = `${ options.fromBotId }-${ options.botFrameworkSkill.appId }-${ skillConversationReference.conversationReference.conversation.id }-${ skillConversationReference.conversationReference.channelId }-skillconvo`;
this.refs[key] = skillConversationReference;
return key;
}
async getSkillConversationReference(skillConversationId) {
return this.refs[skillConversationId];
}
async deleteConversationReference(skillConversationId) {
this.refs[skillConversationId] = undefined;
}
}
module.exports.SkillConversationIdFactory = SkillConversationIdFactory;