
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
node-vk-bot-api
Advanced tools
Clean API for VK bots based on long poll with multi-dispatch send messages (~75 per second).
Clean API for VK bots based on long poll with multi-dispatch send messages (~75 per second).
$ npm install node-vk-bot-api
Full example you can see here.
const app = require('node-vk-bot-api');
app.auth(process.env.BOT_TOKEN);
app.command('/start', (data) => {
const uid = data.user_id;
app.sendMessage(uid, 'Hello, this is /start command!');
});
app.hears('hello', (data) => {
const uid = data.user_id;
app.sendMessage(uid, 'Hi!');
});
app.reserve(data => {
const uid = data.user_id;
const msg = data.msg;
app.sendMessage(uid, msg, 'wall145003487_1900');
});
app.startLongPoll();
Parameter | Type | Requried |
---|---|---|
token | string | yes |
opts | object | no |
Authting with token. Also you can set subscribers mode
and bot will reply only to subscribers.
// Bot will reply to all
app.auth(process.env.BOT_TOKEN);
// Bot will reply only to subscribers.
// If user isn't subscriber, bot will send 'Bot available only for subscribers ...'
app.auth(process.env.BOT_TOKEN, {
subscribers: 1, // mode on
gid: 138165805, // group_id
msg: 'Bot available only for subscribers. Subscribe and then try again. <3' // message
});
Parameter | Type | Requried |
---|---|---|
command | string | yes |
callback | function | yes |
If bot get message which equal to command, then will run callback.
app.command('/start', (data) => {
app.sendMessage(data.user_id, 'This is start command!');
});
Parameter | Type | Requried |
---|---|---|
command | string | yes |
callback | function | yes |
If bot hears command in message from user, then will run callback (e.g. user sent 'Hello, world' and bot hears 'hello', then bot will run callback).
app.hears('hello', (data) => {
app.sendMessage(data.user_id, 'Hi!');
});
Parameter | Type | Requried |
---|---|---|
callback | function | yes |
If bot get message and this isn't command, then will run reserved callback.
app.reserve(data => {
app.sendMessage(data.user_id, 'Sorry, you sent not command to bot.');
});
Parameter | Type | Requried |
---|---|---|
uid | number | yes |
msg | string | yes (no, if setten attach) |
attach | string | yes (no, if setten msg) |
Send message (multi-dispatch). Also you can only one argument opts
, it's must be equal to object
All params for this object you can see on messages.send page.
app.sendMessage(data.user_id, 'Hello, world!');
app.sendMessage({
user_id: data.user_id,
message: 'Hello, function takes only one argument now. It\'s opts.',
forward_messages: '123,431,544'
});
Parameter | Type | Requried |
---|---|---|
updates | array | yes |
Core function for reply message to user. In the start function calls getForwardMessage and then see is the message a command or action and calls sendMessage.
Parameter | Type | Requried |
---|---|---|
update | object | yes |
Get last message from forward message.
app.getLastMessage({
"response": {
"count": 1,
"items": [{
"id": 480,
"date": 1491653021,
"out": 0,
"user_id": 145003487,
"read_state": 1,
"title": " ... ",
"body": "",
"fwd_messages": [{
"user_id": -138165805,
"date": 1491652976,
"body": "Hello, world!"
}]
}]
}
});
Parameter | Type | Requried |
---|---|---|
update | array | yes |
Get message info from forward message. If function detects fwd_messages
, then will call getLastMessage.
app.getForwardMessage([ 4, 487, 529, 145003487, 1491653078, ' ... ', '', { fwd: '145003487_2214301' } ]);
Get long poll params.
app.startLongPoll();
Start long poll.
MIT.
FAQs
🤖 VK bot framework for Node.js, based on Bots Long Poll API and Callback API
The npm package node-vk-bot-api receives a total of 50 weekly downloads. As such, node-vk-bot-api popularity was classified as not popular.
We found that node-vk-bot-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.