Shane H.
@ship_shane ·
Build a Telegram Bot with n8n in 30 Minutes
Introduction to n8n and Telegram Bots
I recently discovered the power of n8n and how it can be used to automate workflows with ease. In this post, I'll share my experience of building a simple Telegram bot using n8n in under 30 minutes.
Prerequisites
Before you start, make sure you have the following:
- n8n installed on your system (I'm using the desktop app)
- A Telegram account and a bot token from the BotFather
- Basic knowledge of n8n workflows
Step 1: Create a New Workflow
Create a new workflow in n8n and add the following nodes:
- Telegram node to receive updates from your bot
- Function node to process the updates
- Telegram node to send responses back to the user
Step 2: Configure the Telegram Node
Configure the Telegram node to receive updates from your bot by providing the bot token and setting up a webhook. You can use the tg:// protocol to set up the webhook.
Step 3: Process Updates with a Function Node
Use the Function node to process the updates received from the Telegram node. For example, you can use JavaScript to parse the message text and respond accordingly.
Step 4: Send Responses with the Telegram Node
Configure the second Telegram node to send responses back to the user. You can use the sendMessage method to send a response.
Example Workflow
Here's an example workflow that responds with a greeting:
- Receive update from Telegram node
- Process update with Function node:
if (msg.text === 'hello') { return { text: 'Hello! How are you?' }; } - Send response with Telegram node
Conclusion
Building a Telegram bot with n8n is a breeze! With these simple steps, you can create a bot that responds to basic commands in under 30 minutes. What are some use cases you've built with n8n and Telegram? Share your experiences in the comments below.