node-telegram-bot-api icon indicating copy to clipboard operation
node-telegram-bot-api copied to clipboard

Polling Error: EFATAL

Open TheRebo opened this issue 1 year ago • 29 comments

Please help me!, error below happen when running the bot for the first time! :

RequestError: AggregateError at new RequestError (/home/kali/Bot-Telegram-Password-Manager/node_modules/request-promise-core/lib/errors.js:14:15) at plumbing.callback (/home/kali/Bot-Telegram-Password-Manager/node_modules/request-promise-core/lib/plumbing.js:87:29) at Request.RP$callback [as _callback] (/home/kali/Bot-Telegram-Password-Manager/node_modules/request-promise-core/lib/plumbing.js:46:31) at self.callback (/home/kali/Bot-Telegram-Password-Manager/node_modules/request/request.js:185:22) at Request.emit (node:events:514:28) at Request.onRequestError (/home/kali/Bot-Telegram-Password-Manager/node_modules/request/request.js:877:8) at ClientRequest.emit (node:events:514:28) at TLSSocket.socketErrorListener (node:_http_client:495:9) at TLSSocket.emit (node:events:514:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { code: 'EFATAL' }

TheRebo avatar Oct 07 '23 08:10 TheRebo

This can be caused by connection Problem try this repo hope it helps https://github.com/yagop/node-telegram-bot-api/issues/766

Redskullvue avatar Oct 07 '23 10:10 Redskullvue

Hi, I have this error, how can I handle this? It crash my app

ngohuunam avatar Oct 09 '23 04:10 ngohuunam

I have same error. The error happens with nodejs v20 and ubuntu 22.04. With nodejs v20 and mac, there is no error. :(

jinsankim avatar Nov 01 '23 16:11 jinsankim

@TheRebo Please could you share the environment?

jinsankim avatar Nov 01 '23 23:11 jinsankim

I have same error. The error happens with nodejs v20 and ubuntu 20.04.

blacktem12 avatar Nov 08 '23 08:11 blacktem12

Same here. NodeJS v20 + Ubuntu 22.04.

cryptomatictrader999 avatar Dec 27 '23 07:12 cryptomatictrader999

Any update on this?

richardscull avatar Dec 31 '23 19:12 richardscull

I am facing this same error in Ubuntu but I can run this code in replit and also works on Mac. Has anyone found the solution?

Pragnesh8122001 avatar Jan 02 '24 12:01 Pragnesh8122001

I'm also facing this error how to solve this please help me

lalitkumawat1m avatar Jan 05 '24 15:01 lalitkumawat1m

I'm also facing this error how to solve this please help me

Are you facing this error in Linux?

Pragnesh8122001 avatar Jan 11 '24 05:01 Pragnesh8122001

I'm also facing this error how to solve this please help me

Are you facing this error in Linux?

No I'm getting this error in windows 11

lalitkumawat1m avatar Jan 14 '24 03:01 lalitkumawat1m

same problem here

Piero87 avatar Jan 17 '24 23:01 Piero87

same problem here on VPS ubuntu 22.04 - nodejs, all of my services were down because that error without any reason

linhdareal15 avatar Jan 22 '24 04:01 linhdareal15

I'm also facing this error how to solve this please help me

Are you facing this error in Linux?

No I'm getting this error in windows 11

I used VPN and it started working.

Pragnesh8122001 avatar Jan 23 '24 04:01 Pragnesh8122001

I'm also facing this error how to solve this please help me

Are you facing this error in Linux?

No I'm getting this error in windows 11

I used VPN and it started working.

could you tell me detail?

hyeongirlife avatar Feb 01 '24 05:02 hyeongirlife

i was facing the same error but with nestgram, i managed to fix it by downgrading from nodejs v20 to v18, and started using proton VPN

felipegbot avatar Feb 10 '24 17:02 felipegbot

Same with Ubuntu 20.04 + Node 20.

thetrung avatar Feb 20 '24 01:02 thetrung

Same with Ubuntu 22.04 + Node v20.11.1

The application starts and works fine for a while. But at some point this error occurs and everything crashes.

BUT Ubuntu 20.04.6 + v18.7.0 Everything works great

andreyLed avatar Feb 23 '24 06:02 andreyLed

I think I solved it, apparently you need to force IPv4 via agentOptions on the request API, like so:

const botToken = "123123123:testAAAAA";
const telegramAPI = require("node-telegram-bot-api");
const bot = new telegramAPI(config.botToken, { polling: true, request: {
    agentOptions: {
        keepAlive: true,
        family: 4
    }
}});
bot.on("message", async function(msg) {
    await bot.sendMessage(msg.chat.id, "test");
});

And then it works fine. There has to be something really really wrong on how SSL requests are made on these libraries or the underlying http(s) infrastructure of node, since the bot indeed does request to an IPv4 address to Telegram despite this setting not being present but the server instantly replies with an RST. Basically, if your ISP just doesn't support IPv6 yet (and you don't have an IPv6 public address), you'll be getting this unless you force IPv4 explicitly somehow. It's also happening on telegraf but haven't managed to force IPv4 explicitly yet since it doesn't seem to expose a way to modify the http(s) agent.

Some related issues: yagop/node-telegram-bot-api#1156 telegraf/telegraf#1961 telegraf/telegraf#1917

PANCHO7532 avatar Apr 03 '24 01:04 PANCHO7532

same with windows 10 can anyone help?

Ali-Script avatar Apr 11 '24 17:04 Ali-Script

I think I solved it, apparently you need to force IPv4 via agentOptions on the request API, like so:

const botToken = "123123123:testAAAAA";
const telegramAPI = require("node-telegram-bot-api");
const bot = new telegramAPI(config.botToken, { polling: true, request: {
    agentOptions: {
        keepAlive: true,
        family: 4
    }
}});
bot.on("message", async function(msg) {
    await bot.sendMessage(msg.chat.id, "test");
});

And then it works fine. There has to be something really really wrong on how SSL requests are made on these libraries or the underlying http(s) infrastructure of node, since the bot indeed does request to an IPv4 address to Telegram despite this setting not being present but the server instantly replies with an RST. Basically, if your ISP just doesn't support IPv6 yet (and you don't have an IPv6 public address), you'll be getting this unless you force IPv4 explicitly somehow. It's also happening on telegraf but haven't managed to force IPv4 explicitly yet since it doesn't seem to expose a way to modify the http(s) agent.

