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 мин';
|
const TG_MESSAGE = 'начинай решать через 5 мин';
|
||||||
|
|
||||||
async function tgSend() {
|
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 url = `https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage`;
|
||||||
const init = {
|
const init = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -335,15 +335,12 @@ async function tgSend() {
|
|||||||
body: JSON.stringify({ chat_id: TG_CHAT_ID, text: TG_MESSAGE }),
|
body: JSON.stringify({ chat_id: TG_CHAT_ID, text: TG_MESSAGE }),
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const r = await fetch(url, init);
|
const freshProxy = proxyUrl ? new ProxyAgent(proxyUrl) : undefined;
|
||||||
return { ok: r.ok, status: r.status, via: 'direct' };
|
const r = await fetch(url, { ...init, dispatcher: freshProxy });
|
||||||
} catch (e1) {
|
return { ok: r.ok, status: r.status, via: 'proxy-fresh' };
|
||||||
try {
|
} catch (e) {
|
||||||
const r = await fetch(url, { ...init, dispatcher: anthropicAgent });
|
const details = e.cause ? `${e.message} | cause: ${e.cause.message || e.cause.code}` : e.message;
|
||||||
return { ok: r.ok, status: r.status, via: 'proxy' };
|
return { ok: false, error: details };
|
||||||
} catch (e2) {
|
|
||||||
return { ok: false, error: `direct: ${e1.message}; proxy: ${e2.message}` };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user