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#

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.

Script template

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

Algorithm for creating 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 webhooks trigger, instance setup: is automatically installed

"webhookUrl": "webhookserver make",
"incomingWebhook": "yes"

Algorithm for setting up a trigger:

  • Create a new scenario
  • Click on the + sign, find GREEN-API for WhatsApp in the list of applications

    app

  • Select the Watch webhooks trigger at the beginning of the list

    watch-webhooks

  • Click on the added module to open its settings

  • Click Create a webhook to add a webhook

    add-webhook

  • Click Create a connection to add a connection to the instance

    create-webhook

  • Specify the values ​​of your instance idInstance and apiTokenInstance
    (The scenario will receive messages from the number associated with this instance)

    make-green-api-form

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

  • Click Save to save the values


  • Test by clicking the Run once button.

If the selected instance has incoming messages and the test is successful, click the magnifying glass to see which fields will be available when configuring the action.

test-trigger

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

How to receive notifications only from a specific chat or group?

By default, the scenario is triggered when a message is received from any number that wrote.

To run a scenario 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, it is required to enter it in international format + postfix c@us - phoneNumber@c.us. For example: 79876543210@c.us.

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

chatIds


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.

  1. Click on the + sign, find GREEN-API for WhatsApp in the list of applications

    empty-action

  2. Select the Send a Message module

    send-message

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

    When adding a new connection, fill in your instance data idInstance and apiTokenInstance
    Then click Save to save.

    connection-action

  4. In the Chat ID source field, select Manual:

    chat-id

  5. Click on the Chat Id input field, specify the sender variable from the senderData object in it.

    sender1

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

  7. Click Save to save the settings

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