Skip to content

How to Create a Telegram Echo Bot Using the GREEN-API in n8n#

Echo bot setup procedure:

  1. Setup the GREEN-API application
  2. Create a scenario
  3. Setup receiving incoming messages
  4. Send a message

Setup the GREEN-API application#

Setting up the GREEN-API application is described in detail in the Integration Setup section.

Create a scenario#

  1. Create a workflow: click the Build a workflow card (on an empty account) or the + button in the upper-left corner.

    workflow

  2. Click Add first step... to open the node panel.

  3. Find the GREEN-API for Telegram node.

    app


Setup receiving incoming messages#

To receive messages in n8n, you need to set up a trigger.

Trigger is the event that starts your scenario. For example, it could be a new message in Telegram, a new entry in Google Sheets, or something else.

Trigger setup procedure:

  1. In the node card, select On incoming message in the Triggers section (the scenario is run when a message is received). The Trigger On field is already set to Incoming Message by default.

  2. In the connection credential selection field, click Connect to Green-API.

    credential

  3. Enter idInstance and apiTokenInstance from the GREEN-API console into the idInstance and apiTokenKey fields respectively. Save your connection credentials by clicking Save.

    console

    Applying the instance settings required for the trigger to work can take up to 5 minutes.

  4. Go to the module settings, click Execute step, and send a test webhook of the incomingMessageReceived type to your webhook's testUrl to get sample data that will be used in the next module. Alternatively, send a test Telegram message to the account linked to the instance. The received data will be displayed in OUTPUT.

    app

    In Telegram, chatId is a number without the @c.us suffix.


Send a message#

After setting up the receipt of incoming messages, you need to create an action that will respond to the user with the same text.

  1. Click + to the right of the trigger, find the GREEN-API for Telegram node, and select Send message in the Actions section.

    empty-action

  2. Use the data received in the webhook module, senderData.chatId and unifiedMessageText, to send a message. Drag them into the corresponding chatId and Message fields in the Send message module parameters.

    send-message

  3. Publish the Workflow: click Publish in the upper-right corner and confirm by clicking Publish in the Publish workflow window. Once published, the button shows Published.

    connection-action

    To stop the bot, click the arrow next to Published and select Unpublish.

This completes the bot setup. Now, when you send a message to the Telegram account linked to the instance, you'll receive a reply with the same content.