Giter Club home page Giter Club logo

node-vk-bot-api's Introduction

node-vk-bot-api node-vk-bot-api

VK Bot API

Clean API for VK bots based on long poll with multi-dispatch send messages (75 per second).

Install

$ npm i node-vk-bot-api

Example

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()

Methods

constructor(options)

Parameter Type Requried
options object yes

You need to set a key if your bot.

const bot = new VK({ token: process.env.TOKEN })

.command(command, callback)

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')
})

.hears(command, callback)

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?!')
})

.on(callback)

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!')
})

.listen()

Start listening without any parameters.

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(peerId, command, callback)

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.

License & Author

MIT. Mikhail Semin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.