Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vk-to-telegram

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vk-to-telegram - npm Package Compare versions

Comparing version 0.2.7 to 0.2.8

5

index.js
const forwarder = require('./lib/forwarder')
const debug = require('debug')('Forwarder')
const Telegram = require('telegraf/telegram')

@@ -83,3 +82,2 @@ const vkApi = require('./lib/vkapi')

}
debug('Post body: %b', body)
if (body.type === 'confirmation') {

@@ -103,3 +101,2 @@ await callback(this.vkConfirmation)

if (this.debug) {debug('heroku Obj: %p', herokuPosts) }
if (this.heroku) {

@@ -137,3 +134,2 @@ const { originalUrl } = request

}
if (this.debug) {debug('heroku Obj: %p', herokuPosts) }
if (this.fromId ? body.object.from_id !== this.fromId : false) {

@@ -173,3 +169,2 @@ throw `Wrong post from_id: ${body.object.from_id} !== ${this.fromId}`

const chatId = this.chatId ? this.chatId : (await telegram.getChat(this.chatName)).id
if (this.debug) { debug('chatId: %c', chatId) }
this.chatId = chatId

@@ -176,0 +171,0 @@ const forward = forwarder(this)

33

lib/forwarder.js
const Telegram = require('telegraf/telegram')
const debug = require('debug')('forwarder')
const utils = require('./utils')

@@ -24,5 +23,2 @@ const defaultConfig = require('./default-config')

let mediaText = post.text || ''
if (config.debug) {
debug('Forwarding post: %m', post)
}
mediaText = mediaText.replace(/\[(\S+)\|([\S\s]*?)\]/ig, '<a href="https://vk.com/$1">$2</a>') // parse vk markdown to html [vkId|Text] => <a href=vk.com/vkId>Text</a>

@@ -125,3 +121,3 @@ mediaText = decode(mediaText)

}
return Promise.all([telegram.sendMessage(chatId, mediaText, messageExtra), telegram.sendMediaGroup(chatId, attachmentsArray)])
return [await telegram.sendMessage(chatId, mediaText, messageExtra), await telegram.sendMediaGroup(chatId, attachmentsArray)]
} else {

@@ -131,9 +127,6 @@ attachments = attachments.filter(el => el.type !== 'link')

let mediaExtra = messageExtra
const mediaPoster = async post => {
const posts = post ? [post] : []
if (config.debug) {
debug('Forwarding posts')
}
const mediaPoster = async message => {
const messages = message ? [message] : []
for (let i = 0; i < attachments.length; i++) {
if (posts.length) {
if (messages.length) {
mediaExtra = defaultConfig()

@@ -162,14 +155,14 @@ }

}
console.log(photosArray)
// console.log(photosArray)
if (photosArray.length === 1) {
posts.push(telegram.sendPhoto(chatId, photosArray[0].post.url, mediaExtra))
messages.push(await telegram.sendPhoto(chatId, photosArray[0].media.url, mediaExtra))
} else {
posts.push(telegram.sendMediaGroup(chatId, photosArray))
messages.push(await telegram.sendMediaGroup(chatId, photosArray))
}
break
case 'doc':
posts.push(sendDocument(attachments[i].doc, null, mediaExtra))
messages.push(await sendDocument(attachments[i].doc, null, mediaExtra))
break
case 'video':
posts.push(sendVideo(attachments[i].video, null, mediaExtra))
messages.push(await sendVideo(attachments[i].video, null, mediaExtra))
break

@@ -182,7 +175,7 @@ case 'album':

mediaExtra.disable_web_page_preview = false
posts.push(sendPhoto(attachments[i].album.thumb, null, mediaExtra))
messages.push(await sendPhoto(attachments[i].album.thumb, null, mediaExtra))
break
}
}
return Promise.all(posts)
return messages
}

@@ -192,7 +185,7 @@ if (mediaText) {

// console.log(JSON.stringify(messageExtra))
return mediaPoster(telegram.sendMessage(chatId, mediaText, messageExtra))
return mediaPoster(await telegram.sendMessage(chatId, mediaText, messageExtra))
} else {
if (attachmentLink.length) {
messageExtra.disable_web_page_preview = false
return mediaPoster(telegram.sendMessage(chatId, `<a href="${attachmentLink[0].url}">&#160;</a>${attachmentLink.map(link => `<a href="${link.url}">${decode(link.title).capitalize()}</a>`).join('\n')}`, messageExtra))
return mediaPoster(await telegram.sendMessage(chatId, `<a href="${attachmentLink[0].url}">&#160;</a>${attachmentLink.map(link => `<a href="${link.url}">${decode(link.title).capitalize()}</a>`).join('\n')}`, messageExtra))
} else {

@@ -199,0 +192,0 @@ return mediaPoster()

@@ -22,12 +22,12 @@ const Telegram = require('telegraf/telegram')

if (!text) {
messages.push(telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
} else if (text && text.length < 1000) {
extra.caption = `${text}\n\n<a href="${doc.url}">Open original</a>`
extra.disable_web_page_preview = true
messages.push(telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
} else {
extra.disable_web_page_preview = false
messages.push(telegram.sendMessage(chatId, text, extra))
messages.push(await telegram.sendMessage(chatId, text, extra))
extra.caption = `<a href="${doc.url}">Open original</a>`
messages.push(telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendAnimation(chatId, { url: doc.preview.video.src, filename: decode(doc.title) }, extra))
}

@@ -37,24 +37,24 @@ } else if (doc.ext === 'mp4' && doc.size < 50000000) {

if (!text) {
messages.push(telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
} else if (text && text.length < 1000) {
extra.caption = `${text}\n\n<a href="${doc.url}">Open original</a>`
extra.disable_web_page_preview = true
messages.push(telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
} else {
extra.disable_web_page_preview = false
messages.push(telegram.sendMessage(chatId, text, extra))
messages.push(await telegram.sendMessage(chatId, text, extra))
extra.caption = `<a href="${doc.url}">Open original</a>`
messages.push(telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendVideo(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
}
} else if (doc.size < 50000000) {
if (!text) {
messages.push(telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
} else if (text && text.length < 1000) {
extra.caption = text
messages.push(telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
} else {
extra.disable_web_page_preview = false
messages.push(telegram.sendMessage(chatId, text, extra))
messages.push(await telegram.sendMessage(chatId, text, extra))
extra.disable_web_page_preview = true
messages.push(telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
messages.push(await telegram.sendDocument(chatId, { url: doc.url, filename: decode(doc.title) }, extra))
}

@@ -67,7 +67,7 @@ } else {

}])
messages.push(telegram.sendMessage(chatId, text, extra))
messages.push(await telegram.sendMessage(chatId, text, extra))
}
return messages.length >= 2 ? Promise.all(messages) : messages[0]
return messages
},
async sendPhoto (photo, text = '', extra = defaultConfig()()) {
async sendPhoto (photo, text = '', extra = defaultConfig()) {
if (!text) {

@@ -74,0 +74,0 @@ return telegram.sendPhoto(chatId, utils.photo.getHQ(photo), extra)

{
"name": "vk-to-telegram",
"version": "0.2.7",
"version": "0.2.8",
"description": "Vk to telegram forwarder",

@@ -24,3 +24,2 @@ "author": "ejnshtein",

"bytes": "^3.0.0",
"debug": "^4.1.0",
"html-entities": "^1.2.1",

@@ -27,0 +26,0 @@ "telegraf": "^3.25.0"

@@ -8,3 +8,3 @@ # vk to telegram forwarder

[![telegram test channel](https://img.shields.io/badge/telegram-test%20channel-blue.svg?style=flat-square)](https://t.me/vktotgforwarderchannel)
[![telegram chat](https://img.shields.io/badge/telegram-chat-blue.svg?style=flat-square)](https://t.me/vktotgforwarder)
[![telegram chat](https://img.shields.io/badge/telegram-chat-blue.svg?style=flat-square)](https://t.me/joinchat/C3fG51BIAgI5lswcaRexMg)

@@ -11,0 +11,0 @@ ## Installation

@@ -16,3 +16,2 @@ const vkToTelegram = require('./')

const Koa = require('koa')
const route = require('koa-route')
const bodyParser = require('koa-bodyparser')

@@ -19,0 +18,0 @@ const app = new Koa()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc