node-vk-bot-api-session-redis
v1.0.6
Published
Redis session middleware for node-vk-bot-api
Downloads
3
Readme
node-vk-bot-api-session-redis
📄 Redis session middleware for node-vk-bot-api.
Install
$ npm i node-vk-bot-api-session-redis -S
Tests
Before you must set TOKEN
and GROUP_ID
in process.env
.
$ npm test
Usage
const 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()
API
Options
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}`;
};
Clear session
bot.on((ctx) => {
ctx.session = null
})
License
MIT.