Answer the question
In order to leave comments, you need to log in
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);
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);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question