๐ Redis session middleware for node-vk-bot-api.
$ npm i node-vk-bot-api-session-redis -SBefore you must set TOKEN and GROUP_ID in process.env.
$ npm testconst VkBot = require('node-vk-bot-api')
const RedisSession = require('node-vk-bot-api-session-redis')
const bot = new VkBot(process.env.TOKEN)
const session = new RedisSession()
bot.use(session.middleware())
bot.on((ctx) => {
ctx.session.counter = ctx.session.counter || 0
ctx.session.counter++
ctx.reply(`You wrote ${ctx.session.counter} messages.`)
})
bot.startPolling()host: Redis host (default:127.0.0.1)port: Redis port (default:6379)password: Redis passwordkey: Context property name (default:session)getSessionKey: Method for get session key
Default getSessionKey:
const getSessionKey = (ctx) => {
const userId = ctx.message.from_id || ctx.message.user_id;
return `${userId}:${userId}`;
};bot.on((ctx) => {
ctx.session = null
})MIT.