diff --git a/packages/botkit/src/conversationState.ts b/packages/botkit/src/conversationState.ts index 9a7901ef7..dcfa5ba9f 100644 --- a/packages/botkit/src/conversationState.ts +++ b/packages/botkit/src/conversationState.ts @@ -24,7 +24,7 @@ export class BotkitConversationState extends ConversationState { // create a combo key by sorting all the fields in the conversation address and combining them all // mix in user id as well, because conversations are between the bot and a single user - const conversationId: string = Object.keys(activity.conversation).sort().map((key) => activity.conversation[key]).filter((val) => val !== '' && val !== null && typeof val !== 'undefined').join('-') + '-' + activity.from.id; + const conversationId: string = 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; if (!channelId) { throw new Error('missing activity.channelId'); diff --git a/packages/botkit/tests/State.tests.js b/packages/botkit/tests/State.tests.js new file mode 100644 index 000000000..081e3c0f6 --- /dev/null +++ b/packages/botkit/tests/State.tests.js @@ -0,0 +1,56 @@ +const assert = require('assert'); +const { BotkitConversationState } = require('../lib/conversationState'); +const { MemoryStorage } = require('botbuilder'); + +const storage = new MemoryStorage(); +const state = new BotkitConversationState(storage); + +describe('BotkitConversationState', function() { + it('should generate appropriate state key', function() { + const key = state.getStorageKey({ + activity: { + channelId: 'test', + from: { + id: 'foo' + }, + conversation: { + id: 'bar' + } + } + }); + assert(key === 'test/conversations/bar-foo/', 'failed key gen'); + }); + it('should generate appropriate state key excluding properties field', function() { + const key = state.getStorageKey({ + activity: { + channelId: 'test', + from: { + id: 'foo' + }, + conversation: { + properties: { + baz: true + }, + id: 'bar' + } + } + }); + assert(key === 'test/conversations/bar-foo/', 'failed key gen'); + }); + it('should generate appropriate state key including platform field', function() { + const key = state.getStorageKey({ + activity: { + channelId: 'test', + from: { + id: 'foo' + }, + conversation: { + threadId: '5', + channel: '9', + id: 'bar' + } + } + }); + assert(key === 'test/conversations/9-bar-5-foo/', 'failed key gen'); + }); +});