I wanted to make a Telegram bot and I wrote this simple code for it:
const TelegramBot = require("node-telegram-bot-api");
const token = "*******";
const bot = new TelegramBot(token, { polling: true });
bot.onText(//start/, (msg) => {
const message = "this is text message";
const chatid = msg.chat.id;
bot.sendMessage(chatid, message);
});
But when I try to run using node bot.js, it gives me this error:
error: [polling_error] {“code”:”EFATAL”,”message”:”EFATAL: Error: connect ETIMEDOUT 10.10.34.36:443″}
Can anyone help me what to do?😑
I disabled the firewall and proxy and checked the internet, there was no problem.
I saw that there’s an active bug in the library causing this.
But, apparently, you can force to use IPv4 in the request.agentOptions
in the TelegramBot
constructor.
Here’s how to do that:
const TelegramBot = require("node-telegram-bot-api")
const token = "My-Awesome-Bot-Token";
const bot = new TelegramBot(token, {
request: {
agentOptions: {
keepAlive: true,
family: 4
}
}
});
Here’s an active discussion on this bug.
Hope this helps.
2