# vk-api-bot

> Module for develop vk.com bot

Latest version **0.2.6** (published 2018-05-23) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install vk-api-bot
pnpm add vk-api-bot
yarn add vk-api-bot
bun add vk-api-bot
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.6 |
| Published | 2018-05-23 |
| First published | 2018-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Колесавин Александр |
| Maintainers | devjess |
| Keywords | vk, vk.com, bot, nodejs, js |

## Links

- npm: https://www.npmjs.com/package/vk-api-bot
- Repository: https://github.com/KolesavinAV/vk-api-bot
- Homepage: https://github.com/KolesavinAV/vk-api-bot#readme
- Issues: https://github.com/KolesavinAV/vk-api-bot/issues
- npm.io page: https://npm.io/package/vk-api-bot

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.2.6 (latest) — 2018-05-23
- 0.2.5 — 2018-05-22
- 0.1.0 — 2018-04-28

## README

# NodeJS message bot for vk.com public group

## Installation:  
You can easily install this nodejs module with `npm`
```
npm install vk-api-bot
```
---
## Usage:  
After installation you should require module and create bot object:  
   
```javascript
const VKBot = require('vk-api-bot')

const bot = new VKBot(token, group_id, prefix, commands)

bot.listen()
```
`Token` is string which you can recieve following this [instruction](https://vk.com/dev/access_token).  
`Group_id` is your group identifier.  
`Prefix` is sybmol, that you'll write before bot's commands.   
`Commands` is array, that contains list of commands, with which bot will interact.  

`Listen` function is necessary to bot start read incomming messages.

### Commands array example:
```javascript
const commands = [
    {
        command: 'commandName',
        desc: 'Command description',
        action: function (userId, value) {
            console.log(`Message from user ${userId}`)
        }
    },
    ...another commands
]
```

When the bot recieved a message - he parsing it and if the first word equals one of defined commands he execute the corresponding function, which contains two parameters: `userId` - identifier of user who sended a message and `value` - some value, has been written after command in a message. If you don't wrote some addition values to command, parameter `value` will be equal `undefined`.

`Desc` parameter is description of command. It's doesn't using now, but it will be implemented in closest patch.

---
### Also
Bot can respond to all messages. It can be used by hanle `message` event.  
```javascript
const VKBot = require('vk-api-bot')

const bot = new VKBot(token, group_id, prefix, commands)

bot.on('message', response => {
    console.log(`Message ${response.message} was recieved from user with id ${response.userId}`)
})

bot.listen()
```  
In additoin bot have this list of methods:  
* *response(userId, message)* - send a message to user. Require two parameters: `userId` and `message`.
* *callApi(method, token, [parameters, [callback]])* - call some api method. Require two necessary parameters: `method`, the list of which is [here](https://vk.com/dev/methods) and your group token, which contains in `bot.token` parameter. And this function contains two unnecassary parameters: `parameters` is object of transmitted parameters to the api method (the names of object parameters must be the same as transmitted parameters names), `callback` is callback function like `function(data){}`.
  * *data* - parameter of callback function, represents answer from vk.com api server.

---
_Source: https://npm.io/package/vk-api-bot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
