Personal Telegram developer console for GitHub
fix: invoke Cloudflare fetch without client receiver
* test: reproduce Cloudflare fetch receiver failure * fix: invoke Cloudflare fetch without client receiver
davoodmehraban89 committed
Oct 3, 2026 at 00:38 UTC
bd01d8ede44331f50e1115d569095fb12246331d
2 files changed
+25
-1
src/telegram.js
+1
-1
@@ -2,7 +2,7 @@ export class TelegramClient {
2
constructor(botToken, options = {}) {
3
this.botToken = botToken;
4
this.baseUrl = options.baseUrl || `https://api.telegram.org/bot${botToken}`;
5
- this.fetchFn = options.fetch || fetch;
5
+ this.fetchFn = options.fetch || ((...args) => fetch(...args));
6
}
7
8
async callApi(method, payload) {
test/telegram.test.js
+24
@@ -38,3 +38,27 @@ test('TelegramClient rejects Telegram ok:false responses even with HTTP 200', as
38
/message is not modified/i
39
);
40
});
41
+
42
+test('TelegramClient invokes the default fetch without a TelegramClient receiver', async () => {
43
+ const originalFetch = globalThis.fetch;
44
+ let observedThis;
45
+
46
+ globalThis.fetch = async function () {
47
+ observedThis = this;
48
+ if (this instanceof TelegramClient) {
49
+ throw new TypeError('Illegal invocation: function called with incorrect this reference');
50
+ }
51
+ return new Response(JSON.stringify({ ok: true, result: { message_id: 1 } }), {
52
+ status: 200,
53
+ headers: { 'content-type': 'application/json' }
54
+ });
55
+ };
56
+
57
+ try {
58
+ const client = new TelegramClient('token');
59
+ await client.sendMessage(1, 'hello');
60
+ assert.notEqual(observedThis, client);
61
+ } finally {
62
+ globalThis.fetch = originalFetch;
63
+ }
64
+});