long
worKaround stuff
There are many reasons why you wanna do this. The most obvious one is: you can't access the API directly. Your host might be blocking it, Telegram could be banned in your region, or even you just don't want your servers to do the heavy lifting. By using a Telegram Bot and Cloudflare worker you can make your life easier. BTW, it's free.
So I'm going to send someone a simple message using a simple script.
async function handleRequest(request) {
const url = new URL(request.url);
// Extract the 'text' parameter from the query string
const text = url.searchParams.get('text');
if (!text) {
return new Response('Bad Request: "text" parameter is required', { status: 400 });
}
// Construct the Telegram API URL
const telegramUrl = `https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={CHAT_ID}&text=${encodeURIComponent(text)}`;
try {
const response = await fetch(telegramUrl);
return new Response(await response.text(), {
status: response.status,
headers: {
'content-type': 'application/json',
},
});
} catch (error) {
return new Response('Internal Server Error', {
status: 500,
headers: {
'content-type': 'text/plain',
},
});
}
}
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request));
});
What this script does is that it looks for a parameter called "text" in the url, and uses the Telegram API to send the message to the user.
Now get your Worker url and try it out; EX:
For the TOKEN and CHAT_ID you could also use an environment variable; Just search for it I'm sure you'll find it easily.
Github repo: github.com/unixnexo/telegram-api-bypass