Clean API for VK bots based on long poll with multi-dispatch send messages (75 per second).
$ npm i node-vk-bot-api
const VK = require('node-vk-bot-api')
const bot = new VK({ token: process.env.TOKEN })
bot.command('attach', (ctx) => {
ctx.reply('Do you need attachment? Take it easy!', 'wall145003487_2068')
})
bot.hears('hello', (ctx) => {
ctx.sendMessage(ctx.user_id, 'Did you say hello to me?!')
})
bot.on((ctx) => {
ctx.reply('I don\'t understand you!')
})
bot.listen()
Parameter | Type | Requried |
---|---|---|
options | object | yes |
You need to set a key if your bot.
const bot = new VK({ token: process.env.TOKEN })
Parameter | Type | Requried |
---|---|---|
command | string | yes |
callback | function | yes |
If the bot get a message which equal to command, then will run a callback.
bot.command('attach', (ctx) => {
ctx.reply('Do you need attachment? Take it easy!', 'wall145003487_2068')
})
Parameter | Type | Requried |
---|---|---|
command | string | yes |
callback | function | yes |
If the bot hears a command in message from user, then will run callback (e.g. user sent 'Hello, world' and bot hears 'hello', then bot will run a callback).
bot.hears('hello', (ctx) => {
ctx.sendMessage(ctx.user_id, 'Did you say hello to me?!')
})
Parameter | Type | Requried |
---|---|---|
callback | function | yes |
If the bot receives a message and doesn't find an answer to it, it will run a callback.
bot.on((ctx) => {
ctx.reply('I don\'t understand you!')
})
Start listening without any parameters.
Parameter | Type | Requried |
---|---|---|
message | string | yes (no, if setten attachment) |
attachment | string | yes (no, if setten message) |
Send a message to the current user.
Parameter | Type | Requried |
---|---|---|
peerId | number | yes |
message | string | yes (no, if setten attachment) |
attachment | string | yes (no, if setten message) |
Send a message to any user.
MIT. Mikhail Semin.