Node PonyApi - Simple Node.js VK API Realization
Installation
npm i node-ponyapi
Usage
var PonyApi = require('node-ponyapi')
var bot = new PonyApi('Your Access Token')
bot.users.get((res) => {
console.log(res);
})
bot.on('message', (msg) => {
console.log(msg);
})
Table of contents
API methods
You can use any available method from VK API.
For example, this method returns users with IDs 1, 2, 3:
bot.users.get({user_ids: '1,2,3'}, (res) => {
console.log(res);
})
Look for another available methods here - https://vk.com/dev/methods
LongPool events
'message'
Message received.
bot.on('message', (msg) => {
console.log(`Received message with text: '${msg.text}'`);
})
'chat_invite_user'
User entered chat.
bot.on('chat_invite_user', (msg) => {
console.log(`User ${msg.attachments.source_mid} added to chat room`);
})
'chat_kick_user'
User leave chat.
bot.on('chat_kick_user', (msg) => {
console.log(`User ${msg.attachments.source_mid} leave a chat`);
})
'chat_title_update'
Chat name changed
bot.on('chat_title_update', (msg) => {
console.log(`Chat name is changed to "${msg.attachments.source_text}"`);
})
'chat_photo_update'
Chat photo changed
bot.on('chat_photo_update', (msg) => {
console.log('Chat photo is changed');
})
'chat_create'
Chat created
bot.on('chat_create', (msg) => {
console.log('Chat is changed');
})
Messaging
Object "msg" has two methods for send messages.
Reply method sends message with attaching original message:
bot.on('message', (msg) => {
if (msg.text == 'test')
msg.reply('passed')
})
Send method just send message to peer of original message:
bot.on('message', (msg) => {
if (msg.text == 'test')
msg.send('passed')
})