@vbots/session-storage
SessinStorage Add-on for Session vk-io library
Last updated 3 months ago by xtcry .
MIT · Original npm · Tarball · package.json
$ cnpm install @vbots/session-storage 
SYNC missed versions from official npm registry.

SessinStorage Add-on for Session vk-io library

NPM version Used Dependencies

Powered by Lowdb

Usage

NPM

npm i @vbots/session-storage

Yarn

yarn add @vbots/session-storage

Example

const { VK } = require('vk-io');
const { SessionManager } = require('@vk-io/session');
const { SessionStorage } = require('@vbots/session-storage');

const vk = new VK({
    token: process.env.TOKEN
});

async function startBot({ updates }) {
    // 
    const storage = new SessionStorage({ name: 'anotherBot' });
    // Init DB folder & file
    await storage.init();

    const sessionManager = new SessionManager({
        storage,
        // For test
        getStorageKey: (context) => context.userId ? (`${context.userId}_${context.userId}`) : (`${context.peerId}_${context.senderId}`)
    });

    // Init user session storage
    updates.on('message', sessionManager.middleware);

    // ...
    updates.hear('/counter', async (context) => {
        const { session } = context;

        if (!session.counter) {
            session.counter = 0;
        }

        session.counter += 1;

        await context.send(`You turned to the bot (${session.counter}) times`);
    });

    // ...
    updates.start().catch(console.error);
}

// ...
startBot(vk);

Current Tags

  • 0.0.4                                ...           latest (3 months ago)

4 Versions

  • 0.0.4                                ...           3 months ago
  • 0.0.3                                ...           3 months ago
  • 0.0.2                                ...           3 months ago
  • 0.0.1                                ...           4 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |