Home
cd ../playbooks
Developer ToolsAdvanced

Telegram Bot Builder

Telegram bot development - chatbots, notifications, AI assistants, and group automation

10 minutes
By communitySource
#telegram#bot#chatbot#automation#notifications

You want a Telegram bot for your community or business but setting up the Bot API, handling commands, and managing state from scratch is tedious. This playbook builds Telegram bots — chatbots, notification systems, AI assistants, and group automation — with clean architecture and deployment.

Who it's for: developers building Telegram notification bots for monitoring and alerting systems, community managers creating automated moderation and engagement bots for Telegram groups, startup founders adding Telegram-based customer interaction to their products, DevOps engineers building deployment notification and status bots, educators creating interactive Telegram bots for course delivery and quizzes

Example

"Build a Telegram bot that sends daily stock alerts and answers portfolio questions" → Telegram bot pipeline: Bot API setup with BotFather token configuration, command handler architecture for /portfolio /alert /help commands, scheduled job system for daily market data alerts, conversational AI integration for natural language portfolio queries, and deployment configuration with webhook or polling mode

CLAUDE.md Template

New here? 3-minute setup guide → | Already set up? Copy the template below.

# Telegram Bot

Build Telegram bots for chatbots, notifications, AI assistants, and group automation. Based on n8n's Telegram workflow templates.

## Overview

This workflow covers:
- Bot setup and configuration
- Message handling patterns
- AI-powered assistants
- Notification workflows
- Group automation

---

## Bot Setup

### Creating a Bot

```yaml
setup_steps:
  1. create_bot:
      - open: @BotFather on Telegram
      - command: /newbot
      - provide: bot_name
      - provide: bot_username (must end in 'bot')
      - receive: API_token
      
  2. configure_bot:
      - command: /setdescription
      - command: /setabouttext
      - command: /setuserpic
      - command: /setcommands
      
  3. get_chat_id:
      - start: conversation with bot
      - call: https://api.telegram.org/bot{TOKEN}/getUpdates
      - extract: chat.id from response
```

### Bot Commands

```yaml
commands:
  - command: /start
    description: "Start the bot"
    
  - command: /help
    description: "Show available commands"
    
  - command: /status
    description: "Check system status"
    
  - command: /subscribe
    description: "Subscribe to notifications"
    
  - command: /unsubscribe
    description: "Unsubscribe from notifications"
```

---

## Message Handlers

### Basic Message Handler

```yaml
workflow: "Telegram Message Handler"
trigger: telegram_message

handlers:
  text_message:
    action: |
      1. Parse message text
      2. Determine intent
      3. Process request
      4. Send response
      
  command:
    pattern: "^/"
    action: route_to_command_handler
    
  photo:
    action: |
      1. Download photo
      2. Process with vision AI
      3. Respond with analysis
      
  document:
    action: |
      1. Download document
      2. Extract content
      3. Process and respond
      
  voice:
    action: |
      1. Download audio
      2. Transcribe with Whisper
      3. Process text
      4. Respond (text or voice)
      
  location:
    action: |
      1. Extract coordinates
      2. Lookup local info
      3. Respond with relevant data
```

### n8n Workflow

```yaml
workflow: "Telegram Bot n8n"

nodes:
  - name: "Telegram Trigger"
    type: "n8n-nodes-base.telegramTrigger"
    parameters:
      updates: ["message", "callback_query"]
      
  - name: "Route Message Type"
    type: "n8n-nodes-base.switch"
    parameters:
      rules:
        - output: 0
          condition: "{{ $json.message.text.startsWith('/') }}"
        - output: 1
          condition: "{{ $json.message.photo }}"
        - output: 2
          condition: "{{ $json.message.voice }}"
        - output: 3
          fallback: true
          
  - name: "Process with AI"
    type: "n8n-nodes-base.openAi"
    parameters:
      model: "gpt-4"
      messages:
        - role: "system"
          content: "You are a helpful Telegram assistant."
        - role: "user"
          content: "{{ $json.message.text }}"
          
  - name: "Send Response"
    type: "n8n-nodes-base.telegram"
    parameters:
      chatId: "{{ $json.message.chat.id }}"
      text: "{{ $json.response }}"
```

---

## AI-Powered Bot

### GPT-4 Integration

