Endless FAQs on WhatsApp With Generative AI and AI Studio

Using Generative AI to Improve Customer Experience

In 2023, Generative Artificial Intelligence (AI) and Large Language Models (LLMs) exploded on the scene, with the promise to completely transform the world. According to SimilarWeb, in just 2 months ChatGPT reached 100 million users. By comparison, it took TikTok 9 months and Instagram 2 years to achieve the feat.

But what is the significance of this booming technology? I’ve always heard that the best developers are lazy developers. I confess I’m a lazy developer. Generative AI helps us be even lazier! Not only can we ask for refactored code or even wholly coded applications from this predictive AI. But we can outsource the other annoying parts of our applications, like all the data values we want to give our users.

Using Generative AI with another tool for lazy efficient developers, Vonage’s low code platform called AI Studio, you can now improve your customer experience exponentially. In this article, you will learn how to replace your company’s Frequently Asked Questions (FAQ) site and turn it into a flexible, comprehensive FAQ WhatsApp agent (also known as a chatbot).

TLDR; If you don’t want to build out the Agent, you can copy the ZIP file and import it to AI Studio following these instructions. You’ll still need to do the Generative AI setup

Mission: Turning Static FAQs into an Interactive WhatsApp Agent

Our mission in this article will be to turn an FAQ site into a WhatsApp Agent. We will use AI Studio’s own FAQ site and turn it into an agent.

You will notice that this site not only contains the traditional FAQ question-and-answer format but also tells users that for any unanswered questions, they can email support@api.vonage.com. This is important in a Generative AI agent as the user’s intent (more about AI Studio Intents) is not to receive an answer here but rather to trigger some action. We call these action phrases. Action phrases can be things like emailing support, connecting users with a human agent, filling an order, and more! With AI Studio’s webhook node you are really empowered to build advanced integrations.

I always suggest starting with a mockup of the agent we want to build. This is how our agent would look if we wanted to build without the new Generative AI node:

You will notice that we must create an intent not just for each action phrase that we will listen for but also for each FAQ question and answer pairing. But we are lazy builders and this would take so long!

Thank goodness with the Generative AI node we can simplify our agent drastically. Now our mockup looks like this:

Notice that now our Generative AI node will not only eliminate the need to define individual question/answer pairings but also handle intent classification! So in our final WhatsApp Agent, which will answer FAQ questions about AI Studio, we simply need to collect the user inquiry and send it to the Generative AI node which will either send back a Gen AI answer or route the inquiry to our email support action.

Prerequisites

  • In order to use the Generative AI node, you will need to set up a paid account directly with OpenAI. Sign up with OpenAI using this link and create an account.

  • You will need a Vonage Developer Account

Configuring Your Generative AI Account in AI Studio

To be able to follow this tutorial you will need to make sure to have your AI Studio account up to date with the latest Generative AI integration instructions. Follow these instructions.

How to Create an AI Studio WhatsApp Agent

To begin we’ll need to create a WhatsApp agent. You can open AI Studio from inside the Vonage Developer Dashboard and then follow the instructions found in the AI Studio documentation. There are three important options for our agent, to select:

  • Type: WhatsApp

  • Template: Start From Scratch

  • Event: Inbound

How to Use the Collect User Input Node

  1. Let's greet our users with a welcome message. Let’s use the Send Message node. I like to attach a photo to our welcome message to use our company branding.

  2. Next, we'll accept our user's response with a Collect Input node. We’ll store the response in a parameter called INQUIRY. The expected input should be only text.

Unless otherwise specified, all parameters in this blog post will use the @sys.any entity. For more information about entities (different types of parameters) in AI Studio, please read the documentation.

Now that we have the user’s inquiry, we’re all set to start using our Generative AI node!

How to Use the AI Studio Generative AI Node

First, let’s select the Generative AI node from the Integrations section like so:

Add Picture

The configuration for our node will be:

  • OpenAI integration: Select your OpenAI Key (see Prerequisites)

  • User Input Parameter: INQUIRY

  • Organization Name: Vonage AI Studio

    • This helps the LLM better understand who it’s talking about so it doesn’t get confused with similarly named organizations.

  • Knowledge Base Description (KBD):

    • Here we will add all of the information from the FAQ site on the AI Studio site with a little bit of “massaging”.

Massaging Your KBD

On an FAQ site you might see something like:

I have a cool feature idea - how can I let you know about it? You can let us know about your feature idea directly on the AI Studio by clicking on the question mark button on the top right.

When added to the KBD, it should be able to stand alone and be declarative:

If you want to let us know about a feature idea, you can submit feedback directly on the AI Studio by clicking on the question mark button on the top right.

Additionally, to help the LLM better answer questions, we’ve pulled a bit of general information from our homepage:

Vonage AI Studio is a conversational AI platform built to handle complex interactions between businesses and customers, lowering operational costs and significantly improving service levels

KBD Character Limits

Note that the Knowledge Base Description has a limit of 6000 characters. If that is not enough you can create more focused flows with more specific intents and more specific Knowledge Base Descriptions.

  • Output Parameter: GEN_AI_ANSWER

    • Create a new parameter to hold the response we receive from the LLM

