Support use case: Use WhatsApp to create an AI agent flow

ActiveCampaign plans
Starter
Plus
Pro
Enterprise

With ActiveCampaign’s WhatsApp feature, you can use ChatGPT to build a flow that answers the most common questions about your business. Doing so allows your Support team to focus on more complex customer issues and helps you provide product or service information 24/7, even when your agents aren’t online.

This article shows you how to create an inbound Support AI Agent flow that answers customer questions, with a handoff condition to send the conversation to a human agent if the question is too complex for the AI.

Take note

  • To complete this setup, you need:
  • We recommend using the playground if you’re not yet familiar with the API. Note your assistant_id, as you will need it later
  • This option is for advanced users. You need to be comfortable with code. Our Customer Experience team cannot help you implement or troubleshoot code
  • This flow requires you to use a custom contact text input field to save the customer’s response to your greeting. In the steps below, we use a field named “gpt_response.” Learn how to create a custom contact field 

Create a Support GPT flow

Step 1: Create a new flow.

From your ActiveCampaign account:

  1. Click WhatsApp > Messaging Flows.
  2. Click “New Messaging Flow.”
  3. Under the “Details” tab, give your flow a short yet descriptive name. Then click “Next.”
  4. Under the “Trigger” tab, determine how contacts enter your flow. For this example:
    • Select “Inbound Message”
    • Select “Any Message.” This ensures that the flow starts whenever a lead or contact sends a message to your support number
    • Click “Next”

Step 2: Add a “Question” step to your flow.

When a customer triggers our flow, we want to greet them with a message or question. To do so, we’re going to add the “Question” step to our flow. 

The customer’s response to this step is saved in the flow as a step variable. We will refer to this variable in Step 3 below. 

Note that we automatically save the customer’s first and last name and phone number when they initiate an inbound flow.

  1. Select the “Question” step option, then click “Add.”
  2. Configure the “Question” step:
    • Click the pencil icon and give your step a name. We recommend using short, descriptive names. In this example, we’ll call this step “Start conversation”
    • Type the question you want to ask in the field provided. For example, “Hi there! How can I help you today?” 
      Green tip callout box: Click the lightning bolt icon in the composer to personalize the message. For example, you can greet customers by their first name.
    • Select an answer type. Note that, depending on the answer type you select, additional configurations will be required. Read the “Question” step article for more information
    • Provide an answer validation message
    • Click the optional toggles to turn them “On”:
      • Go to another step if the contact doesn’t answer the question correctly
      • Go to another step if the contact doesn’t answer the question in a certain period of time
      • Do something if the message fails to send

Step 3: Save the customer’s response

Next, we want to save the customer’s response to the “Question” step above. To do that, we’ll add the “Update contact” step to our flow. The “Update contact” step will save the customer’s response as a custom field value on their contact record. 

  1. Add the “Update Contact” step to your flow:
    • Click the node (“+”) below the “Question” step
    • Select “Update Contact”
  2. Configure the “Update Contact” step:
    • Click the pencil icon and give your step a name. In this example, we’ll call this step “Create/Update contact”
    • Click the “Custom” tab > “Add property” button
    • Click the first dropdown and select the custom field you want to update with the customer’s response. In this example, we’re going to use a custom contact field called “gpt_response” 
    • Next, we need to map our custom field to the step variable that saved the customer’s response. To do so, click the lightning bolt icon, click “Step Variables,” then select the step variable provided. (There should only be one listed at this time)

      Example of the Create Update contact flow step. This shows the property and variable under the custom tab.

Step 4: Integrate GPT for answering questions

In this step, we’ll start an OpenAI thread to send the user’s response to the AI agent. 

  1. Add an “API” step to your flow:
    • Click on the node (+) below the “Update Contact” step 
    • Select “Connect APIs,” then click “Add”
  2. Configure the “Connect APIs” step:
    • Click the pencil icon and give your step a name. In this example, we’ll call this step “Start OpenAI thread”
    • Select “Post” under “Method Type”
    • Enter the following URL: https://api.openai.com/v1/threads
    • Select “JSON” under the “Body” tab. Leave the “Message body” blank
    • Under the “Headers” tab, add the following three headers:
      • Header 1: OpenAI-Beta / assistants=v2
      • Header 2: Content-Type / application/json
      • Header 3: Authorization / Bearer YOUR_API_KEY

        Example of the Connect APIs flow step configuration.
  3. Handle the API Response:
    • OpenAI will respond with a JSON object containing the thread_id, and the data is available for the rest of the flow execution. This data is temporary. If you need to reference this data after the contact exits the flow, we recommend saving it 