```yaml
ai_bot:
  name: "AI Assistant Bot"
  
  system_prompt: |
    You are a helpful AI assistant on Telegram.
    
    Guidelines:
    - Be concise (Telegram has message limits)
    - Use emojis appropriately
    - Format with markdown when helpful
    - Ask clarifying questions if needed
    
  features:
    - conversational_memory: true
    - context_window: last_10_messages
    - tools: [web_search, calculator, weather]
    
  message_formatting:
    max_length: 4096
    split_long_messages: true
    use_markdown: true
```

### Multi-Modal Bot

```yaml
multimodal_bot:
  handlers:
    text:
      model: gpt-4
      action: chat_completion
      
    image:
      model: gpt-4-vision
      action: analyze_and_respond
      
    voice:
      transcribe: whisper
      process: gpt-4
      respond: text_or_voice
      
    document:
      extract: based_on_type
      summarize: gpt-4
      respond: text
```

---

## Notification System

### Alert Bot

```yaml
workflow: "System Alert Bot"

triggers:
  - source: monitoring_system
    event: alert
  - source: ci_cd
    event: build_status
  - source: ecommerce
    event: new_order
    
notification_templates:
  alert:
    format: |
      🚨 *Alert: {severity}*
      
      *Service:* {service}
      *Message:* {message}
      *Time:* {timestamp}
      
      [View Dashboard]({dashboard_link})
      
  build:
    format: |
      {status_emoji} *Build {status}*
      
      *Project:* {project}
      *Branch:* {branch}
      *Commit:* `{commit_short}`
      
      {details}
      
  order:
    format: |
      šŸ›’ *New Order!*
      
      *Order:* #{order_id}
      *Customer:* {customer}
      *Total:* ${total}
      *Items:* {item_count}
      
routing:
  by_severity:
    critical: [admin_group, on_call_user]
    warning: [team_group]
    info: [logging_channel]
```

### Scheduled Notifications

```yaml
scheduled_notifications:
  daily_digest:
    schedule: "9am daily"
    template: |
      šŸ“Š *Daily Summary - {date}*
      
      šŸ“ˆ Sales: ${sales} ({change})
      šŸ‘„ New users: {new_users}
      šŸŽ« Open tickets: {tickets}
      
      Have a great day! ā˜€ļø
      
  weekly_report:
    schedule: "Monday 9am"
    template: weekly_metrics_report
    
  reminder:
    trigger: custom_event
    template: |
      ā° *Reminder*
      
      {reminder_text}
      
      Scheduled by: {creator}
```

---

## Group Automation

### Welcome Bot

```yaml
group_bot:
  on_member_join:
    action: |
      1. Check if new member
      2. Send welcome message
      3. Share rules
      4. Suggest introduction
      
    template: |
      šŸ‘‹ Welcome to {group_name}, {user_name}!
      
      Please:
      1. Read the /rules
      2. Introduce yourself
      3. Ask questions anytime!
      
      Enjoy your stay! šŸŽ‰
      
  on_member_leave:
    action: optional_goodbye
    
  moderation:
    - spam_detection: auto_delete + warn
    - link_filtering: whitelist_only
    - flood_control: rate_limit
```

### Poll & Survey Bot

```yaml
poll_bot:
  commands:
    /poll:
      format: "/poll Question | Option1 | Option2 | ..."
      action: create_poll
      
    /survey:
      action: start_multi_question_survey
      
    /results:
      action: show_aggregated_results
      
  features:
    - anonymous_voting: optional
    - multiple_choice: optional
    - scheduled_close: optional
    - export_results: to_sheets
```

---

## Inline Features

### Inline Keyboard

```yaml
inline_keyboard:
  example:
    text: "Choose an option:"
    keyboard:
      - row:
          - text: "Option 1"
            callback_data: "opt_1"
          - text: "Option 2"
            callback_data: "opt_2"
      - row:
          - text: "Cancel"
            callback_data: "cancel"
            
  callback_handler:
    opt_1:
      action: process_option_1
      response: "You selected Option 1"
      
    opt_2:
      action: process_option_2
      response: "You selected Option 2"
      
    cancel:
      action: cancel_operation
      response: "Operation cancelled"
```

### Inline Query

```yaml
inline_mode:
  trigger: "@botname query"
  
  results:
    - type: article
      title: "{query} result"
      description: "Click to send"
      message_text: "Result for: {query}"
      
    - type: photo
      photo_url: "{search_result_image}"
      
    - type: gif
      gif_url: "{gif_url}"
```

---

## Output Example

**Request**: "Create a Telegram notification bot for server alerts"

