Setup and test your serverless Telegram alert forwarder utilizing Cloudflare Workers.

Configuration & Testing

Live Alert Logs

[Info] Live Panel Initialized. Enter credentials to send tests.

Cloudflare Worker Code

cloudflare-worker.js
addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  if (request.method !== 'POST') {
    return new Response('Send POST requests.', { status: 400 })
  }
  try {
    const data = await request.json()
    const message = `🚨 *Uptime Alert* 🚨\n\n*Service:* ${data.service}\n*Status:* ${data.status}\n*Msg:* ${data.message}`
    
    // Configured via Cloudflare Environment Variables
    const url = `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`
    await fetch(url, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        chat_id: CHAT_ID,
        text: message,
        parse_mode: 'Markdown'
      })
    })
    return new Response('Sent to Telegram.', { status: 200 })
  } catch (err) {
    return new Response('Error: ' + err.message, { status: 500 })
  }
}

Step 1: Log in to your Cloudflare Dashboard.

Step 2: Go to Workers & Pages and click Create Application.

Step 3: Click Create Worker, name it, and click Deploy.

Step 4: Click Edit Code, paste the copied worker script, and click Save and Deploy.

Step 5: Go to the worker's Settings > Variables, and add two Environment Variables:
BOT_TOKEN (Your Telegram Bot Token)
CHAT_ID (Your Telegram Chat ID)

Return to ZipLoot Tools Hub