1. Solutions
  2. Whatsapp AI Agent

Solutions

Whatsapp AI Agent

This guide shows you how to get up and running with the Whatsapp AI Agent from the library template.

1. Creating a template

Overview

The first step is to create a new template, and we're going to use a template from the prebuilt library.
This template is called Whatsapp Chat Assistant Conversation and it will allow you to build an AI agent that can interact with users on Whatsapp.

References :

Steps

  1. Navigate to the Editor

  2. Create a new template

    Click the add button button and then click Create new template

  3. Step 1c

    Create a new template

    Select Create from library create from library

  4. Step 1d

    Filter for Whatsapp

    Type in Whatsapp filter for whatsapp

  5. Step 1e

    Select item

    Select Whatsapp Chat Assistant Conversation

  6. Step 1f

    Add the template

    Click Add this item


Result

Once you have created the template you will be redirected to the template flow canvas in the Editor.
You should see a flow similar to the one below.

start canvas

2. Creating a Stub

Overview

The next step is to add a draft stub to the canvas so that you can test the template.

References :

Steps

  1. Step 2a

    Add a stub

    Click the Add Stub icon on the Navbar draft stub icon

  2. Step 2b

    Set the stub subject

    Type in test1 in the Subject field

  3. Step 2c

    Open the stub

    Click on the open stub icon to open the stub


Result

When you open the stub it will open in a new tab.
The stub is an instance of the template, so it will reflect the template's structure and actions.
You should see the stub opened in the chat-pending state.
The stub also has an indicator showing it is a draft stub, this means it is a testing stub created from the Editor application.

draft stub chat pending

You should get comfortable with switching between the Editor and Inbox applications.
Editor is where you build the template and Inbox is where you test the stubs.
You will need to switch between the two applications to build and test the interaction.

3. Testing the chat

Overview

We're now going to use the stub to test the chat with the AI agent on Whatsapp.
Remember a stub is a draft instance of the template and is used to test the interactions.
We can run actions on the stub by selecting them and then running them.
The start_chat action is going to start the test interaction.

Steps

  1. Step 3a

    Select the start chat action

    Click on the Start Chat action in the actions menu block on the stub. actions menu

  2. Step 3b

    Fill in the Whatsapp number

    Then fill in your cellphone number in the Whatsapp Number field.

  3. Step 3c

    Start the chat

    Click on the Start Chat button to start the chat. start chat


Result

You should now receive a message from the AI agent on Whatsapp.

NOTE

The first message on Whatsapp will be an "Interaction Request" message. It can take up to a minute to arrive on first use. You will be asked to "Allow" the interaction.

This message originates from the draft stub.
All your interactions with the AI Agent will show up on the Stub which keeps the full conversation history and state.
You can reply to the AI Agent from Whatsapp and the conversation will continue.
This is the first step to building the interaction.
Test the conversation and see how the AI Agent responds.
See the conversation history update on the stub page.

4. Customize the prompts

Overview

LLM models get given instructions via what are called prompts.
Now that we have tested the chat on Whatsapp we're going to customize the prompts that the AI Agent uses.
This allows us to change the personality and style of the AI Agent.
It allows us to given specific instructions for tasks.
It also allows us to give the AI a role and persona.

In order to customize the prompts we need to switch back to the Editor application, this should still be open on a tab on your browser.

Steps

  1. Step 4a

    Edit the prompt

    Click on the edit icon on the prompt called prompts.job_details. canvas job prompt

  2. Step 4b

    Edit the prompt

    Copy this sample prompt text : You work for the Green Ball Circus. You have a fun and jolly attitude. You use emojis all the time. You should encourage people to attend the circus on Friday night. The show begins at 7pm. The show will include trapeze artists and a funny clown.

  3. Step 4c

    Paste into the prompt

    edit job prompt

  4. Step 4d

    Close the prompt editor

    Click the close icon

  5. Step 4e

    Create a new draft stub

    Create a new draft stub by clicking the Add Stub icon on the Navbar draft stub icon


Result

You should now be able to chat to the Circus Clown AI Agent on Whatsapp.
You may edit the prompt and add a new stub and test again as many times as you like.
The goal is to get a feel for how the AI Agent responds to different prompts.

Things you could try :

  • Prompt the AI Agent to be more formal
  • Prompt the AI to speak in a different language
  • Prompt the AI to be sarcastic

Have fun.

6. Adding an action for the AI

Overview

In this step we're going to add an action for the AI agent to use in the conversation.
An action allows the AI to do actual work in the conversation.
Actions are very powerful when combined in different states.
Each action can collect data, send notifications, or interact with other systems.

For this tutorial we're going to :

  • collect some information
  • send an email

Let's imagine that the AI agent can reserve tickets for the circus. We'd need to collect the person's name and the number of tickets they want to reserve.

Let's start with adding an action.

