Simplify install with one-click scripts; honor HTTP(S)_PROXY for Telegram.

Add install.ps1/install.sh, shrink README to script-first flow, register bot commands, and route API calls through undici EnvHttpProxyAgent when a proxy is set (v0.2.2).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
owo
2026-08-14 17:46:01 +08:00
co-authored by Cursor
parent 8ef1622822
commit a83af2f33c
15 changed files with 1255 additions and 204 deletions
+26 -1
View File
@@ -1,3 +1,25 @@
import { EnvHttpProxyAgent, fetch as undiciFetch } from 'undici';
function resolveProxyUrl() {
return (process.env.HTTPS_PROXY
|| process.env.HTTP_PROXY
|| process.env.https_proxy
|| process.env.http_proxy
|| undefined);
}
/**
* Node's global `fetch` ignores HTTP(S)_PROXY unless `NODE_USE_ENV_PROXY=1`.
* Undici's EnvHttpProxyAgent honors the env vars (and NO_PROXY).
*/
function createDefaultFetch() {
if (!resolveProxyUrl())
return globalThis.fetch;
const agent = new EnvHttpProxyAgent();
const proxied = ((input, init) => undiciFetch(input, {
...init,
dispatcher: agent,
}));
return proxied;
}
export class TelegramClient {
token;
fetchImpl;
@@ -8,7 +30,7 @@ export class TelegramClient {
throw new Error('bot token is required');
}
this.token = token;
this.fetchImpl = options.fetch ?? fetch;
this.fetchImpl = options.fetch ?? createDefaultFetch();
this.baseUrl = options.baseUrl ?? 'https://api.telegram.org';
this.pollingTimeoutSec = options.pollingTimeoutSec ?? 30;
}
@@ -69,4 +91,7 @@ export class TelegramClient {
body.text = text;
return this.call('answerCallbackQuery', body);
}
async setMyCommands(commands) {
return this.call('setMyCommands', { commands });
}
}