**Output**:

```markdown
# Server Alert Telegram Bot

## Setup

1. Create bot with @BotFather
2. Get token: `123456:ABC-DEF...`
3. Get chat ID for alerts channel

## n8n Workflow

```yaml
nodes:
  1. Webhook (receives alerts)
  2. Format Message
  3. Telegram Send
```

## Alert Templates

**Critical Alert:**
```
🚨 CRITICAL ALERT

Server: production-web-01
Status: DOWN
Time: 2026-01-30 14:32:05 UTC

Details:
- CPU: 98%
- Memory: 95%
- Disk: 89%

[View Grafana] [Acknowledge]
```

**Recovery:**
```
āœ… RECOVERED

Server: production-web-01
Downtime: 5 minutes
Status: All systems normal

Incident resolved automatically.
```

## Implementation

```javascript
// Send alert function
async function sendAlert(severity, message, details) {
  const emoji = {
    critical: '🚨',
    warning: 'āš ļø',
    info: 'ā„¹ļø',
    success: 'āœ…'
  };
  
  const text = `${emoji[severity]} *${severity.toUpperCase()}*\n\n${message}\n\n${details}`;
  
  await telegram.sendMessage({
    chat_id: ALERT_CHANNEL_ID,
    text: text,
    parse_mode: 'Markdown'
  });
}
```

## Features
- Severity-based routing
- Inline action buttons
- Acknowledgment tracking
- Escalation rules
```

---

*Telegram Bot Workflow - Part of Claude Code*
README.md

What This Does

Build Telegram bots for chatbots, notifications, AI assistants, and group automation. Based on n8n's Telegram workflow templates.


Quick Start

Step 1: Create a Project Folder

mkdir -p ~/Documents/TelegramBot

Step 2: Download the Template

Click Download above, then:

mv ~/Downloads/CLAUDE.md ~/Documents/TelegramBot/

Step 3: Start Working

cd ~/Documents/TelegramBot
claude

$Related Playbooks

Developer Tools

Test Specialist

Comprehensive JavaScript/TypeScript testing guidance with test writing, bug analysis, coverage analysis, and proactive issue detection.

10 minutes
Intermediate
Developer Tools

Vercel Analytics & Speed Insights Setup

Wire up Vercel Analytics, Speed Insights, and SPA routing rewrites into a React/Vite project in one pass — including the routing fix most people miss.

5 minutes
Beginner
Developer Tools

Unslop UI: Kill the AI Design Tells

A frontend guardrail built from a 3.2M-post Reddit analysis of what people actually call AI slop, with a build mode that forces design decisions up front and an audit mode that scans existing code for the tells

10 minutes
Intermediate
Developer Tools

Tunnel Doctor

Diagnose and fix conflicts between Tailscale and proxy/VPN tools on macOS — route hijacking, proxy env vars, SSH double-tunneling, and the ~60s DNS resolver stall.

15 minutes
Advanced
Developer Tools

Vibe Coder: Idea to Prototype

Describe what you want to build and get clean, working code with a simple approach explanation, setup instructions, and optional improvements — optimized for shipping over perfecting.

5 minutes
Beginner
Developer Tools

Who Built This Before Me

Check whether your project, tool, library, or product idea has already been built — before you invest a weekend or a quarter in it.

5 minutes
Intermediate
Developer Tools

Vibe Skill Creator

Build world-class Claude skills through a guided 10-step conversation — explore where Claude fails by default, research the domain, draft, self-critique, test on a real scenario, and iterate until the skill actually improves output.

10 minutes
Intermediate
Developer Tools

Twilio SMS Integration

Automate SMS communications, two-way messaging, notifications, and voice workflows with Twilio

10 minutes
Advanced
Developer Tools

Webhook Automation Builder

Build and manage webhook-based integrations for real-time event processing and API connections

10 minutes
Advanced
Developer Tools

Web App Testing

Test local web applications with Playwright automation for frontend verification, UI debugging, and screenshot capture.

15 minutes
Intermediate
Developer Tools

Tech Debt Analyzer

Identify, analyze, document, and track technical debt in JavaScript/TypeScript codebases with automated detection and prioritized remediation plans.

10 minutes
Intermediate
Developer Tools

Agent SDK App Builder

Scaffold new Claude Agent SDK applications in TypeScript or Python, and verify existing ones against official SDK patterns before you ship.

10 minutes
Intermediate

Browse all Developer Tools playbooks →