node-ts-vk-api

import pkg from 'node-ts-vk-api'; const {Bot} = pkg;

Usage no npm install needed!

<script type="module">
  import nodeTsVkApi from 'https://cdn.skypack.dev/node-ts-vk-api';
</script>

README

Simple Vk api for typescript

Basic Exaple

import pkg from 'node-ts-vk-api';
const {Bot} = pkg;

const bot = new Bot({
    token: 'YOUR TOKEN HERE'
});

bot.api.method('messages.send', { message: 'Hello World!', peer_id: 1 /* your vk id */});

Uploading Photos for Message

import pkg from 'node-ts-vk-api';
const {Bot} = pkg;
import { createReadStream } from "fs";

const user_id = 1; // id where do you want to send message with photo

const bot = new Bot({
    token: 'YOUR TOKEN HERE'
});

async function main(){
    const { id } = await bot.api.upload(createReadStream('./image.png'), user_id); //creating fs reading stream and uploading image to vk server
    await bot.api.method('messages.send', { message: 'Hello World!', peer_id: user_id, atachement: `photo${user_id}_${id}`});
}
main();