Step 5: Send the customer’s query to OpenAI

  1. Add another “API” step to your flow:
    • Click on the node (+) under the “Response” branch of the previous step
    • Select “Connect APIs,” then click “Add”
  2. Configure the “Connect APIs” step:

    • Click the pencil icon and give your step a name. In this example, we’ll call this step “Send Message to OpenAI thread”
    • Select “Post” under “Method Type”
    • Enter the following URLhttps://api.openai.com/v1/threads//messages
    • Now, we need to update the URL to contain the customer’s response to our “Question” step. To do so:
      • Click between the two slashes “//” in the URL
      • Next, click the lightning bolt icon > Step Variables
      • Select the step variable that contains “step.STEPNAME.response.ID.” To continue with our example, our variable looks like: “step.Send Message to OpenAI Thread.respose.id”
    • Under the “Body” tab, select “JSON”
    • Add the following JSON object in the body:
    {
    
      "role": "user",
    
      "content": ""
    
    }
  3. Now we need to update the JSON object to refer to the field we used in the “Update Contact” step above:
    • Click between the two quotation marks (“”) in the content line
    • Click the lightning bolt icon > Contact > Field name. To continue with our example, we’re using the field called “last_chatgpt_response”

Step 6: Run the OpenAI thread

  1. Add an API step to run the assistant:
    • Click on the node (+) under the “Response” branch
    • Select “Connect APIs,” then click “Add”
  2. Configure the “Connect APIs” step:
    • Click the pencil icon and give your step a name. In this example, we’ll call it “Run OpenAI thread with messages”
    • Select “Post” under “Method Type”
    • Enter the following URLhttps://api.openai.com/v1/threads//runs
    • Now, we need to update the URL to contain the thread response ID. To do so:
      • Click between the two slashes “//” in the URL
      • Next, click the lightning bolt icon > Step Variables
      • Select the step variable that contains the response thread ID. To continue with our example, we’ll select “step.Start OpenAI thread.response.id”
    • Under the “Body” tab, select “JSON”
    • Add the following JSON object in the body:
{
  "assistant_id": "YOUR_ASSISTANT_ID"
}
  • Note that you’ll need to insert your assistant ID. You can get the assistant ID when creating a new assistant in the OpenAI

Step 7: Check for GPT response

Here, we are adding another “Connect APIs” step to obtain a response from OpenAI. We’ll also add a “Conditional” step to check whether a response was sent. 

  1. Add the “Connect APIs” step to check for a response:
    • Click the node (+) under the “Response” branch
    • Select “Connect APIs,” then click “Add”
  2. Configure the “Connect APIs” step:
    • Click the pencil icon and give your step a name. For our example, we’ll call this step “Get generated OpenAI”
    • Select “Get” under “Method Type”
    • Enter the following URL: https://api.openai.com/v1/threads//messages
    • Now, we need to update the URL to contain the thread response ID. To do so:
      • Click between the two slashes “//” in the URL
      • Next, click the lightning bolt icon > Step Variables
      • Select the step variable that contains the response thread ID. To continue with our example, we’ll select “step.Start OpenAI thread.response.id”
    • Don’t select anything for the “Body” tab
  3. Add a “Conditional” step:
    • Click on the node (+) under the “Response” branch 
    • Select “Conditional” then click “Add”
    • Set the condition to check if the OpenAI response is empty. To do so:
      • Give your step a name. For our example, we’ll call it “Validate if the message is there”
      • Use the dropdown fields to select your conditions. For our example, we’re using the following:

Where: step.Get generated OpenAI messages.response.data.0.role (Is) Equals assistant 

AND step.Get generated OpenAI messages.response.data.0.content.0.text.value “Is empty.”
Click the “x No” option


Example of the configuration fields for the Conditional step.

  1. Configure the “Path 1” branch:
  2. Configure the “Else” branch. Here, we need to check if the GPT response indicates the need for human intervention:
    • Add a “Conditional” step:
      • Click on the node (+) under the “Else” branch 
      • Select “Conditional” then click “Add”
      • Configure the step:
        • Give your step a name. In our example, we’ll call it “Assign human”
        • Use the dropdown fields to select your conditions. You can have it check for specific keywords or phrases in the GPT response that indicates the need for human intervention. For our example we’re using the following:

          Where: step.Get generated OpenAI messages.response. Data.0.content.0.text.value 
          Contains Assign Human

          Example of the Conditional step configuration.

Step 8: Configure the “Path 1” branch under the “Conditional” step

  1. Click the node (+) under “Path 1.”
  2. Select “Question” then click “Add.”
    • Click the pencil icon and give your step a name. In our example, we’ll call it “Continue chat”
    • In the message body, click the lightning bolt, then click “Step variables”
    • Select the step variable for the “Get generated OpenAI message” step. For our example, we’ll use “step.Get generated OpenAI message.reponse.data.0.content.0.text.value
    • Select “Free Text” for message type

      Example of Question step configuration.
  3. Click the node, then add the “Update Contact” step. To configure this step:
    • Click the pencil icon and give your step a name. In our example, we’re going to call it “Create/Update contact 2”
    • Click the “Custom” tab, then click the “Add property”
    • Select the custom field you created for this flow. Ours is called “last_chatgpt_response”
    • For the value, click the lightning bolt, then click “Step variables”
    • Select the step variable for the previous step. In this example, ours is called “step.Continue chat”
  4. Click the node and add a “Go to” step. Here, we want contacts go to the “Sent Message to OpenAI Thread” step. To do so:
    • Click the pencil icon and give your step a name. We’re calling ours “Go back to OpenAI”
    • The step we’re selecting is “Send Message to OpenAI Thread.” Note the two highlighted steps in the image below:

      Example of the Support GPT flow in the Flow Builder. The Go To step is open and showing the two connected steps.

Step 9: Configure the “Else” branch and assign an agent

In this final part of the flow, we’re going to add two more steps that sends a message to the contact letting them know that we’re transferring them to an agent. The final step is to assign the conversation to the agent. 

  1. Click the node under the “Else” branch and select the “Message” step. To configure this step:
    • Click the pencil icon and give your step a name. We’ll call ours “Assign agent message”
    • Click the dropdown for “Message type” and select “Text”
    • For the body, write a brief message letting the customer know that they’re being transferred to an agent

      Example of the Message step configuration.
  2. Assign the conversation to a team or agent. To do so:
    • Click the node under the previous step, then select the “Conversation” step
    • Configure the step:
      • Click the pencil icon and give your step a name. We’re calling ours “Assign agent”
      • For the “User(s) to assign this conversation to” dropdown, select the user you want to send the message to
      • Click the toggle for the “Append tags?” setting. This means that any tags added to the contact or conversation will be added to tags that already exist

Step 10: Save and publish the flow

Click “Publish” to make the flow active. 

Example Flow Structure

Your flow should now have the following structure:

  1. Trigger: Any incoming message
  2. Question step: Ask the user for their query
  3. Update Contact step: Save the user’s response
  4. Connect APIs step: Integrate OpenAI for answering questions
  5. Connect APIs step: Send the user’s query to OpenAI
  6. Connect APIs step: Run OpenAI thread with messages
  7. Connect APIs step: Check for OpenAI response
  8. Conditional Step: Check if the response is there
    • Path 1 Branch:
      • Delay Step: Wait for 10 seconds
      • Go To Step: Loop back to check for OpenAI response
    • Else branch:
      • Conditional Step: Check if human intervention is needed
        • Path 1 Branch:
          • Question step: Get generated OpenAI message response
          • Update contact step: Update custom field with information from customer
          • Go to step: Loop back to “Send Message to OpenAI thread” step (Step 5 above)
        • Else Branch:
          • Message step: Let the customer know that you’re sending them to an agent.
          • Assign Agent step: Assign the conversation to an agent

Final Steps

Send a test message to your support number to ensure the flow triggers correctly and the GPT responses are accurate. Also, take into account the real conversation your users might have and adjust the GPT prompt and knowledge base accordingly to improve the responses.

Have more questions? Get in touch

Start free trial