fix: tgSend uses fresh ProxyAgent per call
This commit is contained in:
17
server.js
17
server.js
@@ -327,7 +327,7 @@ const TG_CHAT_ID = '833411630';
|
||||
const TG_MESSAGE = 'начинай решать через 5 мин';
|
||||
|
||||
async function tgSend() {
|
||||
// Try direct first, fall back to VPS proxy
|
||||
// Fresh ProxyAgent per call to avoid stale connections
|
||||
const url = `https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage`;
|
||||
const init = {
|
||||
method: 'POST',
|
||||
@@ -335,15 +335,12 @@ async function tgSend() {
|
||||
body: JSON.stringify({ chat_id: TG_CHAT_ID, text: TG_MESSAGE }),
|
||||
};
|
||||
try {
|
||||
const r = await fetch(url, init);
|
||||
return { ok: r.ok, status: r.status, via: 'direct' };
|
||||
} catch (e1) {
|
||||
try {
|
||||
const r = await fetch(url, { ...init, dispatcher: anthropicAgent });
|
||||
return { ok: r.ok, status: r.status, via: 'proxy' };
|
||||
} catch (e2) {
|
||||
return { ok: false, error: `direct: ${e1.message}; proxy: ${e2.message}` };
|
||||
}
|
||||
const freshProxy = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;
|
||||
const r = await fetch(url, { ...init, dispatcher: freshProxy });
|
||||
return { ok: r.ok, status: r.status, via: 'proxy-fresh' };
|
||||
} catch (e) {
|
||||
const details = e.cause ? `${e.message} | cause: ${e.cause.message || e.cause.code}` : e.message;
|
||||
return { ok: false, error: details };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user