UNPKG

nodevk-ts

Version:

Simple Node.js module that allows you to interact with the VKontakte API.

25 lines (24 loc) 891 B
import { GroupSession } from "../app.js"; import VKAPIException from "../VKAPIException.js"; export class InvokeMethodException extends Error { constructor(method_name, TypeSession, additional_message = "") { super(`Don't call method ${method_name} with ${TypeSession} access token${additional_message ? " " + additional_message : ""}.`); } } export default class API { constructor(Session) { this.type = "app"; this.Session = Session; if (Session instanceof GroupSession) this.type = "group"; } checkValid(...types) { return types.indexOf(this.type) != -1; } async call(method, params) { const response = await this.Session.invokeMethod(method, params); if (response.error) throw new VKAPIException(response.error); return response.response; } }