Nominal Pizza Masticator

    node-vk-bot-api-session-redis

    1.0.6 • Public • Published

    node-vk-bot-api-session-redis node-vk-bot-api-session-redis

    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 password
    • key: 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.

    Install

    npm i node-vk-bot-api-session-redis

    DownloadsWeekly Downloads

    1

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    5.24 kB

    Total Files

    7

    Last publish

    Collaborators

    • bifot