@vk-io/session
TypeScript icon, indicating that this package has built-in type declarations

2.2.1 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i @vk-io/session

Weekly Downloads

29

Version

2.2.1

License

MIT

Unpacked Size

10.3 kB

Total Files

10

Last publish

Collaborators

  • negezor