For now, we will skip the Actions tab and leave it blank. Open the Configurations tab and set it to look like this

  • Creativity Level: None

    • The temperature reflects how much the model will go outside of the KBD and pull information from the internet for its answers. Experiment with this knob until you find a comfortable setting.

  • Timeout: 10 seconds

    • The timeout refers to the amount of time that the agent will wait to receive an answer from the LLM. Longer answers may take a longer response time but also your user may get impatient and begin typing messages to the agent which may cause it to error.

  • Output Parameter: GEN_AI_ANSWER

    • Create a new parameter to hold the response we receive from the LLM

When you’ve filled it all out, your node should look like this:

Click “Save & Exit” and our agent is ready to send questions and receive answers from OpenAI.

How to Handle Our Generative AI Response

Now that we’ve hooked up our node to get FAQ answers, let’s send them to our users! The whole flow will look like this:

This may look kind of complicated but most of it is error handling and improving the user experience. The Generative AI node creates 4 exit points: INQUIRY (success), Fallback, Conversation Ended, and Failed. These exit points provide us with some error handling depending on the result we get back from Open AI. And the rest of the nodes allow our users to keep asking questions until they are satisfied.

To build it out:

  1. For INQUIRY exit point:

    Use a Send Message node and have it simply send $GEN_AI_ANSWER. Connect our Inquiry exit point to this node.

  2. For Fallback exit point:

    Use a Send Message node and have it send an error message. Something like "Uh oh, we weren't able to find an answer to that. Let's try again.” Connect our Fallback exit point to this node. And from this node connect back to the Collect Inquiry node we made before. This will allow the user to ask again.

    • A Fallback exit point occurs when the Generative AI is unable to answer the question

  3. For Conversation Ended exit point:

    Use an End Conversation node and connect our Conversation Ended exit point to this node.

    • A Conversation Ended occurs when Gen AI node recognizes that either the end-user or GPT has ended the conversation

  4. For Failed exit point:

    Use a Send Message node and have it send an error message. Something like "Oops! There was a problem. Let's try again.” Connect our Failed exit point to this node. And from this node connect back to the Collect Inquiry node we made before. This will allow the user to ask again.

    • A Failed exit point refers to an API error or timeout

  5. We want to allow the user to ask multiple questions of our chatbot. So now create a Collect Input node called Collect Repeat that will save a new Parameter called REPEAT. The node will receive Reply Button inputs. One button should have a title Yes and value of true. The other button should have a title of No and a value of false.

  6. Now we’ll use a Condition Node which will check against REPEAT. Create one condition to check if REPEAT is equal to true, and another to check if REPEAT is equal to false. Connect the true condition again to the Collect Inquiry node, the first collect input node we used.

  7. So that our users know the flow is over and our agent is “asleep”, let’s create one final Send Message node with a simple Goodbye Message, “Thanks for using AI Studio!” Connect our false condition to this node.

  8. Connect the false condition to an End Conversation node.

You can now test your agent and ask it questions!

How to Use the Send Email Node in AI Studio

Let’s implement the Email Support flow now. Remember when we skipped the actions tab in the Gen AI node? We can go back and set that up now. All we need to do is add our action phrase! So it should look like this:

Without having to define any user intents, our Generative AI node uses this action phrase along with the knowledge base to understand our users. Amazing!

Next, we’re going to need 2 additional pieces of information from the user before we can use the Send Email node:

  • Collect User Email

    • Using a Collect Input node ask the user for their email address

      • E.g. “Great! Can I have your email address?”

    • Store it inside a new Parameter USER_EMAIL

    • Set this parameter to @sys.email so that AI Studio will only accept valid email addresses

  • Collect User Question

    • Using a Collect Input node ask the user for the question that was unanswerable by the agent

      • E.g. “Great! Please explain the question you have and I'll pass it along to support 💌”

    • Store it inside a new Parameter EMAIL_INQUIRY

Now we are ready for the Send Email node. The configuration for our node will be:

  • To: support[at]api.vonage.com

    • Make sure to hit enter so that the address is saved, it should turn into a grey block

    • You can add more than one email recipient

  • Subject: New FAQ Agent Question: $PROFILE_NAME

    • $PROFILE_NAME is a System Parameter that allows us to access the user’s profile name they set in WhatsApp. Note: not everyone uses their real name as a profile name.

  • Body:

Contact Info:

  • Respondent Name: $PROFILE_NAME

  • Respondent Phone Number: $SENDER_PHONE_NUMBER

  • Respondent Email: $USER_EMAIL

User Submitted Question:

$EMAIL_INQUIRY

Conversation Time:

$CONVERSATION_START_TIME

Your node should look like this:

Now we can connect our Email Support node to the Collect Repeat node. This allows our user to ask more questions or end the conversation.

And that’s it! Our agent is fully built!

Conclusion

👏Give yourself a round of applause! You did it! You built your first Generative AI WhatsApp agent. Now let’s test using the built-in tester.

Does your classification node work? Is your agent able to differentiate when you want to send an email or ask a question about AI Studio? Try asking questions directly from the FAQ site and seeing how the answers compare. Then maybe try asking your agent questions that deviate a bit from the FAQ. And then questions that are entirely not apart of the training data!

How does your agent behave? Let me know! Join the Vonage Developer Community Slack and tell me what your building in the #ai-studio channel. Or find me on X, formerly known as Twitter. And give VonageDev a follow while you’re at it.

Last updated