From 6b3dc4632125b8a30f6e118466474ee7e442a457 Mon Sep 17 00:00:00 2001 From: xTCry Date: Wed, 7 Nov 2018 01:15:33 +0300 Subject: [PATCH 1/3] Add Tor proxy agent Install: apt-get install tor tor-geoipdb privoxy Config - Default Host:Port - /etc/privoxy/config : forward-socks5 / 127.0.0.1:9050 . --- lib/telebot.js | 12 ++++++++++++ package.json | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/telebot.js b/lib/telebot.js index 451cf5f..20796eb 100644 --- a/lib/telebot.js +++ b/lib/telebot.js @@ -1,4 +1,6 @@ const request = require('request'); +const socks5Agent = require('socks5-https-client/lib/Agent'); + const webhook = require('./webhook.js'); const standardUpdates = require('./updates.js'); const standardMethods = require('./methods.js'); @@ -34,6 +36,7 @@ class TeleBot { const poll = cfg.polling || {}; + this.tor = poll.tor; this.proxy = poll.proxy; this.limit = poll.limit > 0 && poll.limit <= 100 ? poll.limit : 100; this.interval = poll.interval >= 0 ? poll.interval : 300; @@ -303,6 +306,15 @@ class TeleBot { json: true }; + if(this.tor) { + options.agentClass = socks5Agent; + options.strictSSL = true; + options.agentOptions = { + // socksHost: 'localhost', // Defaults to 'localhost'. + socksPort: 9050 // Defaults to 1080. + }; + } + if (this.proxy) options.proxy = this.proxy; if (form) { diff --git a/package.json b/package.json index ccae830..3a7d3e5 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "node": ">= 6.0.0" }, "dependencies": { - "request": "^2.81.0" + "request": "^2.81.0", + "socks5-http-client": "^1.0.3", + "socks5-https-client": "^1.2.1", }, "devDependencies": { "ava": "^0.19.1", From 8319db917608ea739a89027775ed18b01a15b4f9 Mon Sep 17 00:00:00 2001 From: xTCry Date: Wed, 7 Nov 2018 01:17:44 +0300 Subject: [PATCH 2/3] Deprecate botanio & Add dashbot --- package.json | 2 +- plugins/botan.js | 30 ---------------------------- plugins/dashbot.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 31 deletions(-) delete mode 100644 plugins/botan.js create mode 100644 plugins/dashbot.js diff --git a/package.json b/package.json index 3a7d3e5..30c1c15 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ }, "dependencies": { "request": "^2.81.0", - "socks5-http-client": "^1.0.3", "socks5-https-client": "^1.2.1", + "dashbot": "^10.2.1" }, "devDependencies": { "ava": "^0.19.1", diff --git a/plugins/botan.js b/plugins/botan.js deleted file mode 100644 index fdc2316..0000000 --- a/plugins/botan.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - Advanced analytics for your Telegram bot - http://botan.io - Requires "botanio" npm package. -*/ - -module.exports = { - - id: 'botan', - defaultConfig: null, - - plugin(bot, config) { - - // Check AppMetrika key - const token = config; - - if (token) { - - // Require botanio - const botan = require('botanio')(token); - - // Track every type of message - bot.on('*', (msg, props) => botan.track(msg, props.type)); - - } else { - console.error('[botan] no token key'); - } - - } - -}; diff --git a/plugins/dashbot.js b/plugins/dashbot.js new file mode 100644 index 0000000..a14070c --- /dev/null +++ b/plugins/dashbot.js @@ -0,0 +1,49 @@ +/* + Requires "dashbot" npm package. + + Advanced analytics bot - https://www.dashbot.io/docs + + Create a bot to get an API key - https://dashbot.io/bots + Platform -> Universal +*/ + +module.exports = { + + id: 'dashbot', + defaultConfig: null, + + plugin(bot, config) { + + // Create a bot to get an API key - https://dashbot.io/bots + const API_KEY = config; + + if (API_KEY) { + + const dashbot = require('dashbot')(API_KEY).universal; + + // Track every type of message + bot.on('text', (data) => { + const { from, text } = data, + uName = from.first_name + " "+from.last_name; + dashbot.logIncoming({ + "text": text, + "userId": "USER"+from.id, + "platformJson": JSON.stringify(data) + }); + }); + bot.on('*', (msg, props) => { + if(props.type == "text") return; + dashbot.logIncoming({ + "text": props.type, + "userId": "USER"+msg.from.id, + "platformJson": JSON.stringify(msg) + }); + }); + + } + else + console.error('[dashbot] API Key not specified'); + + } + +}; From 43aeb43e62b58fa7805f5e6aafe778d0fa887127 Mon Sep 17 00:00:00 2001 From: xTCry Date: Wed, 7 Nov 2018 01:19:24 +0300 Subject: [PATCH 3/3] Added Callback function in plugin Button --- plugins/namedButtons.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/namedButtons.js b/plugins/namedButtons.js index ff992ba..7b288ce 100644 --- a/plugins/namedButtons.js +++ b/plugins/namedButtons.js @@ -9,7 +9,8 @@ module.exports = { buttons: { // myButton: { // label: '😄 My Button Name', - // command: '/myBotCommand' + // command: '/myBotCommand', + // cb: _=> { console.log("Event My Button"); } // } } }, @@ -23,6 +24,8 @@ module.exports = { for (let buttonId in buttons) { const button = buttons[buttonId]; if (button.label === text) { + if(typeof button.cb === "function") + button.cb(msg); return bot.event(button.command, msg, props); } }