A
A
Albert Ushakov2020-01-14 01:09:20
JavaScript
Albert Ushakov, 2020-01-14 01:09:20

How to set up a proxy for a telegram bot?

The entire Internet went through, there are options, but I just don’t understand how to saddle.
There is a common example of a bot, there is a proxy server IP, PORT, LOG and PASS. How to get through it on node js?
There is a working example in php. Code below:

$ch = curl_init();
    curl_setopt_array(
        $ch,
        array( 
            CURLOPT_URL => "https://api.telegram.org/bot" . TELEGRAM_TOKEN . "/sendMessage",
            CURLOPT_POST => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 10,
            CURLOPT_POSTFIELDS => array(
                "chat_id" => TELEGRAM_CHATID,
                "text" => ТУТ ТЕКСТ,
            ),
            CURLOPT_PROXY => "ИП:ПОРТ", 
            CURLOPT_PROXYUSERPWD => "tЛОГИН:ПАРОЛЬ",
            CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5,
            CURLOPT_PROXYAUTH => CURLAUTH_BASIC,
        )
    );
    curl_exec($ch);

The text is sent.
How to implement this in Node in JS?
Here is a sample code I took:
var TelegramBot = require('node-telegram-bot-api');
var token = 'ТУТ ТОКЕН';
var bot = new TelegramBot(token, {
 polling: true,
 request: {
  proxy: "Вот тут я не знаю как обращаться к телеге через прокси в примере выше"
 }
});
var notes = [];

bot.onText(/напомни (.+) в (.+)/, function (msg, match) {
    var userId = msg.from.id;
    var text = match[1];
    var time = match[2];

    notes.push({ 'uid': userId, 'time': time, 'text': text });

    bot.sendMessage(userId, 'Отлично!');
});

setInterval(function(){
    for (var i = 0; i < notes.length; i++) {
    const curDate = new Date().getHours() + ':' + new Date().getMinutes();
    if (notes[i]['time'] === curDate) {
      bot.sendMessage(notes[i]['uid'], 'Напоминаю, что вы должны: '+ notes[i]['text'] + ' сейчас.');
      notes.splice(i, 1);
    }
  }
}, 1000);

Please help, or do you have any examples?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zlo1, 2020-01-17
@fuck_ask

http proxy with connect support

F
FlatUser, 2020-01-14
@FlatUser

request: {
proxy: " http://[user]:[pw]@127.0.0.1:1234 ",
},

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question