Skip to content

OpenAI 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#

  1. Setting up the Make application
  2. Setting up the GREEN-API application
  3. Creating a scenario
  4. Setting up receiving incoming messages
  5. Processing the request through OpenAI
  6. Sending the response message to the user
  7. Testing the functionality

Setting up Make and Green-API applications#

Setting up Make and Green-API applications is described in detail in the section Integration setup

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.

Script template

You can create a script using the instructions below or use our ready-made template.

Algorithm for creating a scenario:

  1. Log in or register an account on Make
  2. In the sidebar menu, click on the Scenarios button

    go-to-scenarios

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

    create-new-scenario

The scenario has been successfully created!


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.

  1. Create a new module to receive incoming messages. In the list, select the "GREEN-API" integration

    Image with the GREEN-API application search

  2. Select the module for receiving the incoming webhook – "New Message Webhook"

    Image with the selection of the "New Message Webhook" module

  3. Select the webhook

    An image with a webhook selection from the drop-down list

    How to create a webhook?
      1. Click the add button in the module window
        An image with a click on a button in the webhook module

      If the webhook and instance connection do not exist yet, create them using the following steps:

      1. Then, select the connection to the instance or create it by clicking the add button in the window that appears
        Image of the instance selection window
  4. 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

    Enabling webhook settings

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

Error processing webhook
  • If the OpenAI module receives an error like the one below when running the scenario, you need to install a filter between the New Message Webhook module and the OpenAI module.

    Error

  • In the filter, set the condition where typeWebhook must be equal to incoming Message Received.

    Filter1
    Filter2


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.

  1. Among the integrations, find "OpenAI"

    Image with OpenAI application search

  2. To generate a response for the user, select the "Create a Completion" module

    Image with the "Create a Completion" module selection

  3. Before proceeding with the configuration, we will need to obtain the Api key and Organization ID from the OpenAI account's personal dashboard

    1. To get the Api Key, you need to sign up or log into your OpenAI
    2. Go to the Api Keys tab and click the Create New Api Key button

      An image with a transition to the desired button

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

      An image with data input for creating an Api Key

    4. Save the generated key

      Image with Window with Api Key

    5. In addition to the Api Key, you will also need the Organization ID. It can be found in the General tab

      An image from the General page with the Organization ID specified on it

  4. Enter the account details in the module

    1. Click the Create a connection button

      An image with a connection creation button

    2. Paste the data into the API Key and Organization ID fields obtained in step 3

      Images with the entered data for connection with OpenAI

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

    An image with a model selection for the answer

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

    What 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

    Image with the "User" role selection

    1. To do this, click the Add message button

      An image with a button for creating a message with a role

    2. Select the role. First, we will create the "System" role with additional instructions for the model

      Image with the choice of the "System" role

    3. Fill in the message, mentioning the user's name based on the senderName

      An image with a completed system message for the model

    4. Then, create a second request with the "User" role, passing the user's message in the Text Content field

      An image with a completed user message for the model

Before proceeding to the next step, you need to send a message to the number associated with the instance again to continue the configuration


Sending a reply message to the user#

  1. Creating a new module "Send Message" from the integration of the GREEN-API

    Image showing the selection of the "Send Message" module

  2. For the recipient, choose the sender from the first message

    Image showing the selection of the sender's ChatId as the recipient

  3. The text message will be the response from the language model. Select the "Result" variable from the "Create a Completion" module

    Image showing the selection of the OpenAI result as the reply message

  4. Run the automation by toggling the switch in the corner of the screen

    Image showing the toggling of the scenario switch


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.

An image with successful 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

How to use Google Sheets for organizing mailings in Make

How to make messaging between WhatsApp and Google Sheets