vk-to-telegram
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -36,15 +36,17 @@ const Telegram = require('telegraf/telegram') | ||
let { attachments } = media | ||
let attachmentLink | ||
const attachmentLink = [] | ||
let poll | ||
if (attachments) { | ||
if (attachments.some(el => el.type === 'link')) { | ||
attachmentLink = attachments.find(el => el.type === 'link').link | ||
if (/^[\d?\s]*$/ig.test(attachmentLink.title)) { | ||
attachmentLink.title = 'Read' | ||
} | ||
attachments.filter(el => el.type === 'link').forEach(({ link }) => { | ||
if (/^[\d?\s]*$/ig.test(link.title)) { | ||
link.title = 'Read more' | ||
} | ||
attachmentLink.push(link) | ||
messageExtra.reply_markup.inline_keyboard.unshift([{ | ||
text: entities.decode(link.title).capitalize(), | ||
url: link.url | ||
}]) | ||
}) | ||
attachments = attachments.filter(el => el.type !== 'link') | ||
messageExtra.reply_markup.inline_keyboard.unshift([{ | ||
text: entities.decode(attachmentLink.title).capitalize(), | ||
url: attachmentLink.url | ||
}]) | ||
} | ||
@@ -71,8 +73,5 @@ if (attachments.some(el => el.type === 'poll')) { | ||
if (attachments.length === 0 && attachmentLink) { | ||
if (attachments.length === 0 && attachmentLink.length) { | ||
messageExtra.disable_web_page_preview = false | ||
telegram.sendMessage(config.get('chatId'), `<a href="${attachmentLink.url}"> </a> | ||
${mediaText ? mediaText : `<a href="${attachmentLink.url}">${entities.decode(attachmentLink.title).capitalize()}</a>`} | ||
${mediaText ? `\n<a href="${attachmentLink.url}">${attachmentLink.button ? entities.decode(attachmentLink.title).capitalize() : 'Open link source'}</a>` : ''} | ||
`, messageExtra) | ||
telegram.sendMessage(config.get('chatId'), `<a href="${attachmentLink[0].url}"> </a>${mediaText ? `${mediaText}\n\n` : ''}${attachmentLink.map(link => `<a href="${link.url}">${entities.decode(link.title).capitalize()}</a>`).join('\n')}`, messageExtra) | ||
.then(resolve) | ||
@@ -158,17 +157,2 @@ .catch(reject) | ||
}) | ||
// telegram.sendMediaGroup(config.get('chatId'), attachmentsArray) | ||
// .then(resolve) | ||
// .catch(reject) | ||
// mediaExtra.reply_markup.inline_keyboard.unshift([{ | ||
// text: entities.decode(attachments[i].album.title), | ||
// url: `https://vk.com/album${attachments[i].album.owner_id}_${attachments[i].album.id}` | ||
// }]) | ||
// mediaExtra.disable_web_page_preview = false | ||
// sender.sendPhoto(attachments[i].album.thumb, null, mediaExtra) | ||
// .then(msg => { | ||
// i++ | ||
// mediaPoster(msg) | ||
// }) | ||
// .catch(reject) | ||
} else { | ||
@@ -293,5 +277,6 @@ attachments = attachments.filter(el => el.type !== 'link') | ||
} else { | ||
if (attachmentLink) { | ||
if (attachmentLink.length) { | ||
messageExtra.disable_web_page_preview = false | ||
telegram.sendMessage(config.get('chatId'), `<a href="${attachmentLink.url}"> </a><a href="${attachmentLink.url}">${attachmentLink.button ? `Read "${attachmentLink.title.capitalize()}"` : 'Open source'}</a>`, messageExtra) | ||
telegram.sendMessage(config.get('chatId'), `<a href="${attachmentLink[0].url}"> </a>${attachmentLink.map(link => `<a href="${link.url}">${entities.decode(link.title).capitalize()}</a>`).join('\n')}`, messageExtra) | ||
.then(msg => mediaPoster(msg)) | ||
@@ -298,0 +283,0 @@ .catch(reject) |
@@ -192,19 +192,24 @@ const Telegram = require('telegraf/telegram') | ||
.then(response => { | ||
const video = response.response.items[0] | ||
const apivideo = response.response.items[0] | ||
let vk = false | ||
switch (video.platform) { | ||
case 'YouTube': // https://www.youtube.com/embed/qLQr0VrMVQk?__ref=vk.api -> https://www.youtube.com/watch?v=tyHAI-70DSg | ||
video.player = `https://youtube.com/watch?v=${video.player.match(/https:\/\/www\.youtube\.com\/embed\/(\S+)\?/i)[1]}` | ||
break | ||
case 'Vimeo': // https://player.vimeo.com/video/231140379?__ref=vk.api -> https://vimeo.com/231140379 | ||
video.player = `https://vimeo.com/${video.player.match(/https:\/\/player\.vimeo\.com\/video\/(\S+)\?/i)[1]}` | ||
break | ||
case undefined: // vk | ||
vk = true | ||
video.player = `https://vk.com/video${video.owner_id}_${video.id}` | ||
break | ||
default: | ||
vk = true | ||
video.player = `https://vk.com/video${video.owner_id}_${video.id}` | ||
break | ||
if (apivideo) { | ||
switch (apivideo.platform) { | ||
case 'YouTube': // https://www.youtube.com/embed/qLQr0VrMVQk?__ref=vk.api -> https://www.youtube.com/watch?v=tyHAI-70DSg | ||
apivideo.player = `https://youtube.com/watch?v=${apivideo.player.match(/https:\/\/www\.youtube\.com\/embed\/(\S+)\?/i)[1]}` | ||
break | ||
case 'Vimeo': // https://player.vimeo.com/video/231140379?__ref=vk.api -> https://vimeo.com/231140379 | ||
apivideo.player = `https://vimeo.com/${apivideo.player.match(/https:\/\/player\.vimeo\.com\/video\/(\S+)\?/i)[1]}` | ||
break | ||
case undefined: // vk | ||
vk = true | ||
apivideo.player = `https://vk.com/video${apivideo.owner_id}_${apivideo.id}` | ||
break | ||
default: | ||
vk = true | ||
apivideo.player = `https://vk.com/video${apivideo.owner_id}_${apivideo.id}` | ||
break | ||
} | ||
} else { | ||
video.player = `https://vk.com/video${video.owner_id}_${video.id}` | ||
vk = true | ||
} | ||
@@ -219,4 +224,3 @@ extra.disable_web_page_preview = false | ||
return telegram.sendMessage(chatId, | ||
`<a href="${vk ? utils.video.getPreview(video) : video.player}"> </a> | ||
${text ? `${text}\n\n` : ''}<a href="${video.player}">${video.title}</a>`, | ||
`<a href="${vk ? utils.video.getPreview(video) : video.player}"> </a>${text ? `${text}\n\n` : ''}<a href="${video.player}">${video.title}</a>`, | ||
extra) | ||
@@ -223,0 +227,0 @@ }) |
{ | ||
"name": "vk-to-telegram", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Vk to telegram forwarder", | ||
@@ -5,0 +5,0 @@ "author": "ejnshtein", |
const vkToTelegram = require('./index'), | ||
app = require('express')(), | ||
bodyParser = require('body-parser'), | ||
axios = require('axios'), | ||
config = require('./config.json'), | ||
@@ -5,0 +6,0 @@ vkToTg = new vkToTelegram({ |
57300
1124