Git Product home page Git Product logo

vk-fast-longpoll's Introduction

vk-fast-longpoll

RU | Мощный инструмент для работы с VK API, который работает в 25 раз быстрее обычных вызовов API методов.

EN | Powerfull tool for VK api that works 25 times faster then usual api calls

NPM version NPM downloads

Русский

Установка и начало работы

Установка

npm install vk-fast-longpoll --save

Инициализация

const VK = require('vk-fast-longpoll');
const group = new VK('token here');

Запуск longpoll соединения

group.longpoll.start();

Начинаем слушать сообщения

group.longpoll.on('message', (message) => {
    if(!message.isOutbox)
    {
        //Отвечаем на сообщение
    }
});

Вызов API методов

Все методы VK должны вызываться с префиксом api например

group.api.messages.send({user_id: 1, message: 'Привет, Паша'});

Методы возвращают Promise-ы, поэтому стоит добавлять обработчик ошибок к каждому вызову.

group.api.messages.send({user_id: 1, message: 'Привет, Паша'}).catch(console.error);

Все названия методов, а также названия полей полностью соответсвуют названиям из документации VK

Echo пример

const VK = require('vk-fast-longpoll');
const group = new VK('token here');

group.longpoll.start();

group.longpoll.on('message', (message) => {
    if(!message.isOutbox)
    {
        group.api.messages.send({user_id: message.sender, message: message.text}).then(() => {
            console.log(message.text);
        }).catch(console.error);
    }
});

Загрузка файлов

//В разработке

English

Installing and getting started

Installing

npm install vk-io --save

Initializing

const VK = require('vk-fast-longpoll');
const group = new VK('token here');

Longpoll connection start

group.longpoll.start();

Listen to messages

group.longpoll.on('message', (message) => {
    if(!message.isOutbox)
    {
        //Reply message
    }
});

API method calls

All VK Api methods must be called with api prefix

group.api.messages.send({user_id: 1, message: 'Hello, Pasha'});

All methods return Promises, therefor you need to catch errors in every api call.

group.api.messages.send({user_id: 1, message: 'Hello, Pasha'}).catch(console.error);

All methods names and fields names are equal as VK Api docs

Echo example

const VK = require('vk-fast-longpoll');
const group = new VK('token here');

group.longpoll.start();

group.longpoll.on('message', (message) => {
    if(!message.isOutbox)
    {
        group.api.messages.send({user_id: message.sender, message: message.text}).then(() => {
            console.log(message.text);
        }).catch(console.error);
    }
});

File uploading

//In development

vk-fast-longpoll's People

Contributors

emcifuntik avatar profbiss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vk-fast-longpoll's Issues

Добавить событие на кик/добавление юзера в чате

Доброго дня, очень понравилась ваша библиотека, но в ней не хватает возможности детально получить сообщение об операции добавления или удаления пользователя из чата.
Насколько я знаю, longpoll вк присылает их в виде:
source_act: chat_kick_user (удаление),
source_act: chat_invite_user (добавление)
И в source_mid содержится id кикнутого/добавленого пользователя.

В идеале, хотелось бы видеть обработчики на все доступные source_act (chat_create, chat_title_update, chat_photo_update, chat_invite_user, chat_kick_user).

Если возможно реализовать, буду благодарен :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.