Compact SDK with VK API for Node.js
npm i lib-vk
/** process.env.TOKEN — group or page token
* process.env.GROUPID — group id (if the page token does not need to be specified)
* process.env.SECRET — secret key for working with callback
* process.env.PATH — path for receiving callback events
*/
const vk = new (require('lib-vk').VK)(
{
longPoll: {
token: process.env.TOKEN,
groupId: process.env.GROUPID
},
callback: {
secret: process.env.SECRET,
path: process.env.PATH
}
}
)
/** In the event location, you can specify an array of events that will be intercepted (For pages)
* Example: ['messageNew', 'messageEdit']
*/
vk.track('messageNew', message =>
message.text == 'test' &&
vk.reply(message, 'This is a reply message') &&
vk.send(message, 'This is a normal message'))
const getUser = await vk.Query('users.get', {user_id: 1});
// Calling multiple methods at once
const response = await vk.parallelExecute([[
[
['messages.send', {chat_id: 1, random_id: 0, message: 'send 1'}],
['messages.send', {chat_id: 2, random_id: 0, message: 'send 2'}],
['users.get', {user_ids: [1, 2, 3]}]
]
]])
if(message.text === '!kick') {
if(!vk.hasReply(message)) return vk.reply(message, 'Нужно ответить на сообщение кого исключить');
return vk.parallelExecute([
[
[['messages.removeChatUser', {member_id: message.reply_message.from_id, chat_id: message.peer_id - 2e9}],
['users.get', {user_ids: message.reply_message.from_id}]],
`messages.send({random_id: 0, message: !this[0]
? ("Не могу исключить ${message.reply_message.from_id > 0 ? '@id" + this[1][0].id + " (этого пользователя)"'
: `@club${-message.reply_message.from_id} (это сообщество)"`})
: (" ${message.reply_message.from_id > 0 ? ' @id" + this[1][0].id + "(" + this[1][0].first_name + ") исключён"'
: ` Исключил @club${-message.reply_message.from_id} (это сообщество)"`}),
chat_id: ${message.peer_id - 2e9}})`
]
])
}
Adding a new message
* messageNew
{
'type' {string}
'id' {integer}
'minorId' {integer}
'peerId' {integer}
'date' {integer}
'text' {string}
}
* messageEdit
{
'type' {string}
'id' {integer}
'minorId' {integer}
'peerId' {integer}
'date' {integer}
'text' {string}
}
* readingAllOutMessages
{
'type' {string}
'peerId' {integer}
'localId' {integer}
}
* userOnline
{
'type' {string}
'userId' {integer}
'extra' {integer}
'timestamp' {integer}
}
* userOffline
{
'type' {sting}
'userId' {integer}
'flags' {integer}
'timestamp' {integer}
}
* changingChatInfo
{
'type' {string}
'typeEventIsChat' {string}
'peerId' {integer}
'infoType' {string OR integer}
}
* messageTyping
{
'type' {string}
'userId' {integer}
'flags' {integer}
}
* messageTypingIsChat
{
'type' {string}
'userId' {integer}
'chatId' {integer}
}
* messageTypingsIsChat
{
'type' {string}
'userIds' {integer}
'peerId' {integer}
'totalCount' {integer}
'ts' {integer}
}
* recordsAudiomessage
{
'type' {string}
'userIds' {integer}
'peerId' {integer}
'totalCount' {integer}
'ts' {integer}
}
Если вам есть что предложить прошу написать мне VK