Socket
Socket
Sign inDemoInstall

node-vk-bot-api-session-redis

Package Overview
Dependencies
4
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-vk-bot-api-session-redis

Redis session middleware for node-vk-bot-api


Version published
Weekly downloads
7
increased by600%
Maintainers
1
Install size
281 kB
Created
Weekly downloads
 

Readme

Source

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.

Keywords

FAQs

Last updated on 18 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc