mokeddes / botbuilder-storage-redis Goto Github PK
View Code? Open in Web Editor NEWRedis storage for Microsoft BotBuilder V4
License: MIT License
Redis storage for Microsoft BotBuilder V4
License: MIT License
It caused me unexpected issues in the code which was using MemoryStorage before.
MemoryStorage does not return an item if it is missing in the storage.
keys.forEach((key: string) => {
const item: string = this.memory[key];
if (item) {
data[key] = JSON.parse(item);
}
});
Example in Storage interface suggests that read returns undefined too.
const items = await storage.read(['botState']);
const state = items['botState'] || {};
So I think that this code is incorrent and should be modified to return only keys that exist in storage.
stateKeys.forEach((key: string, index: number): void => {
data[key] = JSON.parse(allKeysValuesFromRedis[index] || '{}');
});
Using Redis 6.0.5, creating a RedisDbStorage object with ttlInSeconds <1
Result of .write() is "ERR invalid expire time in setex". It appears that at least as of Redis 6.0.5 the SETEX 'seconds' parameter must be positive.
I believe simply reverting d01f88c will suffice to fix this.
Note also that the usage example in README.md has a comment re "// data expires in 2 hours", whereas it should either read "data expires in 2 minutes" or have the ttlInSeconds updated to 3600
Conversation state is temporary by its nature - when the conversation ends, that data is no longer useful, but, unless it is explicitly deleted, it stays in storage for a long time, so it wastes memory and/or disk space and can cause compliance issues.
Redis has a nice feature where it is possible to set expiration time of data items (I'm not an expert in Redis), it would really useful if abandoned data would magically disappear few hours later.
I think that the expiration time could be passed as constructor argument to RedisDbStorage and default to 0.
If expiration time is 0, then it would use set
command, if expiration time is more than 0, it would use setex command with expiration time as second parameter.
Does it look like a good idea?
I can make a pull request.
Hi there,
Using the latest version available 1.0.9, I'm getting this error when the bot is trying to read/update its state. Any idea why could be causing this? Could it be the package is not compatible with recent versions of the botbuilder? I'm using botbuilder 4.8.0.
0|ms-bot | TypeError: this.storage.read is not a function
0|ms-bot | at Promise.resolve.then (/var/www/ms-bot/releases/20200424210108/node_modules/botbuilder-core/lib/botState.js:63:37)
0|ms-bot | Error: BotFrameworkAdapter.processActivity(): 500 ERROR
0|ms-bot | TypeError: this.storage.delete is not a function
0|ms-bot | at Promise.resolve.then (/var/www/ms-bot/releases/20200424210108/node_modules/botbuilder-core/lib/botState.js:141:91)
0|ms-bot | at process._tickCallback (internal/process/next_tick.js:68:7)
0|ms-bot | at BotFrameworkAdapter.<anonymous> (/var/www/ms-bot/releases/20200424210108/node_modules/botbuilder/lib/botFrameworkAdapter.js:660:27)
0|ms-bot | at Generator.throw (<anonymous>)
0|ms-bot | at rejected (/var/www/ms-bot/releases/20200424210108/node_modules/botbuilder/lib/botFrameworkAdapter.js:12:65)
0|ms-bot | at process._tickCallback (internal/process/next_tick.js:68:7)
I do have to say that the documentation in the readme does not match with the official sample applications: https://github.com/microsoft/BotBuilder-Samples/blob/master/samples/javascript_nodejs/45.state-management/index.js#L38
I'm passing an instance of the redisStorage directly to state objects:
const redisStateStorage = new RedisDbStorage(redisClient);
const conversationState = new ConversationState(redisStateStorage);
const userState = new UserState(redisStateStorage);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.