Steps

  1. Step 6a

    Add a new action

    Click the add action icon to add a new action to the canvas.

  2. Step 6b

    Name the action

    Name the action reserve_tickets.


Result

We now have an action that is unconnected to anything on the canvas.
We're going to link the action to the conversation state next.

new reserve tickets action

7. Make the action available

Overview

The next step is to make the reserve_tickets action available in the chat-in-progress state.
Actions are only available in the states that they are linked to.

Steps

  1. Step 7a

    Link the action to the state

    Drag from the chat-in-progress state icon on the state to the reserve_tickets action. make reserve tickets available


Result

link reserve tickets

We now have an action that is available in the state, but it is not yet enabled for the AI agent to use.
Every action in Stubber needs to be explicitly enabled for the AI agent to use.

8. Enable the action for the AI agent

Overview

The next step is to make the reserve_tickets action enabled for AI.
Stubber requires that each AI action be enabled before allowing an AI to be able to call it.

Steps

  1. Step 8a

    Edit the action

    Click the edit icon on the reserve_tickets action.

  2. Step 8b

    Navigate to the AI tab

    Click on the AI tab in the action editor. reserve tickets ai tab

  3. Step 8c

    Enable the action for the AI agent

    Click the AI Enabled toggle to enable the action for the AI agent. rerserve tickets ai enabled

Results

Great! Now the AI agent can use the reserve_tickets action in the conversation.

9. Adding fields to the action

Overview

In order for us to collect structured data from the AI agent we need to add fields to the reserve_tickets action.
Fields are the part of an action that facilitates the collection of data.
When the AI agent calls the reserve_tickets action, the action fields will indicate to the AI wha data to collect from the user.

Steps

  1. Step 9a

    switch to the Fields tab

    Click on the fields tab on the action editor. reserve tickets fields

  2. Step 9b

    Add a name field

    Click the Add Field button to add a new field to the action.

  3. Step 9c

    Search for a text field

    Type in text in the search field to find a text field. add text field

  4. Step 9d

    Add the text field

    Click Add this item to add the text field to the action.

  5. Step 9e

    Name the field

    Name the field customer_name. field customer name

  6. Step 9f

    Add a number of tickets field

    Click the Add Field button to again.

  7. Step 9g

    Search for a number field

    Type in text in the search field. add text field

  8. Step 9h

    Add the number field

    Click Add this item to add the text field to the action.

  9. Step 9i

    Name the field

    Name the field number_of_tickets. field number of tickets

Results

On the fields tab of the action editor you should now see the Action Preview. The resulting fields in a form should look like this: reserve ticket form

You should now be able to create a new stub and chat to the Circus Clown AI Agent on Whatsapp once more.

Things you can now try :

  • Ask the AI agent to reserve tickets for you
  • See how the AI collects the data from the fields you added

We've now allowed our agent to reserve tickets for the circus, by allowing it call the reserve_tickets action and collect the necessary data.

10. Adding a notification

Overview

Lastly we can add a notification to the action to send an email to the circus to reserve the tickets.
This is a simple way to show how you can integrate with other systems.
We can add a notification to the reserve_tickets action that will send an email to the circus with the details of the reservation.

We're going to use variable substitution to include the customer name and the number of tickets in the email body text.

Steps

  1. Step 10a

    Edit the action

    Click the edit icon on the reserve_tickets action.

  2. Step 10b

    Navigate to the Notifications tab

    Click on the Notifications tab in the action editor. reserve tickets notifications

  3. Step 10c

    Add an email notification

    Click the Add Notification button.

  4. Step 10d

    Search for email

    Type in email in the search field and find the Email to email address notification. email to email address

  5. Step 10e

    Add the email notification

    Click Add this item to add the Email to email address notification.

  6. Step 10f

    Name the notification

    Name the notification send_email_to_circus. email to email address

  7. Step 10g

    Configure the email notification

    Click on the edit icon on the send_email_to_circus notification. edit send email to circus

  8. Step 10h

    Set the destination email

    Click on the Send To tab.

  9. Step 10i

    Set the destination email

    Edit the value field under the Destination -> Value section to set the email to your email address. add destination email

  10. Step 10j

    Set the email body

    Start typing in the Message field. Type : Hi, {{ start email message

  11. Step 10k

    Select the customer name

    Type customer and select the stubpost.data.customer_name variable.

    select customer name

  12. Step 10l

    Add the number of tickets

    Type {{ and select the stubpost.data.number_of_tickets variable.

  13. Step 10m

    Complete the email message

    Set the final email message to look like this : Hi, {{stubpost.data.customer_name}}, you have reserved {{stubpost.data.number_of_tickets}} tickets for the circus.

  14. Results

    The final email message should look like this: email message complete

    We're now ready to create a new draft stub and test the full conversation with the AI agent.
    You should be able to chat to the agent and then reserve tickets for the circus.
    You should receive an email with the details of the reservation.

    Congratulations! You have now built a Whatsapp AI Agent that can reserve tickets for the circus.