![node-vk-bot-api](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)
node-vk-bot-api
API for VK bots 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)
Parameter | Type | Requried |
---|
token | string | yes |
Create bot.
const bot = new API(process.env.TOKEN)
.command(command, callback)
Parameter | Type | Requried |
---|
command | string | yes |
callback | function | yes |
Add command w/ strict match.
bot.command('start', ({ reply }) => {
reply('This is start!')
})
.hears(command, callback)
Parameter | Type | Requried |
---|
command | string | yes |
callback | function | yes |
Add command w/ match like RegEx.
bot.hears(/(car|tesla)/, ({ reply }) => {
reply('I love Tesla!')
})
.on(callback)
Parameter | Type | Requried |
---|
callback | function | yes |
Add reserved callback.
bot.on(({ reply }) => {
reply('What?')
})
.listen()
Start listen.
Context Methods
.reply(message, attachment)
Parameter | Type | Requried |
---|
message | string | yes (no, if setten attachment) |
attachment | string | yes (no, if setten message) |
Send a message to the current user.
.sendMessage(peer, command, callback)
Parameter | Type | Requried |
---|
peer | number | yes |
message | string | yes (no, if setten attachment) |
attachment | string | yes (no, if setten message) |
Send a message to any user.
License
MIT.