Skip to content

How to Create WhatsApp Echo Bot Using GREEN-API in Make#

How ​​to create an echo bot:

  1. Setting up the Green-API application
  2. Creating a scenario
  3. Setting up receiving incoming messages
  4. Sending a message
  5. Launching and testing the bot

Setting up the Green-API application#

Setting up the Green-API application is described in detail in the section Integration setup

Creating a scenario#

A Scenario is an automated process created in Make.
Each scenario consists of a trigger and an action. When a trigger is fired in one application, Make automatically performs the action in the other.

Scenario template

You can create a scenario according to the instructions or use our ready-made template.

Steps to create a scenario:

  • Log in or register an account in Make
  • Click the Scenarios button in the sidebar

    go-to-scenarios

  • On the scenarios page, click Create a new scenario to create a new scenario

    create-new-scenario

  • Scenario successfully created!

After creating the scenario, a plus sign (adding a module) will appear on the Make page.


Setting up receiving incoming messages#

To receive messages in Make, you need to set up a trigger:

Setting up an instance

When using the Watch Incoming Webhooks trigger, instance setup: is automatically installed

"webhookUrl": "https://hook.eu2.make.com/xxxxxxxxxxxxxxxxxxxx",
"incomingWebhook": "yes"
  1. Create a new scenario
  2. Click on the + sign, in the list of applications find GREEN-API for WhatsApp

    app

  3. Select the Watch Incoming Webhooks trigger at the top of the list

    watch-webhooks

  4. Click on the added module to open its settings

  5. Click Create a webhook to add a webhook

    add-webhook

  6. Click Create a connection to add a connection to the instance

    create-webhook

    • Specify the values of your idInstance and apiTokenInstance
      (The script will receive messages from the number linked to this instance)

    make-green-api-form

    The Connection name field can be used to name the instance being added (for example, "work number" or "sales").
    This will allow you to easily find the required account in the list of available integrations when creating.

Filter messages by sender number

By default, the script activates when a message is received from any number.
To run the script when a message is received from a specific number (or several specific numbers), use the chatIds parameter.

chatIds

  • The number can be selected from the contact list by clicking on the drop-down list icon:

    specify-chat-yes-contactlist

  • The number can be added manually by entering it in the ChatId field:

    specify-chat-yes-manual

When filling in the number manually, enter it in international format + postfix c@us - phoneNumber@c.us.
For example: 79876543210@c.us.

To add multiple numbers, add the required number of fields by clicking Add item

chatIds

  • Click Save to save your settings

  • Test by clicking Run once.

If the selected chat has incoming messages and the test is successful, click the magnifer to see what fields will be available when configuring the action.

test-trigger

Done! The trigger is set up, ready to use!


Sending 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.

To do this, find GREEN-API for WhatsApp in the list of applications

empty-action

  1. Select Send a Message module

    send-message

  2. From the Connection list, select a ready-made connection or add a new connection by clicking the add button.

    When adding a new connection, specify your instance values idInstance and apiTokenInstance

    Then click Save to save.

    connection-action

  3. As a recipient, select the sender from the incomingMessageReceived notification received in the Watch Incoming Webhooks module

    • Click on the Chat Id input field.
    • A window will open on the right with data received via the trigger.
    • Specify the chatId variable from the senderData object as the Chat Id.

    Image with the sender's ChatId selected as a recipient

  4. In the Message field, specify the variable with the message text.

    Since the message text can be transmitted in different fields depending on the message type, it is recommended to specify the condition: "extendedTextMessageData.text should only be used if textMessageData: textmessage is empty"

    text-format

  5. Click Save to save the settings

  6. Run a test by clicking the Run once button. If the test is successful, click on the magnifying glass to see the action result details

    test-action

Done! Echobot is ready to run

How to configure the bot to respond only to certain messages?

In some situations, it may be useful for the bot to respond only to certain messages from the chat, for example, when the bot is in a group.
Let's configure our bot to respond to messages with the text !green-bot.

To do this, we will use filters. You can configure them by clicking on the dots linking the webhook and sending the message.

Image with clicked link between receiving and sending a message

As an example, we will check the incoming message for the phrase !green-bot.

  • In the Condition parameter, we specify a variable with the message text.

Since the message text can be transmitted in different fields depending on the message type, it is recommended to specify the condition:
"if textMessageData: textmessage is not empty, then use it; otherwise, use extendedTextMessageData.text"

  • In the Text operators: Equal to parameter, specify the text that the bot will respond to

Image with the textMessage variable selection

We set the check condition to Starts with, to check for the presence of a phrase at the beginning of the message

Image with the choice operator

Now the bot will only respond to messages starting with !green-bot.


To remove this part of the message and get only the user's text request, we will use the Replace module from the built-in Text parser application.

Create a module between the webhook and sending a message

Image with creating a module between the webhook and sending a message

Select the Replace module

Image with selecting the Replace module

In the Pattern field, enter the phrase that we will delete. In our case, !green-bot (with a space at the end)

Image with input of the phrase for replacement

In the New Value field, insert the variable emptyString to replace the phrase with an empty string

Image with selection of an empty string for replacement

As the text for processing, select textMessage

Image with selection of text for processing

In the Send a Message module, replace the text of the response message with output of the Replace module

Image with the processed line selected in the SendMessage module

After this setup, the bot will only respond if the phrase !green-bot is entered at the beginning of the message


Launching and testing the bot#

To ensure that the echo bot works continuously, you need to run automation by activating the switch.

Image with the scenario running

Now the bot is launched and ready to work. You can check its functionality by writing to the number associated with the instance. The bot will respond with the same message in response.

GIF showing the bot in action

This completes the bot setup.