VK Chat Bot

This is a chat bot library for VK communities (groups).
See the wiki for description of all features.
Changelog is available here.
Features
- Easy to use - setting up behavior is simple - see Behavior setup
- Respects the quota - the library calls VK API not more then 20 times/second, so you don't exceed the quota
Usage
Installation
npm i vk-chat-bot
Example
You can find the example in the vk-chat-bot-example
repository.
Also, you can take a look at the step-by-step Heroku Deploy Guide.
Quick Start
1. Preparation
First, require()
the library:
const vk = require('vk-chat-bot')
Then, create your bot using the vk.bot
function (see Params object for more information about params
):
var params = {
vk_token: 'your_vk_access_token',
confirmation_token: 'f123456',
group_id: 1234567,
secret: 's3r10us1y_s3cr3t_phr4s3',
port: 12345,
cmd_prefix: "/"
}
var {bot, core} = vk.bot(params)
2. Behavior setup
See Core
wiki to learn more about behavior functions.
Here are some examples:
core.on('no_match', $ => {
$.text("I don't know how to respond to your message.")
})
var Keyboard = vk.kbd.Keyboard
var Button = vk.kbd.Button
var colors = vk.kbd.colors
core.cmd('keyboard', $ => {
var kbd = new Keyboard([
[
new Button('Default'),
new Button('Primary', colors.primary),
new Button('Negative', colors.negative),
new Button('Positive', colors.positive)
],
[
new Button('Maximum rows is 10, columns - 4.')
],
], false)
$.text('Here is your keyboard, as promised.')
$.keyboard(kbd)
})
core.cmd('help', $ => {
$.text('Test Bot v1.0' + core.help())
$.attach('photo', 6492, 456240778)
}, 'shows the help message')
core.regex(/h(i|ello|ey)/i, $ => {
$.text('Hello, I am a test bot. You said: ' + $.msg)
})
3. Start it!
Start the bot:
bot.start()
The bot will log some useful information, see Logging wiki for more information.
Contributing
License
This project is licensed under the terms of the MIT license.