const { VK } = require('vk-io');
const requst = require('request');
const moment = require('moment');
const vk = new VK({
token: 'Токен вк'
});
const bot = async ctx => {
const userdata = await vk.api.users.get({user_ids: ctx.senderId, fields: "photo_50"});
const data = ctx.message.date;
const time = moment(data * 1000).utc().format('YYYY-MM-DDTHH:mm:ss.SSS');
return {
"username": "Имя бота",
"embeds": [
{
"title": "Название записи",
"url": "https://vk.com/write" + ctx.senderId,
"color": 2451211,
"timestamp": `${time}Z`,
"author": {
"name": userdata[0].first_name + ' ' + userdata[0].last_name,
"url": "https://vk.com/gim191140619?sel=" + ctx.senderId,
"icon_url": userdata[0].photo_50
},
"fields": [
{
"name": "Сообщение",
"value": ctx.text
}
]
}
]
}
}
vk.updates.on('message', async ctx => {
if(ctx.isOutbox || !ctx.is('message')) return;
if(!ctx.isChat || ctx.isFromGroup) {
let req = requst({
method: "POST",
uri: 'Вебхук дискорд бота',
body: await bot(ctx),
json: true
},
function (err, req1, resp) {
if(!resp) return;
console.log(resp);
}
)
}
});
vk.updates.start()
.then(() => console.log('Bot has been started'));
if (ctx.chatId !== CHATID) return;
const { VK } = require('vk-io');
const requst = require('request');
const moment = require('moment');
const vk = new VK({
token: 'Токен вк'
});
const bot = async ctx => {
const userdata = await vk.api.users.get({user_ids: ctx.senderId, fields: "photo_50"});
const data = ctx.message.date;
const time = moment(data * 1000).utc().format('YYYY-MM-DDTHH:mm:ss.SSS');
return {
"username": "Имя бота",
"embeds": [
{
"title": "Название записи",
"url": "https://vk.com/write" + ctx.senderId,
"color": 2451211,
"timestamp": `${time}Z`,
"author": {
"name": userdata[0].first_name + ' ' + userdata[0].last_name,
"url": "https://vk.com/gim191140619?sel=" + ctx.senderId,
"icon_url": userdata[0].photo_50
},
"fields": [
{
"name": "Сообщение",
"value": ctx.text
}
]
}
]
}
}
vk.updates.on('message_new', async ctx => {
if(ctx.isOutbox || !ctx.is('message')) return;
if(ctx.chatId === CHATID || ctx.isFromGroup) {
let req = requst({
method: "POST",
uri: 'Вебхук дискорд бота',
body: await bot(ctx),
json: true
},
function (err, req1, resp) {
if(!resp) return;
console.log(resp);
}
)
}
});
vk.updates.start()
.then(() => console.log('Bot has been started'));