Lesson 154 min

How to Connect n8n to Telegram

Learn how to connect n8n to Telegram by creating a new bot with BotFather, getting an API access token, and using the Telegram trigger to receive messages in your workflows.

How to Connect n8n to Telegram

Connecting n8n to Telegram allows you to build powerful bots and automations that react to messages in real-time. This tutorial will guide you through the process of creating a new Telegram bot using BotFather, obtaining an access token, and setting up the n8n Telegram trigger to listen for new messages.


Prerequisites

  • An n8n workflow.
  • A Telegram account.

Step 1: Create a New Bot with BotFather

The first step is to create a new bot inside Telegram using a special, official bot called BotFather.

  1. Open your Telegram app (web, desktop, or mobile).
  2. Search for the user @BotFather (it will have a blue checkmark next to its name) or click this link to open a chat directly.
  3. Start a chat with BotFather and send the command /newbot.
  4. BotFather will then ask you for a display name for your bot. Enter any name you like (e.g., n8n New Bot).
  5. Next, it will ask for a unique username. This username must end with the word bot (e.g., MyAwesomeN8nTest_bot).

Step 2: Get Your API Access Token

Once the bot is successfully created, BotFather will provide you with the unique API access token required to connect to it.

  1. After you provide a valid username, BotFather will respond with a confirmation message.
  2. This message contains your API access token. It is a long string of numbers and letters.
  3. Click the token to copy it to your clipboard.

⚠️ Important: Treat this access token like a password. Anyone who has it can control your bot.


Step 3: Configure the Telegram Node in n8n

Now, let's add the Telegram trigger to your n8n workflow and configure it with your new token.

  1. In your n8n workflow, add a new Telegram Trigger node.
  2. For the "Event," select "On Message". This will make the workflow run every time a new message is sent to your bot.
  3. In the "Credential" field, select "Create New".
  4. A dialog will appear asking for an "Access Token".
  5. Paste the API token you copied from BotFather into this field.
  6. Click "Save". You should see a "Credential successfully created" message.

Step 4: Test the Telegram Trigger

Finally, let's test the connection to ensure your n8n workflow can receive messages from your new bot.

  1. In the confirmation message from BotFather, there is a direct link to your new bot (e.g., t.me/YourBotUsername). Click this link to open a chat.
  2. Click the "Start" button at the bottom of the chat window.
  3. Go to your n8n workflow and click "Test workflow" on the Telegram Trigger node. The node will now show that it is "Waiting for webhook call."
  4. Switch back to Telegram and send a message to your bot (e.g., "Hello world").
  5. Return to n8n. The workflow should have executed successfully, and you will see the message data from Telegram in the trigger's output.

You have now successfully connected n8n to Telegram and can use incoming messages to trigger any automation you can imagine.