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..30c1c15 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-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'); + + } + +}; 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); } }