Some related issues: #1156 telegraf/telegraf#1961 telegraf/telegraf#1917

Thank you very much!

TheRebo avatar Apr 13 '24 19:04 TheRebo

I think I solved it, apparently you need to force IPv4 via agentOptions on the request API, like so:

const botToken = "123123123:testAAAAA";
const telegramAPI = require("node-telegram-bot-api");
const bot = new telegramAPI(config.botToken, { polling: true, request: {
    agentOptions: {
        keepAlive: true,
        family: 4
    }
}});
bot.on("message", async function(msg) {
    await bot.sendMessage(msg.chat.id, "test");
});

And then it works fine. There has to be something really really wrong on how SSL requests are made on these libraries or the underlying http(s) infrastructure of node, since the bot indeed does request to an IPv4 address to Telegram despite this setting not being present but the server instantly replies with an RST. Basically, if your ISP just doesn't support IPv6 yet (and you don't have an IPv6 public address), you'll be getting this unless you force IPv4 explicitly somehow. It's also happening on telegraf but haven't managed to force IPv4 explicitly yet since it doesn't seem to expose a way to modify the http(s) agent.

Some related issues: #1156 telegraf/telegraf#1961 telegraf/telegraf#1917

It works! Thank you

uziins avatar Apr 25 '24 15:04 uziins

I think I solved it, apparently you need to force IPv4 via agentOptions on the request API, like so:

const botToken = "123123123:testAAAAA";
const telegramAPI = require("node-telegram-bot-api");
const bot = new telegramAPI(config.botToken, { polling: true, request: {
    agentOptions: {
        keepAlive: true,
        family: 4
    }
}});
bot.on("message", async function(msg) {
    await bot.sendMessage(msg.chat.id, "test");
});

And then it works fine. There has to be something really really wrong on how SSL requests are made on these libraries or the underlying http(s) infrastructure of node, since the bot indeed does request to an IPv4 address to Telegram despite this setting not being present but the server instantly replies with an RST. Basically, if your ISP just doesn't support IPv6 yet (and you don't have an IPv6 public address), you'll be getting this unless you force IPv4 explicitly somehow. It's also happening on telegraf but haven't managed to force IPv4 explicitly yet since it doesn't seem to expose a way to modify the http(s) agent.

Some related issues: #1156 telegraf/telegraf#1961 telegraf/telegraf#1917

it works, thank you very much

lwhuang avatar Apr 28 '24 13:04 lwhuang

Hey guys, a little update for request type, is missing the URL parameter:

request: { agentOptions: { keepAlive: true, family: 4 }, url: "https://api.telegram.org", }

frantrick avatar Apr 30 '24 12:04 frantrick

Hey guys, a little update for request type, is missing the URL parameter:

request: { agentOptions: { keepAlive: true, family: 4 }, url: "https://api.telegram.org", }

I think this is unnecessary since node-telegram-bot-api already fills that parameter with the correct URL, unless you're doing something really customized for your use-case you shouldn't do that.

PANCHO7532 avatar May 01 '24 18:05 PANCHO7532

I am facing the same error with nodejs v20 and ubuntu 22.04 on virtual machine (VM). but there is no error on my local computer with nodejs v20 and macos. I downgraded the nodejs version to v14 on VM and it worked fine.

nafifurqon avatar May 05 '24 11:05 nafifurqon

I think I solved it, apparently you need to force IPv4 via agentOptions on the request API, like so:

const botToken = "123123123:testAAAAA";
const telegramAPI = require("node-telegram-bot-api");
const bot = new telegramAPI(config.botToken, { polling: true, request: {
    agentOptions: {
        keepAlive: true,
        family: 4
    }
}});
bot.on("message", async function(msg) {
    await bot.sendMessage(msg.chat.id, "test");
});

And then it works fine. There has to be something really really wrong on how SSL requests are made on these libraries or the underlying http(s) infrastructure of node, since the bot indeed does request to an IPv4 address to Telegram despite this setting not being present but the server instantly replies with an RST. Basically, if your ISP just doesn't support IPv6 yet (and you don't have an IPv6 public address), you'll be getting this unless you force IPv4 explicitly somehow. It's also happening on telegraf but haven't managed to force IPv4 explicitly yet since it doesn't seem to expose a way to modify the http(s) agent.

Some related issues: #1156 telegraf/telegraf#1961 telegraf/telegraf#1917

Thanks, It works for me.

Ligengxin96 avatar Jun 21 '24 07:06 Ligengxin96