productivity6 nodes20-25 min

Telegram Bot Command Router

Turn n8n into a Telegram bot backend that responds to slash commands in real time. This workflow receives Telegram messages via webhook, parses the command (e.g., /status production, /stats weekly, /alert @team deploy started), extracts arguments, and routes to the appropriate sub-workflow or external API. Includes built-in /help command that auto-generates usage docs, /status command that checks system health, and /stats command that queries your metrics database. Perfect for ChatOps — give your team operational superpowers through Telegram. Extensible: add custom commands by connecting additional Switch branches.

telegrambotchatopsdevops
$19

One-time purchase

⬇ Download Free Preview

How It Works

1Receive

Telegram webhook captures every message sent to your bot

2Parse

Extract command (/status), sub-command, and arguments

3Route

Switch node sends each command to its handler branch

4Respond

Telegram API sends formatted reply back to the chat

📋 Prerequisites

  • Telegram Bot Token (create via @BotFather)
  • n8n instance with public webhook URL (or ngrok for local dev)
  • Optional: Database or API for /stats and /status commands

🎁 What You Get

  • Importable n8n workflow JSON file
  • 6 built-in commands: /help, /status, /stats, /alert, /echo, /whoami
  • Command parser with argument extraction
  • Telegram Bot setup guide (@BotFather → webhook registration)
  • Extensible Switch-based routing — add commands without restructuring
  • Help command auto-generation from registered commands

📖 Setup Guide

## Setup Guide 1. **Create Telegram Bot**: Message @BotFather on Telegram, send /newbot, choose a name and username. Save the API token. 2. **Register Webhook**: In n8n, create a Webhook node (Production URL). Register it with Telegram: ``` curl -X POST https://api.telegram.org/bot<YOUR_TOKEN>/setWebhook \ -d url=https://your-n8n-instance.com/webhook/your-webhook-path ``` 3. **Webhook node**: Configure as POST, respond "When Last Node Finishes" 4. **Function node (Parser)**: Extract command from message text: ```javascript const text = $input.first().json.message.text; const match = text.match(/^\/(\w+)(?:\s+(.+))?/); return { command: match ? match[1] : 'unknown', args: match ? (match[2] || '').split(' ') : [], chat_id: $input.first().json.message.chat.id, user: $input.first().json.message.from }; ``` 5. **Switch node**: Route by command value: - **/help** → HTTP Request: sendMessage with list of available commands - **/status** → Query your monitoring system, format results, send reply - **/stats** → Query metrics DB, send formatted stats - **/alert** → Parse alert target and message, forward to Slack/email - **/echo** → Send back the arguments (useful for testing) - **/whoami** → Reply with Telegram user info - **Default** → Send "Unknown command. Try /help" 6. **HTTP Request node (Telegram API)**: For each response, call: ``` POST https://api.telegram.org/bot<TOKEN>/sendMessage { chat_id: {{ chat_id }}, text: "Your response", parse_mode: "Markdown" } ``` > 💡 **Pro tip**: Add a "cooldown" check at the start — if the same user sends more than 10 commands in 30 seconds, temporarily ignore them with a "rate limit" reply.

Ready to automate?

Get this template and start automating in 20-25 min. One-time purchase, lifetime access.