Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
node-vk-bot-api
Advanced tools
🤖 VK bot framework for Node.js, based on Bots Long Poll API.
$ npm i node-vk-bot-api@2 -S # bots longpoll api
$ npm i node-vk-bot-api@1 -S # user longpoll api
const VkBot = require('node-vk-bot-api')
const bot = new VkBot({
token: process.env.TOKEN,
group_id: process.env.GROUP_ID
})
bot.command('/start', (ctx) => {
ctx.reply('Hello!')
})
bot.startPolling()
There's a few simple examples.
Create bot.
const bot = new VkBot({
token: process.env.TOKEN,
group_id: process.env.GROUP_ID
})
Add simple middleware.
bot.use((ctx, next) => {
ctx.message.timestamp = new Date().getTime()
next()
})
Add middlewares with triggers for message_new
event.
bot.command('start', (ctx) => {
ctx.reply('Hello!')
})
Add middlewares with triggers for selected events.
bot.event('message_edit', (ctx) => {
ctx.reply('Your message was editted')
})
Add reserved middlewares without triggers.
bot.on((ctx) => {
ctx.reply('No commands for you.')
})
Send message to user.
// Simple usage
bot.sendMessage(145003487, 'Hello!', 'photo1_1')
// Advanced usage
bot.sendMessage(145003487, {
message: 'Hello!',
lat: 59.939095,
lng: 30.315868
})
Start polling with given timeout (25 by default).
bot.startPolling()
Helper method for reply to the current user.
bot.command('start', (ctx) => {
ctx.reply('Hello!')
})
Markup.keyboard(buttons)
: Create keyboardMarkup.button(label, color, payload)
: Create custom buttonMarkup.oneTime()
: Set oneTime to keyboardctx.reply('Select your sport', null, Markup
.keyboard([
'Football',
'Basketball',
])
.oneTime()
)
ctx.reply('How are you doing?', null, Markup
.keyboard([
[
Markup.button('Normally', 'primary'),
],
[
Markup.button('Fine', 'positive'),
Markup.button('Bad', 'negative'),
],
])
)
Store anything for current user in local (or redis) memory.
const VkBot = require('node-vk-bot-api')
const Session = require('node-vk-bot-api/lib/session')
const bot = new VkBot({
token: process.env.TOKEN,
group_id: process.env.GROUP_ID,
})
const session = new Session()
bot.use(session.middleware())
bot.on((ctx) => {
ctx.session.counter = ctx.session.counter || 0
ctx.session.counter++
ctx.reply(`You wrote ${ctx.session.counter} messages.`)
})
bot.startPolling()
key
: Context property name (default: session
)getSessionKey
: Getter for session keygetSessionKey(ctx)
const getSessionKey = (ctx) => {
return `${ctx.message.from_id}:${ctx.message.from_id}`
}
Scene manager.
const VkBot = require('node-vk-bot-api')
const Scene = require('node-vk-bot-api/lib/scene')
const Session = require('node-vk-bot-api/lib/session')
const Stage = require('node-vk-bot-api/lib/stage')
const bot = new VkBot({
token: process.env.TOKEN,
group_id: process.env.GROUP_ID,
})
const scene = new Scene('meet',
(ctx) => {
ctx.scene.next()
ctx.reply('How old are you?')
},
(ctx) => {
ctx.session.age = +ctx.message.text
ctx.scene.next()
ctx.reply('What is your name?')
},
(ctx) => {
ctx.session.name = ctx.message.text
ctx.scene.leave()
ctx.reply(`Nice to meet you, ${ctx.session.name} (${ctx.session.age} years old)`)
}
)
const session = new Session()
const stage = new Stage(scene)
bot.use(session.middleware())
bot.use(stage.middleware())
bot.command('/meet', (ctx) => {
ctx.scene.enter('meet')
})
bot.startPolling()
constructor(...scenes)
: Register scenesconstructor(name, ...middlewares)
: Create scenectx.scene.enter(name) // Enter in scene
ctx.scene.leave() // Leave from scene
ctx.scene.next() // Go to the next step in scene
ctx.scene.selectStep(index) // Go to the selected step in scene
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 202 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.