16.0.0 • Published 4 years ago

vk-chat-bot v16.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

❮vk-chat-bot❯

version downloads bundle size

Package for easy creation of chat bots for VK communities (groups). Uses Callback API. documentation »changelog »featuresusagecontributinglicense

Features

  • Easy to use — setting up behavior is simple — see 2. Behavior setup below
  • Respects the quota — the package calls VK API not more then 20 times/second, so you don't exceed the quota

The version of VK API used by this package can be found here.

Usage

Installation

$ yarn add vk-chat-bot

Example

You can find an example bot in the u32i64/vk-chat-bot-example repository.

  • Deploying on Glitch

    Simply press the button below and follow the SETUP.md file there:

  • Deploying on Heroku

    You can find a step-by-step guide on deploying the example to Heroku here.

Quick Start

1. Preparation

First, require() the package:

const vk = require('vk-chat-bot');

Then, create your bot using the vk.bot function (see Params object for more information about params):

const params = {
  vkToken: 'your_vk_access_token',
  confirmationToken: 'f123456',
  groupId: 1234567,
  secret: 's3r10us1y_s3cr3t_phr4s3',
  port: 12345,

  cmdPrefix: '/'
};

var { bot, core } = vk.bot(params);

2. Behavior setup

See Core wiki to learn more about behavior functions. Here are some examples:

// Use stuff from the package...
const { Color, button, Keyboard } = vk.kbd;

// ...to create a keyboard like this.
// +-----------+---------+----------+----------+
// | Secondary | Primary | Negative | Positive |
// +-----------+---------+----------+----------+
// |      Maximum rows is 10, columns - 4.     |
// +-------------------------------------------+
var kbd = new Keyboard([
  [ /* Row (array of buttons) */
    button.text('Secondary'),
    button.text('Primary', Color.Primary),
    button.text('Negative', Color.Negative),
    button.text('Positive', Color.Positive)
  ],
  [
    button.text('Maximum rows is 10, columns - 4.')
  ],
]);

// When user presses the `Start` button...
// (you have to enable the button in community settings)
core.on('start', $ => {
  // ...send them our keyboard.
  $.text('Thanks for messaging us! Choose from the options below:');
  $.keyboard(kbd);

  // Here, $.send() is added automatically.
});
// Searches for cmd_prefix + 'help', e.g. '/help'
core.cmd('help', $ => {
  // core.help() returns the help message
  $.text('Test Bot v1.0' + core.help());

  // Attach an image from
  // https://vk.com/team?z=photo6492_45624077
  $.attach('photo', 6492, 456240778);
}, 'shows the help message');
// Use case-insensitive regular expression to find words 'hi', 'hello' or 'hey'
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 documentation for more information.

Contributing

  • Something does not seem right or you have a feature request? Open an issue.
  • You know how to make vk-chat-bot better? Open a pull request!

License

This project is licensed under the terms of the MIT license.

16.0.0

4 years ago

15.1.0

5 years ago

15.0.1

5 years ago

15.0.0

5 years ago

14.0.0

5 years ago

13.1.3

5 years ago

13.1.2

5 years ago

13.1.1

5 years ago

13.1.0

5 years ago

13.0.3

5 years ago

13.0.2

5 years ago

13.0.1

5 years ago

13.0.0

5 years ago

12.1.0

5 years ago

12.0.0

6 years ago

11.0.1

6 years ago

11.0.0

6 years ago

10.5.1

6 years ago

10.5.0

6 years ago

10.4.1

6 years ago

10.4.0

6 years ago

10.3.0

6 years ago

10.2.0

6 years ago

10.1.1

6 years ago

10.1.0

6 years ago

10.0.4

6 years ago

10.0.3

6 years ago

10.0.2

6 years ago

10.0.1

6 years ago

10.0.0

6 years ago

9.3.1

6 years ago

9.3.0

6 years ago

9.2.0

6 years ago

9.1.2

6 years ago

9.1.1

6 years ago

9.1.0

6 years ago

9.0.1

6 years ago

9.0.0

6 years ago

8.3.2

6 years ago

8.3.1

6 years ago

8.3.0

6 years ago

8.2.2

6 years ago

8.2.1

6 years ago

8.2.0

6 years ago

8.1.0

6 years ago

8.0.0

6 years ago

7.0.2

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.0.5

6 years ago

6.0.4

6 years ago

6.0.3

6 years ago

6.0.2

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.4.5

6 years ago

5.4.4

6 years ago

5.4.3

6 years ago

5.4.2

6 years ago

5.4.1

6 years ago

5.4.0

6 years ago

5.3.16

6 years ago

5.3.15

6 years ago

5.3.14

6 years ago

5.3.13

6 years ago

5.3.12

6 years ago

5.3.11

6 years ago

5.3.10

6 years ago

5.3.9

6 years ago

5.3.8

6 years ago

5.3.7

6 years ago

5.3.6

6 years ago

5.3.5

6 years ago

5.3.4

6 years ago

5.3.3

6 years ago

5.3.2

6 years ago

5.3.1

6 years ago

5.3.0

6 years ago

5.2.3

6 years ago

5.2.2

6 years ago

5.2.1

6 years ago

5.2.0

6 years ago

5.1.4

6 years ago

5.1.3

6 years ago

5.1.2

6 years ago

5.1.1

6 years ago

5.1.0

6 years ago

5.0.12

6 years ago

5.0.11

6 years ago

5.0.10

6 years ago

5.0.9

6 years ago

5.0.8

6 years ago

5.0.7

6 years ago

5.0.6

6 years ago

5.0.5

6 years ago

5.0.4

6 years ago

5.0.3

6 years ago

5.0.2

6 years ago

5.0.1

6 years ago

5.0.0

6 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.1.11

6 years ago

3.1.10

6 years ago

3.1.9

6 years ago

3.1.8

6 years ago

3.1.7

6 years ago

3.1.6

6 years ago

3.1.5

6 years ago

3.1.4

6 years ago

3.1.3

6 years ago

3.1.2

6 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.13

6 years ago

2.1.12

6 years ago

2.1.11

6 years ago

2.1.10

6 years ago

2.1.9

6 years ago

2.1.8

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago