Skip to content

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

In the Make service, the GREEN-API platform has its own application (alternative link to the application), with which you can send messages to WhatsApp.

What should I do if an installation error occurs?

If an error occurs when installing the application using the specified links in Make, we recommend that you specify in the link the subdomain in which you were authorized on the site.
The subdomain determines the availability of the site via a link.
Examples of available domains: eu1, eu2, us1, us2.

EU1

In this tutorial, we'll walk through the process of creating an echo bot for WhatsApp that will automatically reply to received messages. The bot is implemented using the GREEN-API application for the Make platform.

Steps to create an echo bot:

  1. Setting up integration

  2. Receiving a message

  3. Sending a message

  4. Launching and testing the bot

1. Setting up integration#

Before you start developing a bot, you need to log in to the Make service and connect the application from GREEN-API. To do this, follow the link to install the application specified above and click the "Install" button on the page that opens. After that, select the organization for which you want to install the application.

Scenario - an automated process created in Make. Each scenario consists of a trigger and an action. When a trigger is triggered in one application, Make automatically performs the action in the other. You can create a scenario from the "Scenarios" section of the side menu by clicking on the "Create a new scenario" button.

Image with transition to tab

Image with scenario creation

After this, the scenario workspace will appear, in which you can make further adjustments.

2. Receiving a message#

To start using the application in Make, you need to get the instance data. Information on how to create an instance and retrieve its data can be found at link.

The instance must also be authorized. This action links the WhatsApp account on your phone to the instance, allowing you to send and receive messages. Detailed instructions on authorizing the instance are provided in the article "Quick Start" в нашей документации.

The scenario should be run after the echo bot receives an incoming message. In this tutorial, we will look at the process of receiving notifications via WebHook.

Other ways to set up notifications can be found at link.

To receive incoming notifications via WebHook, use the "New Message Webhook" trigger from the GREEN-API integration. Let’s set it up as follows.

  1. Click on the plus sign and find "GREEN-API" in the list of applications
    Image with application search
  2. Select the "New Message Webhook" module
    Image with trigger selection
  3. Click on Add to add a webhook to the instance from which notifications will be received
    Image with new WebHook added
  4. In the window that opens, click Add to add a connection to the instance
    Image with new instance added
  5. Enter a value from the authorized instance, where:

    • Connection name - arbitrary name of the connection to the instance (not to be confused with the instance name)
    • ID Instance and Api Token Instance - your instance authorization data
      Image with instance data input
    What should I do if an error occurs when trying to connect an instance?

    When trying to connect an unauthorized instance, a notification with the error Unexpected status notAuthorized. Should be "authorized" will appear. This error can be removed by authorizing the instance, linking the WhatsApp account to the instance

    Image with error when connecting instance

  6. Save the webhook data by first clicking on the "Save" button, and then on the "OK" button

Before further configuration, you will need to send a test message to the phone number associated with the instance.

  • To do this, temporarily run the automation by clicking on the "Run Once" button

    Image with the scenario launch button

  • Send a text message to the phone number associated with the instance. In a few seconds, you should receive an incoming notification, the data from which will be required for further configuration

    Image with received notification

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

In the "Create a webhook" window, in the "Only From Specify Chat" section, select "Yes".
You can specify a chat manually by selecting the "Manual" type in the Chat ID source, or through the contact list by selecting "From Contact List".
When filling in the number manually, you need to enter the number in the format phoneNumber@c.us. For example: 0100123456789@c.us.

You must enter the full phone number in international format. Do not use plus signs, zeros, brackets or hyphens when entering a phone number in international format.

specify-chat-yes-manual

When selecting a number from the contact list, you must select the desired chat in the drop-down menu in the Chat Id section.
specify-chat-yes-contactlist

3. 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. The sendMessage method will help with this.

To send messages in Make, you need to add and configure the "Send Message" module.

  1. To add an action, click on the semicircle next to the trigger. An empty gray circle with a plus sign will appear (add app)

    add-action

  2. Select an application to perform the action, to do this, find GREEN-API in the application list

    empty-action

  3. Select the SendMessage method

    send-message

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

    connection-action

  5. In the Chat ID source field, select Manual

    Image with Chat ID Source selection

  6. To reply to a user who wrote to the bot, you need to define them as a recipient. To do this, in the Chat Id field, you need to specify the value of the chatId variable, which is located in the senderData section of the incoming notification

    Image with chatId selection

  7. In the Message field, paste the textMessage variable from the messageData section. Then click OK
    Image with textMessage selection
  8. Make a test by clicking the Run once button. If the test is successful, click on the zoom in icon to see details of the action result
    test-action

Done! Echo Bot is ready to launch

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

In some situations it may be useful for the bot to only respond 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 that connect the webhook and sending the message.

Image with click on the connection between receiving and sending a message
After this, a window with filter settings will open, in which Label is an arbitrary filter name, and the presented text fields use comparisons with each other according to the condition selected in the Text operators menu.
In our case, we will check the incoming message for the phrase !green-bot. To do this, insert the variable textMessage from the messageData section into the first field.
Image with textMessage variable selected
In the second field we write the phrase to which the bot will react
Image with the phrase entered in the second field

We set the check condition to Starts with to check for the presence of the phrase at the beginning of the message
Image with operator selection
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 query, we will use the Replace module from the built-in Text parser application.
Create a module between the webhook and sending a message
Image showing module creation between webhook and message sending
Select the Replace module
Image with Replace module selected
Enter the phrase we will be deleting in the Pattern field. In our case, !green-bot (with a space at the end)
Image with input phrase for replacement
In the New Value field, insert the emptyString variable to replace the phrase with an empty string
Image with empty string selection for replacement
As the text to be processed, select textMessage
Image with text selection for processing
Replace the text of the response message in the SendMessage module with the output of the Replace module
Image with selection of processed line in SendMessage module
After this setting, the bot will only respond if the phrase !green-bot is entered at the beginning of the message

4. Launching and testing the bot#

To ensure continuous operation of the echo bot, you need to start automation by activating the switch.

Image with scenario running

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

GIF showing the bot in action

This completes the bot setup.