Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-vk-bot-api-session-redis

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-vk-bot-api-session-redis - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

.eslintrc.json

9

lib/session.js

@@ -7,5 +7,3 @@ const createClient = require('./redis')

key: 'session',
host: '127.0.0.1',
port: 6379,
getSessionKey: ctx => `${ctx.message.from_id}:${ctx.message.from_id}`
getSessionKey: ctx => `${ctx.message.from_id}:${ctx.message.from_id}`,
}, settings)

@@ -15,3 +13,4 @@

host: this.host,
port: this.port
port: this.port,
password: this.password,
})

@@ -23,3 +22,3 @@ }

const key = this.getSessionKey(ctx)
const session = JSON.parse((await this.redis.get(key)) || '{}')
let session = JSON.parse((await this.redis.get(key)) || '{}')

@@ -26,0 +25,0 @@ Object.defineProperty(ctx, this.key, {

{
"name": "node-vk-bot-api-session-redis",
"version": "1.0.2",
"version": "1.0.3",
"description": "Redis session middleware for node-vk-bot-api",

@@ -10,3 +10,5 @@ "main": "lib/session.js",

"scripts": {
"test": "mocha test/session.test.js --exit --timeout 2500"
"test": "mocha test/session.test.js --exit --timeout 2500",
"eslint": "eslint ./",
"eslint:fix": "eslint ./ --fix"
},

@@ -34,6 +36,9 @@ "keywords": [

"chai": "^4.1.2",
"eslint": "^5.6.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0",
"mocha": "^5.2.0",
"node-vk-bot-api": "^2.0.0",
"node-vk-bot-api": "^2.1.6",
"sinon": "^6.1.4"
}
}

@@ -28,6 +28,3 @@ [![node-vk-bot-api-session-redis](https://img.shields.io/npm/v/node-vk-bot-api-session-redis.svg?style=flat-square)](https://www.npmjs.com/package/node-vk-bot-api-session-redis/)

const bot = new VkBot({
token: process.env.TOKEN,
group_id: process.env.GROUP_ID
})
const bot = new VkBot(process.env.TOKEN)
const session = new RedisSession()

@@ -53,13 +50,22 @@

* `port`: Redis port (default: `6379`)
* `password`: Redis password
* `key`: Context property name (default: `session`)
* `getSessionKey`: Getter for session key
* `getSessionKey`: Method for get session key
#### Default `getSessionKey(ctx)`
Default `getSessionKey`:
```js
const getSessionKey = (ctx) => {
return `${ctx.message.from_id}:${ctx.message.from_id}`
return `${ctx.message.from_id}:${ctx.message.from_id}`
}
````
### Clear session
```js
bot.on((ctx) => {
ctx.session = null
})
```
## License

@@ -66,0 +72,0 @@

const VkBot = require('node-vk-bot-api')
const bot = new VkBot({
token: process.env.TOKEN,
group_id: process.env.GROUP_ID,
})
const bot = new VkBot(process.env.TOKEN)
module.exports = {
bot,
handleUpdate: (text, type = 'message_new') => new Promise(resolve => {
handleUpdate: (text, type = 'message_new') => new Promise((resolve) => {
bot.next({

@@ -15,8 +12,8 @@ message: {

type,
from_id: 145003487
}
from_id: 145003487,
},
})
setTimeout(resolve, 100)
})
}),
}

@@ -8,2 +8,4 @@ const { expect } = require('chai')

const user = { name: 'bifot' }
bot.use(session.middleware())

@@ -16,6 +18,6 @@

bot.command('/set', (ctx) => {
ctx.session.user = { name: 'bifot' }
ctx.session.user = user
callback()
expect(ctx.session.user).to.be.a('object')
expect(ctx.session.user).to.deep.equal(user)
})

@@ -33,3 +35,3 @@

callback()
expect(ctx.session.user).to.be.a('object')
expect(ctx.session.user).to.deep.equal(user)
})

@@ -36,0 +38,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc