Telegram Bot Cloudflare logo

Telegram Bot Cloudflare

Community
mrhlaingbwardev
telegram-bot-cloudflare

Deploy Telegram bots to Cloudflare Workers with proper secret configuration. Use ONLY when user asks to create/deploy/fix Telegram bot on Cloudflare Workers.

Overview

Publishermrhlaingbwardev
Repositoryagentic-hacking-skills
Skill nametelegram-bot-cloudflare
Stars
350
Forks
57
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by mrhlaingbwardev on GitHub. Read the source before you install it.

Installation

Install the Telegram Bot Cloudflare AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/mrhlaingbwardev/agentic-hacking-skills/tree/main/skills/telegram-bot-cloudflare
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mrhlaingbwardev/agentic-hacking-skills.git /tmp/agentic-hacking-skills
mkdir -p .claude/skills
cp -r /tmp/agentic-hacking-skills/skills/telegram-bot-cloudflare .claude/skills/telegram-bot-cloudflare
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Telegram Bot Cloudflare in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Telegram Bot Cloudflare on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Telegram Bot Cloudflare is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Telegram Bot on Cloudflare Workers

Deploy Telegram bots to Cloudflare Workers serverless platform.

Prerequisites

  • Telegram Bot Token from @BotFather
  • Cloudflare account with Workers enabled
  • Workers.dev subdomain configured

Step-by-Step Deployment

1. Get Bot Token

User gets token from @BotFather:

/newbot
Bot name: My Bot
Username: mybot_bot
Token: 123456789:ABCdefGHI...

2. Configure Workers.dev Subdomain

CRITICAL: Must configure subdomain BEFORE deploying worker.

javascript
// Check if subdomain exists
GET /accounts/{account_id}/workers/subdomain

// If 404, create subdomain
PUT /accounts/{account_id}/workers/subdomain
Body: {"subdomain": "your-subdomain"}

Example subdomain: yatal, mybots, etc.

3. Deploy Worker Script

Use vanilla JavaScript (no external imports - Cloudflare Workers doesn't support ESM imports from URLs).

javascript
export default {
  async fetch(request, env) {
    if (request.method === 'GET') {
      return new Response('Bot is running!')
    }

    const update = await request.json()
    const BOT_TOKEN = env.BOT_TOKEN
    
    async function sendMessage(chatId, text, options = {}) {
      const body = { chat_id: chatId, text, parse_mode: 'Markdown', ...options }
      await fetch(`https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(body)
      })
    }

    // Handle /start
    if (update.message?.text === '/start') {
      await sendMessage(update.message.chat.id, 'Hello!')
    }

    return new Response('OK', { status: 200 })
  }
}

Deploy via Cloudflare MCP:

javascript
cloudflare.request({
  method: 'PUT',
  path: `/accounts/${accountId}/workers/scripts/bot-name`,
  body: multipart_form_data_with_script,
  contentType: 'multipart/form-data; boundary=...',
  rawBody: true
})

Metadata must include:

json
{
  "main_module": "worker.js",
  "compatibility_date": "2024-01-01"
}

4. Set Environment Variables (CRITICAL!)

WRONG WAY (will encrypt values):

javascript
// This creates encrypted secrets that worker can't read!
cloudflare.request({
  method: 'PUT',
  path: `/accounts/${accountId}/workers/scripts/bot-name/secrets`,
  body: { name: 'BOT_TOKEN', text: 'xxx', type: 'secret_text' }
})

CORRECT WAY:

javascript
// Method 1: Use secrets endpoint correctly
cloudflare.request({
  method: 'PUT',
  path: `/accounts/${accountId}/workers/scripts/bot-name/secrets`,
  body: { name: 'BOT_TOKEN', text: 'token-value', type: 'secret_text' }
})

// If this creates "Value encrypted" issue, DELETE and re-add:
// DELETE /accounts/{account_id}/workers/scripts/{script}/secrets/{secret_name}
// Then PUT again

Verification: Check in dashboard that variables show actual values (or "Secret" for secret_text type), NOT "Value encrypted".

5. Set Webhook

Worker URL format: https://{script-name}.{subdomain}.workers.dev

Example: https://my-bot.yatal.workers.dev

bash
curl "https://api.telegram.org/bot{TOKEN}/setWebhook?url=https://my-bot.yatal.workers.dev"

6. Test & Debug

Check webhook status:

bash
curl "https://api.telegram.org/bot{TOKEN}/getWebhookInfo"

Common errors:

ErrorCauseFix
404 Not FoundSubdomain not configuredCreate subdomain first
SSL handshake failureNew subdomain (cert pending)Wait 5 min or use custom domain
Value encryptedWrong secret API usageDelete secret, re-add correctly
Bot not respondingenv.BOT_TOKEN undefinedCheck secrets in dashboard

Test worker directly:

bash
# Should return "Bot is running!"
curl https://my-bot.yatal.workers.dev

Check if bot received updates:

bash
curl "https://api.telegram.org/bot{TOKEN}/getUpdates"

Common Patterns

Inline Keyboard Buttons

javascript
const keyboard = {
  inline_keyboard: [
    [
      { text: 'Button 1', callback_data: 'btn1' },
      { text: 'Button 2', callback_data: 'btn2' }
    ]
  ]
}

await sendMessage(chatId, 'Choose:', { reply_markup: keyboard })

Handle Button Callbacks

javascript
if (update.callback_query) {
  const data = update.callback_query.data
  const chatId = update.callback_query.message.chat.id
  
  // Answer callback (removes loading state)
  await fetch(`https://api.telegram.org/bot${BOT_TOKEN}/answerCallbackQuery`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ callback_query_id: update.callback_query.id })
  })
  
  // Send response
  await sendMessage(chatId, `You clicked: ${data}`)
}

Forward to Admin

javascript
bot.on('message:text', async (ctx) => {
  if (ctx.message.text.length > 30) {
    await sendMessage(
      env.ADMIN_CHAT_ID,
      `New message from ${ctx.from.first_name}:\n${ctx.message.text}`
    )
  }
})

Full Deployment Checklist

  • Get bot token from @BotFather
  • Check/create workers.dev subdomain
  • Deploy worker script with correct metadata
  • Set BOT_TOKEN secret (verify not "Value encrypted")
  • Set ADMIN_CHAT_ID if needed
  • Set webhook URL
  • Test: Send /start to bot
  • Check webhook info for errors
  • If SSL error: wait or use custom domain

Troubleshooting Commands

javascript
// List all workers
cloudflare.request({ method: 'GET', path: `/accounts/${accountId}/workers/scripts` })

// Get worker details
cloudflare.request({ method: 'GET', path: `/accounts/${accountId}/workers/scripts/bot-name` })

// Check subdomain
cloudflare.request({ method: 'GET', path: `/accounts/${accountId}/workers/subdomain` })

// Delete worker (start over)
cloudflare.request({ method: 'DELETE', path: `/accounts/${accountId}/workers/scripts/bot-name` })

Security Notes

  • Never commit bot tokens to git
  • Use secret_text type for sensitive values
  • Validate admin_chat_id before forwarding
  • Add rate limiting for production bots

Alternative: Custom Domain (Recommended for Production)

If SSL issues persist with workers.dev:

  1. Add domain to Cloudflare
  2. Create DNS record: bot.example.com → Worker route
  3. Use https://bot.example.com as webhook URL
  4. SSL works immediately (no waiting)

Remember: The most common mistake is incorrect secret configuration. Always verify in dashboard that secrets are accessible to the worker, not showing "Value encrypted" error.

Frequently asked questions

What does the Telegram Bot Cloudflare AI skill do?

Deploy Telegram bots to Cloudflare Workers with proper secret configuration. Use ONLY when user asks to create/deploy/fix Telegram bot on Cloudflare Workers.

Why use Telegram Bot Cloudflare on TypingMind?

Because you install it once and use it with any model. Telegram Bot Cloudflare is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Telegram Bot Cloudflare in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/mrhlaingbwardev/agentic-hacking-skills/tree/main/skills/telegram-bot-cloudflare. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Telegram Bot Cloudflare?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Telegram Bot Cloudflare?

As many as you like. As long as a model supports skills, you can use Telegram Bot Cloudflare with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Telegram Bot Cloudflare AI skill free?

It is published on GitHub by mrhlaingbwardev. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