How to use the vk-io.VK function in vk-io

To help you get started, we’ve selected a few vk-io examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fakemancat / vkbot-core / start.js View on Github external
// Модули
const { VK } = require('vk-io');
const vk = new VK();
const fs = require('fs');
const colors = require('colors');
const config = require("./config.js");
// database
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const adapter = new FileSync('database/db.json');
const db = low(adapter);

db.defaults({ users: [] }).write();
//

db.getUser = async(ID) => {
  let user = db.get('users').find({ id: ID }).value();
  if (!user) {
    db.get('users').push({
github negezor / vk-io / docs / examples / questionnaire / bot.js View on Github external
const { VK, Keyboard } = require('vk-io');

const { Wizard } = require('./middlewares/wizard');
const { getSessionMiddleware } = require('./middlewares/session');

const scenes = require('./scenes');

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

const wizard = new Wizard();

// Register scenes
for (const scene of scenes) {
	wizard.addScene(scene);
}

// Skip outbox messages
vk.updates.on('message', async (context, next) => {
	if (context.isOutbox) {
		return;
	}
github negezor / vk-io / docs / examples / uploads.js View on Github external
const { VK } = require('vk-io');
const fetch = require('node-fetch');

const fs = require('fs');

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

/**
 * Sets custom uploadUrl or timeout
 */
vk.upload.photoAlbum({
	source: {
		uploadUrl: '',
		timeout: 60e3,
		values: [
			// Examples of parameters below
		]
	}
});
github negezor / vk-io / docs / examples / simple-keyboard-bot.js View on Github external
const { VK, Keyboard } = require('vk-io');

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

vk.updates.on('message', (context, next) => {
	const { messagePayload } = context;

	context.state.command = messagePayload && messagePayload.command
		? messagePayload.command
		: null;

	return next();
});

// Simple wrapper for commands
const hearCommand = (name, conditions, handle) => {
	if (typeof handle !== 'function') {
github negezor / vk-io / docs / examples / hello-world.js View on Github external
const { VK } = require('vk-io');

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

vk.updates.hear(/hello/i, context => (
	context.send('World!')
));

vk.updates.start().catch(console.error);
github negezor / vk-io / docs / examples / simple-session-context.js View on Github external
const { VK } = require('vk-io');
const { SessionManager } = require('@vk-io/session');

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

const sessionManager = new SessionManager();

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

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

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

	session.counter += 1;
github negezor / vk-io / docs / examples / simple-updates-bot.js View on Github external
const { VK } = require('vk-io');

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

vk.updates.hear('/start', async (context) => {
	await context.send(`
		My commands list

		/cat - Cat photo
		/purr - Cat purring
		/time - The current date
		/reverse - Reverse text
	`);
});

vk.updates.hear('/cat', async (context) => {
	await Promise.all([
github TGXed / CocosCore / src / index.js View on Github external
async configure() {
        if (this.isConfigured) {
            return this.logger.warn('Бот уже сконфигурирован');
        }

        if (!this.token) {
            throw new ConfigureError('Не указан токен бота');
        }

        this.vk = new VK({
            apiLimit: this.apiLimit,
            apiMode: this.apiMode,
            token: this.token
        });

        await this.vk.updates.start();

        if (!this.groupId) {
            this.groupId = this.vk.options.pollingGroupId;
        }

        if (this.groupId < 0) {
            this.groupId = -this.groupId;
        }
        
        if (this.vk.options.pollingGroupId !== this.groupId) {
github negezor / vk-io / docs / examples / scene-bot.js View on Github external
const { VK } = require('vk-io');

const { SessionManager } = require('@vk-io/session');
const { SceneManager, StepScene } = require('@vk-io/scenes');

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

const sessionManager = new SessionManager();
const sceneManager = new SceneManager();

sceneManager.addScene(new StepScene('signup', [
	(context) => {
		if (context.scene.step.firstTime || !context.text) {
			return context.send('What\'s your name?');
		}

		context.scene.state.firstName = context.text;

		return context.scene.step.next();
	},