GTVKApi
This API for VK (Actually it mix of two APIs) that mostly adapted for bots, but can be used for anything
It written in TypeScript, but can be used in JS too.
All examples in this readme written in TS.
.d.ts files for used APIs and this api can be found on github
For node imports will be converted like this:
import {name1, name2} from 'gt-vk-api';
->
var vk = require('gt-vk-api');
var name1 = vk.name1;
var name2 = vk.name2;
or just require and use vk.name1; vk.name2;
and
import Name = require('name');
->
var Name = require('name');
bot
in all examples is bot from vk-bot-api so you can also use all it features
Authentication:
With login & pass:
import {auth, Creditanials} from 'gt-vk-api';
const credentials: Credentials = {
client_id: 0,//Application ID
login: 'login|email|phone',
pass: 'password',
phone: 'phone',
scope: ['messages', 'photos', 'users', 'audio']
};
//Second argumet is prefix for bot command
auth(credentials, '!').then(bot => {
//You have access to api now
}).catch(e => {
//Authorization faild, e describes the error
});
With token:
import {authToken} from 'gt-vk-api';
import Bot = require('vk-bot-api');
//Second argumet is prefix for bot command
var bot: Bot = authToken('...token...', '!');
//You have access to api now
Api access:
import {$} from 'gt-vk-api';//$ can be replaced with 'callApi'
$('method.name', {
param1: 1,
parame2" 'foo'
}, bot /*Optional, if ommited last authenticated bot will be used*/).then(res => {
//res is 'response' param from json returned by vk
}.catch(e => {
//Error
});
Sending message:
By peer_id (User id || chat id + 2000000000 || -group id)
bot.sendMessage(peer_id, "message");
By message ('message.getById' or from frist arg in command (see below)):
import {reply} from 'gt-vk-api';
reply(msg, "message", bot /*Optional, if ommited last authenticated bot will be used*/);
Commands:
import {createCommand, Message} form 'gt-vk-api'
//Should be used after authentication
createCommand('commandName' (msg: Message, args: string[]) => {
//Perform command here
}
Regex can also be used:
import {createCommand, Message} form 'gt-vk-api'
//Should be used after authentication
createCommand('/commandNam.?/i' (msg: Message, args: string[]) => {
//Perform command here
}