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.
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#
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.
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.
- Click on the plus sign and find "GREEN-API" in the list of applications
- Select the "New Message Webhook" module
- Click on
Add
to add a webhook to the instance from which notifications will be received
- In the window that opens, click
Add
to add a connection to the instance
-
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
andApi Token Instance
- your instance authorization data
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
-
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
-
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
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.
When selecting a number from the contact list, you must select the desired chat in the drop-down menu in the
Chat Id
section.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.
-
To add an action, click on the semicircle next to the trigger. An empty gray circle with a plus sign will appear (add app)
-
Select an application to perform the action, to do this, find GREEN-API in the application list
-
Select the SendMessage method
-
From the
Connection
list, select a ready-made connection or add a connection by clicking theAdd
button
-
In the
Chat ID source
field, selectManual
-
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 thechatId
variable, which is located in thesenderData
section of the incoming notification - In the
Message
field, paste thetextMessage
variable from themessageData
section. Then clickOK
- Make a test by clicking the
Run once
button. If the test is successful, click on thezoom in
icon to see details of the action result
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.
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. We set the check condition to
Starts with
to check for the presence of the phrase at the beginning of the message !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
Replace
modulePattern
field. In our case, !green-bot
(with a space at the end)New Value
field, insert the emptyString
variable to replace the phrase with an empty string textMessage
SendMessage
module with the output of the Replace
module !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.
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.
This completes the bot setup.