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

API for VK bots on long poll.

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-vk-bot-api node-vk-bot-api

node-vk-bot-api

API for VK bots, based on Long Poll.

Install

$ npm i node-vk-bot-api

Example

const API = require('node-vk-bot-api')

const bot = new API(process.env.TOKEN)

bot.command('start', ({ reply }) => reply('This is start!'))
bot.hears(/(car|tesla)/, ({ reply }) => reply('I love Tesla!'))
bot.on(({ reply }) => reply('What?'))

bot.listen()

Methods

constructor(options)

ParameterTypeRequired
tokenstringyes

Create bot.

const bot = new API(process.env.TOKEN)

.use(callback)

ParameterTypeRequired
callbackfunctionyes

Add middleware.

bot.use(ctx => ctx.date = new Date())

bot.on(({ date }) => {
  // Fri Nov 24 2017 16:00:21 GMT+0300 (MSK)
})

.command(command, callback)

ParameterTypeRequired
commandstringyes
callbackfunctionyes

Add command w/ strict match.

bot.command('start', ({ reply }) => reply('This is start!'))

.hears(command, callback)

ParameterTypeRequired
commandstring/regexpyes
callbackfunctionyes

Add command w/ match like RegEx.

bot.hears(/(car|tesla)/, ({ reply }) => reply('I love Tesla!'))

.on(callback)

ParameterTypeRequired
callbackfunctionyes

Add reserved callback.

bot.on(({ reply }) => {
  reply('What?')
})

.listen()

Start listen.

Context Methods

.reply(peer_id, message, attachment, callback)

ParameterTypeRequried
user_idnumber or arrayyes
messagestringyes (no, if setten attachment)
attachmentstringyes (no, if setten message)
callbackfunctionno

Send a message to user.

bot.command('start', (ctx) => {
  // with shortcut from context
  ctx.reply('Hi, this is start!')
  // function from context
  ctx.sendMessage(ctx.peer_id, 'Hi, this is start!')
  // simple usage
  bot.reply(ctx.peer_id, 'Hi, this is start!')
})

License

MIT.

Keywords

FAQs

Package last updated on 23 Jan 2018

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