Skip to content

Instantly share code, notes, and snippets.

@moesoha
moesoha / worker.js
Last active September 10, 2024 20:16
Auto kick any joining users from Telegram group (deployed on Cloudflare Worker)
addEventListener('fetch', event => event.respondWith(handleRequest(event.request)));
// Add environment variable `TGBOT_TOKEN` via Worker-Settings
async function requestTelegramBotAPI(method, payload) {
return fetch(`https://api.telegram.org/bot${TGBOT_TOKEN}/${method}`, {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8"
},
body: !payload ? undefined : JSON.stringify(payload)