To use n8n with Telegram, you can integrate your Telegram Bot to receive and send messages automatically via workflows. Below is a step-by-step guide to set up this integration.
π§© Step-by-Step: Connect n8n with Telegram
β
Step 1: Create a Telegram Bot
- Open Telegram and search for
@BotFather.
- Type
/start then /newbot.
- Follow the prompts to give your bot a name and username.
- Youβll receive a Bot Token like
123456789:ABCdefGhIjKlMnOpQRstuVWXyZ.
β
Step 2: Set the Webhook (Optional if using polling)
If you're hosting your own n8n and using Telegram Trigger, you can either:
- Use Polling (easier for local development)
- Or set a Webhook URL using:
https://api.telegram.org/bot<YourBotToken>/setWebhook?url=https://your-n8n-url/webhook/telegram
Note: Replace <YourBotToken> and your-n8n-url accordingly.
β
Step 3: Add Telegram Credentials in n8n
Go to n8n Dashboard > Credentials.
Create new credentials:
β
Step 4: Create a Telegram Trigger Workflow
- In the n8n Editor, add the node:
- Telegram Trigger
- Select credentials you created
- Choose
Polling or Webhook
- This will listen for new messages sent to your bot.
β
Step 5: Add Processing Nodes
You can add additional nodes like:
- Function: to parse messages
- IF: to check keywords
- Telegram (Sender node): to send replies
Example:
- Telegram Trigger β Function (parse "hello") β Telegram (send "Hi there!")
β
Step 6: Activate Workflow
Click Activate to make the bot live. Now every time a user sends a message, your bot will respond automatically based on your flow.
π Example Use Case
Respond with βHi πβ when a user types βhelloβ:
1. Telegram Trigger (listens to all messages)
2. IF Node:
- IF `message.text` equals `hello`
3. Telegram Node (Send Message):
- Text: `Hi π! How can I help you today?`
π§ Pro Tips
- Always test in manual execution mode first.
- Secure your webhook endpoint.
- Use environment variables for sensitive data.
Here is a sample n8n workflow JSON that connects to Telegram, listens for a message like "hello", and replies with "Hi π! How can I help you today?".
β
How to Import the Workflow:
- Open your n8n Editor.
- Click the menu (β‘) in the top right.
- Choose Import Workflow > paste the JSON below.
- Replace the Telegram credentials with your own.
π¦ Sample Workflow JSON
{
"nodes": [
{
"parameters": {
"updateInterval": 1000,
"additionalFields": {}
},
"id": "1",
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"typeVersion": 1,
"position": [300, 300],
"credentials": {
"telegramApi": {
"id": "YOUR_CREDENTIAL_ID",
"name": "Telegram API"
}
}
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$json[\"message\"][\"text\"]}}",
"operation": "equals",
"value2": "hello"
}
]
}
},
"id": "2",
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [500, 300]
},
{
"parameters": {
"chatId": "={{$json[\"message\"][\"chat\"][\"id\"]}}",
"text": "Hi π! How can I help you today?",
"additionalFields": {}
},
"id": "3",
"name": "Send Telegram Message",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1,
"position": [700, 200],
"credentials": {
"telegramApi": {
"id": "YOUR_CREDENTIAL_ID",
"name": "Telegram API"
}
}
}
],
"connections": {
"Telegram Trigger": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "Send Telegram Message",
"type": "main",
"index": 0
}
],
[]
]
}
},
"active": false,
"settings": {},
"name": "Telegram Hello Bot",
"tags": []
}
π§ Replace:
"YOUR_CREDENTIAL_ID" with the ID of your Telegram credentials in n8n.
- You can also use the credential name if preferred.
Let me know if you'd like:
- A more advanced version (e.g. command handler, reply keyboard).
- A Webhook-based version instead of Polling.
- Instructions on how to deploy this on cloud/VPS securely.