How to create an AI-powered chatbot with OpenAI in WhatsApp?#
The Make platform offers extensive opportunities for automating various processes. We have covered in previous articles how to automate messaging between WhatsApp, Discord, and Slack, as well as how to set up message broadcasting using Google Sheets. In this article, we will consider how to use Google Sheets and GREEN-API to automate mailings in WhatsApp.
To follow along, you'll need a GREEN-API account with an instance set up, as well as accounts on Make and OpenAI.
Content#
- Setting up the Make application
- Setting up the GREEN-API application
- Creating a scenario
- Setting up receiving incoming messages
- Processing the request through OpenAI
- Sending the response message to the user
- Testing the functionality
1. Setting up the Make application#
- Log in or create an account on Make
- Install the GREEN-API app in Make using the link
- Click the
Install
button
- Select the organization where the GREEN-API app will be installed and click the
Install
button - On the
Installed Apps
page, you can check the availability of the app in your organization
2. Setting up the Green API application#
To start working with GREEN-API, you need to register and get idInstance
and apiTokenInstance
in your console. We recommend that you pay attention to our free Developer plan.
- Log in or register an account on GREEN-API
- Create an instance on the free "Developer" plan. To do this, go to console and click the
Create an instance
button. Then, for testing purposes, select the "Developer" plan
-
Authorize the phone. To do this:
-
You can scan the QR code on the instance setup page. In the WhatsApp mobile app or WhatsApp Business, log in to the linked devices and scan the QR code received
-
Or request a six-digit authorization code to be bound by phone number. In the WhatsApp mobile app or WhatsApp Business, log in to linked devices and tap
Link with phone number instead
After successful authorization, the instance should have the status
Authorized
You can check the status of the instance using theGetStateInstance
method -
-
You will need to copy the values of
idInstance
andapiTokenInstance
for working with Make scenarios
3. Creating a scenario#
Scenario - an automated process created in Make. Each scenario consists of a trigger and an action. When the trigger is activated in one of the Make applications, it automatically performs an action in another.
Algorithm for creating a scenario:
- Log in or register an account on Make
- In the sidebar menu, click on the
Scenarios
button - On the scenarios page, click
Create a new scenario
, to create a new scenario
The scenario has been successfully created!
4. Setting up receiving incoming messages#
After creating the scenario, you can configure receiving incoming messages. Let's set it up using Webhooks technology.
Useful
You can find detailed configuration of the GREEN-API integration, as well as other ways to receive messages, in the article on integration setup.
- Create a new module to receive incoming messages. In the list, select the "GREEN-API" integration
- Select the module for receiving the incoming webhook – "New Message Webhook"
-
Select the webhook
How to create a webhook?
- If the webhook and instance connection do not exist yet, create them using the following steps:
- Click the
add
button in the module window - Then, select the connection to the instance or create it by clicking the
add
button in the window that appears
- Click the
- If the webhook and instance connection do not exist yet, create them using the following steps:
-
To receive incoming notifications, you need to enable notifications for incoming messages in the personal account interface or by using the SetSettings method. Applying the settings may take up to 5 minutes
Before proceeding to the next step, you need to send a message to the number associated with the instance in order to continue configuring the integration
5. Processing the request through OpenAI#
In this step, we will set up sending the user's message to the OpenAI integration to get a response from the neural network.
- Among the integrations, find "OpenAI"
- To generate a response for the user, select the "Create a Completion" module
- Before proceeding with the configuration, we will need to obtain the
Api key
andOrganization ID
from the OpenAI account's personal dashboard- To get the
Api Key
, you need to sign up or log into your OpenAI - Go to the
Api Keys
tab and click theCreate New Api Key
button
- Enter a name for the key and select a project. In our case, it will be "Default Project." After entering all the required information, click the
Create New Key
button - Save the generated key
- In addition to the
Api Key
, you will also need theOrganization ID
. It can be found in theGeneral
tab
- To get the
- Enter the account details in the module
- Click the
Create a connection
button - Paste the data into the
API Key
andOrganization ID
fields obtained in step 3
- Click the
- The next step is to choose the model that will generate the response for the user. Each model in the list has its own advantages and disadvantages, which can be found in the official documentation
For our purposes, the "gpt-4o-mini" model is suitable, as it provides high-quality responses with fast generation speed and low cost
-
Let's create a query for the model. At this stage, we need to select a role and its corresponding message
In this example, we will create a request with the "System" role to pass the user's name and the dialogue format to the modelWhat are roles and what’s the difference between them?
When using the OpenAI API, you may encounter the concept of a "Role" in a request to ChatGPT. What is the difference between them? * A request with the "System" role is a direct input to the language model, setting its context and behavior. For example, you can make the tone of the model more formal or provide additional information that the model will use to generate the response * A request with the "User" role represents the user's input, to which the language model responds
- To do this, click the
Add message
button - Select the role. First, we will create the "System" role with additional instructions for the model
- Fill in the message, mentioning the user's name based on the senderName
- Then, create a second request with the "User" role, passing the user's message in the
Text Content
field
- To do this, click the
Before proceeding to the next step, you need to send a message to the number associated with the instance again to continue the configuration
6. Sending a reply message to the user#
- Creating a new module "Send Message" from the integration of the GREEN-API
- For the recipient, choose the sender from the first message
- The text message will be the response from the language model. Select the "Result" variable from the "Create a Completion" module
- Run the automation by toggling the switch in the corner of the screen
7. Testing the functionality.#
To test the automation, it is enough to send a message to the number associated with the instance. After a few seconds, a reply message will be sent in response, containing a response from ChatGPT, and in Make you can see the successful completion of automation.
Thus, we have set up a personal AI chatbot in WhatsApp for communication with users.
Examples of using the GREEN-API application#
How to make messaging between WhatsApp and Slack
How to make messaging between WhatsApp and Discord