vk-to-telegram
Advanced tools
Comparing version 0.1.1 to 0.1.2
49
index.js
@@ -98,6 +98,19 @@ const forward = require('./lib/forwarder') | ||
if (this.debug) { util.log(herokuPosts) } | ||
telegram = new Telegram(this.token) | ||
vkapi = vkApi(this.vkToken) | ||
resolve() | ||
if ((this.fromId ? body.object.from_id === this.fromId : true) && body.type === 'wall_post_new' && body.object.post_type === 'post') { | ||
telegram = new Telegram(this.token) | ||
vkapi = vkApi(this.vkToken) | ||
resolve() | ||
} else { | ||
reject('Post not sent') | ||
} | ||
}) | ||
.then(() => vkapi.wall.getById(`${body.object.owner_id}_${body.object.id}`,{ | ||
copy_history_depth: 1 | ||
})) | ||
.then(response => { | ||
if (response.response && response.response[0]) { | ||
body.object = response.response[0] | ||
} | ||
}) | ||
.then(() => this.chatId ? { id: this.chatId } : telegram.getChat(this.chatName)) | ||
@@ -108,20 +121,16 @@ .then(chat => { | ||
forwarder = forward(this) | ||
if ((this.fromId ? body.object.from_id === this.fromId : true) && body.type === 'wall_post_new' && body.object.post_type === 'post') { | ||
if (body.object.text.length > 4090) { | ||
body.object.text = this.get('customLongPostText').replace(/\[([\S\s]*?)\]/ig, `<a href="https://vk.com/wall${body.object.owner_id}_${body.object.id}">$1</a>`) | ||
} | ||
if (this.signed && body.object.signer_id) { | ||
return vkapi.users.get(body.object.signer_id) | ||
.then(response => response.response[0]) | ||
.then(signer => { | ||
if (signer) { | ||
body.object.text += `\n\n[id${signer.id}|${this.signed} ${signer.first_name} ${signer.last_name ? signer.last_name : ''}]` | ||
} | ||
return forwarder(body.object) | ||
}) | ||
} else { | ||
return forwarder(body.object) | ||
} | ||
if (body.object.text.length > 4090) { | ||
body.object.text = this.get('customLongPostText').replace(/\[([\S\s]*?)\]/ig, `<a href="https://vk.com/wall${body.object.owner_id}_${body.object.id}">$1</a>`) | ||
} | ||
if (this.signed && body.object.signer_id) { | ||
return vkapi.users.get(body.object.signer_id) | ||
.then(response => response.response[0]) | ||
.then(signer => { | ||
if (signer) { | ||
body.object.text += `\n\n[id${signer.id}|${this.signed} ${signer.first_name} ${signer.last_name ? signer.last_name : ''}]` | ||
} | ||
return forwarder(body.object) | ||
}) | ||
} else { | ||
throw `post not sent ${body.object}` | ||
return forwarder(body.object) | ||
} | ||
@@ -128,0 +137,0 @@ }) |
const axios = require('axios') | ||
const origin = 'https://api.vk.com/method/' | ||
module.exports = (token) => { | ||
@@ -20,6 +20,7 @@ const vkToken = token | ||
return new Promise((resolve, reject) => { | ||
axios.get('https://api.vk.com/method/video.get', { | ||
axios.get(`${origin}video.get`, { | ||
params: Object.assign(defaultParams, { videos: videos.join(','), extended: 1 }) | ||
}) | ||
.then(response => { | ||
if (response.status !== 200) { return reject(response)} | ||
const video = response.data | ||
@@ -42,6 +43,7 @@ resolve(video) | ||
return new Promise((resolve, reject) => { | ||
axios.get('https://api.vk.com/method/docs.getById', { | ||
axios.get(`${origin}docs.getById`, { | ||
params: Object.assign(defaultParams, { docs: docs.join(',') }) | ||
}) | ||
.then(response => { | ||
if (response.status !== 200) { return reject(response)} | ||
const doc = response.data | ||
@@ -64,6 +66,7 @@ resolve(doc) | ||
return new Promise((resolve, reject) => { | ||
axios.get('https://api.vk.com/method/users.get', { | ||
axios.get(`${origin}users.get`, { | ||
params: Object.assign(defaultParams, { user_ids: users.join(','), fields: 'first_name,last_name' }) | ||
}) | ||
.then(response => { | ||
if (response.status !== 200) { return reject(response)} | ||
const doc = response.data | ||
@@ -75,4 +78,26 @@ resolve(doc) | ||
} | ||
}, | ||
wall: { | ||
/** | ||
* @param {String[]} walls | ||
*/ | ||
getById (walls, params = {}) { | ||
if (!Array.isArray(walls)) { | ||
walls = [walls] | ||
} | ||
return new Promise((resolve, reject) => { | ||
axios.get(`${origin}wall.getById`, { | ||
params: Object.assign(defaultParams, { posts: walls.join(',') }, params) | ||
}) | ||
.then(response => { | ||
if (response.status !== 200) { return reject(response)} | ||
const wall = response.data | ||
resolve(wall) | ||
}) | ||
.catch(reject) | ||
}) | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "vk-to-telegram", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Vk to telegram forwarder", | ||
@@ -5,0 +5,0 @@ "author": "ejnshtein", |
@@ -48,9 +48,9 @@ # vk to telegram forwarder | ||
| Photo(s) | `Yes` | | ||
| Video(s) | `Yes`, as links. | | ||
| Audio(s) | **NO.** Why? [Read here](https://vk.com/dev/audio). | | ||
| Video(s) | `Yes` | | ||
| Document(s) | `Yes` | | ||
| Link | `Yes`, but VK do [terrible things ...](https://i.imgur.com/vb0LDP4.png) with links titles written by cyrillic. | | ||
| Link | `Yes` | | ||
| Application Content | `Yes` | | ||
| Poll | **Not** yet, but forwarder will send link to poll. | | ||
| Album(s) | `Yes`, as photos in the caption have links to the album(s). | | ||
| Poll | **Not yet**, but forwarder will send link to poll. | | ||
| Audio(s) | **NO.** Why? [Read here](https://vk.com/dev/audio). | | ||
| Album(s) | `Yes` | | ||
| Graffiti | `Not tested.` | | ||
@@ -71,11 +71,4 @@ | Wiki Page | `Not tested.` | | ||
| `chatName`|`String` | **Yes** | Telegram channel or group link, like '[@tavernofheroes](https://t.me/tavernofoverwatchnews)'| | ||
|`chatId`|`Number`|`Optional`|If you know your chat/channel id, put it here, it will replace chatName parameter| | ||
| `ownerId`|`Number`|**Yes** | Your telegram id for sending error if they are. U can get know it from [@getidsbot](https://t.me/getidsbot)| | ||
| `vkConfirmation`|`String`|**Yes**|Confirmation string from ur group callback api server: <img src="https://i.imgur.com/Gq1bly4.png" width="600">| | ||
|`fromId` |`Number`| Optional | VK group id with '-'in start or nothing, if you don't need check. | | ||
|`customVkButton`|`String`|`Optional`|Title for button which will be added to each post to open it in VK| | ||
|`customPollTitle`|`String`|`Optional`|Custom template string in the title of button with URL to poll("Open poll" -> "Open poll - ${poll.question}")| | ||
|`customLongPostText`|`String`|`Optional`|Custom template string that replace full post text, because it's too long for Telegram(max 4096 characters) ("Too long post... [Read full]" -> "Too long post... \<a href="https://vk.com/poll${poll.owner_id}_${poll.id}">Read full</a>" and parse as HTML)| | ||
|`signed`|`String`|`Optional`|Custom template string that add post signer in the end of Telegram message ("Post By" -> "\n\nPost by \<a href="https://vk.com/id${post.signer_id}">${signer.first_name} ${signer.last_name}</a>" and parse as HTML) | | ||
|`heroku`|`Boolean`|`Optional`|Add filter that stops forwarder if detect that post repeats(Because of app [sleeping](https://devcenter.heroku.com/articles/free-dyno-hours))| | ||
| `vkToken` |`String`| **Yes** | Follow the instructions below:| | ||
@@ -87,2 +80,9 @@ ||||1. Create Standalone application here: [https://vk.com/apps?act=manage](https://vk.com/apps?act=manage) | | ||
||||4. Click allow all that need's and it's all! Your token is in query url, do not copy all link, only token without other params. | | ||
|`chatId`|`Number`|**Optional**|If you know your chat/channel id, put it here, it will replace `chatName` parameter| | ||
|`fromId` |`Number`| **Optional** | VK group id with '-'in start or nothing, if you don't need check. | | ||
|`customVkButton`|`String`|**Optional**|Title for button which will be added to each post to open it in VK| | ||
|`customPollTitle`|`String`|**Optional**|Custom template string in the title of button with URL to poll("Open poll" -> "Open poll - ${poll.question}")| | ||
|`customLongPostText`|`String`|**Optional**|Custom template string that replace full post text, because it's too long for Telegram(max 4096 characters) ("Too long post... [Read full]" -> "Too long post... \<a href="https://vk.com/poll${poll.owner_id}_${poll.id}">Read full</a>" and parse as HTML)| | ||
|`signed`|`String`|**Optional**|Custom template string that add post signer in the end of Telegram message ("Post By" -> "\n\nPost by \<a href="https://vk.com/id${post.signer_id}">${signer.first_name} ${signer.last_name}</a>" and parse as HTML) | | ||
|`heroku`|`Boolean`|**Optional**|Add filter that stops forwarder if detect that post repeats(Because of app [sleeping](https://devcenter.heroku.com/articles/free-dyno-hours))| | ||
@@ -89,0 +89,0 @@ * DON'T forget to pick in your vk group api dashboard event type 'WALL POST - NEW'. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57793
1134