Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-vk-bot-api

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-vk-bot-api

Clean API for VK bots based on long poll with multi-dispatch send messages (~75 per second).

  • 0.1.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
125
decreased by-42.66%
Maintainers
1
Weekly downloads
 
Created
Source

VK Bot API

Clean API for VK bots based on long poll with multi-dispatch send messages (~75 per second).

Install

$ npm install node-vk-bot-api

Example

Full example you can check in examples folder.

const app = require('node-vk-bot-api');

app.auth(process.env.BOT_TOKEN);

app.command('/start', (data) => {
  const uid = data.user_id;

  app.sendMessage({ user_id: uid, message: 'Hello, this is /start command!' });
});

app.hears('hello', (data) => {
  const uid = data.user_id;

  app.sendMessage({ user_id: uid, message: 'Hi!' });
});

app.reserve(data => {
  const uid = data.user_id;
  const msg = data.msg;

  app.sendMessage({ user_id: uid, message: msg }); // => '{ response: [ 3 ] }'
});

app.startLongPoll();

Methods

.auth(token)

ParameterTypeRequried
tokenstringyes

Authting with token.

app.setToken('88935996c67c290f47b79a0c8b0093227e916ce14c62e490aa96c8f8ed3090c9cbcdda92c8fadf1f5c74c');

.command(command, callback)

ParameterTypeRequried
commandstringyes
callbackfunctionyes

If bot get message which equal to command, then will run callback.

app.command('/start', (data) => {
  app.sendMessage({ user_id: data.user_id, message: 'This is start command!' });
});

.hears(command, callback)

ParameterTypeRequried
commandstringyes
callbackfunctionyes

If bot hears command in message from user, then will run callback (e.g. user sent 'Hello, world' and bot hears 'hello', then bot will run callback).

app.hears('hello', (data) => {
  app.sendMessage({ user_id: data.user_id, message: 'Hi!' });
});

.reserve(callback)

ParameterTypeRequried
callbackfunctionyes

If bot get message and this isn't command, then will run reserved callback.

app.reserve(data => {
  app.sendMessage({ user_id: data.user_id, message: 'Sorry, you sent not command to bot.' });
});

.sendMessage(opts)

ParameterTypeRequried
optsobjectyes

Send message (multi-dispatch).

app.sendMessage({ user_id: data.user_id, message: 'Hello, world!' });

.getLastMessage(update)

ParameterTypeRequried
updateobjectyes

Get last message from forward message.

app.getLastMessage({
  "response": {
    "count": 1,
    "items": [{
      "id": 480,
      "date": 1491653021,
      "out": 0,
      "user_id": 145003487,
      "read_state": 1,
      "title": " ... ",
      "body": "",
      "fwd_messages": [{
        "user_id": -138165805,
        "date": 1491652976,
        "body": "Hello, world!"
      }]
    }]
  }
});

.getForwardMessage(update)

ParameterTypeRequried
updatearrayyes

Get message info from forward message. If function detects fwd_messages, then will call .getLastMessage(update).

app.getForwardMessage([ 4, 487, 529, 145003487, 1491653078, ' ... ', '',  { fwd: '145003487_2214301' } ]);

.startLongPoll()

Get long poll params.

app.startLongPoll();

.getLongPoll()

Start long poll.

License

MIT.

Keywords

FAQs

Package last updated on 08 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc