Skip to content

Latest commit

 

History

History

session

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

VK-IO Session

NPM version Build Status NPM downloads

VK-IO Session - Simple implementation of the sessions ⚙️

📦 Installation

Node.js 12.20.0 or newer is required

  • Using npm (recommended)
    npm i @vk-io/session
  • Using Yarn
    yarn add @vk-io/session
  • Using pnpm
    pnpm add @vk-io/session

Example usage

import { VK } from 'vk-io';

import { SessionManager } from '@vk-io/session';

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

const sessionManager = new SessionManager();

vk.updates.on('message_new', sessionManager.middleware);

vk.updates.on('message_new', async (context, next) => {
    if (context.text !== '/counter') {
        return next();
    }
    
    const { session } = context;

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

    session.counter += 1;

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

vk.updates.start().catch(console.error);

Community

Useful modules that may be useful to you

If you want to add your module in the list, create a new issue in the repository.