Sup fam. I’m talking about a WhatsApp bot that chats like a real person, that can push a conversation back and forth the same way you do. There are many applications for something like this. You can employ the bot to answer customer enquiries, use it as an interface for any kind of documentation, use it as an in-house company AI assistant, or as a recruiting agent that interviews job applicants by chatting with them; the list goes on.

Use Case for the Demo

For this demo, let’s do a simple chatbot just to show you the ropes. We’ll develop an AI WhatsApp bot that replies to customer enquiries. The common problem for companies that have a customer enquiries desk is they get overwhelmed with too many enquiries.

It’s hard for them to scale their marketing efforts without creating a crowd of people that will drown the customer enquiries desk. An AI-powered WhatsApp chatbot like the one we’ll develop here solves that problem. It can instantly respond to hundreds of people simultaneously and works 24/7.

Our example: let’s say there’s a dojo called KarateKiddos that teaches kids self-defence and martial arts. The dojo runs ads on Facebook and their call to action is “Contact Us on Whatsapp to Book a Class”. Their WhatsApp number is actually a chatbot number. We’re developing that bot in this demo.

All the interested people will chat with the WhatsApp bot. The bot will chat to qualify them to see if they’re legitimately able to attend a class. It’ll ask about the age of the kid, whether the kid has done any martial arts before if the kid has any physical abnormalities/inabilities if there is a parent/guardian that can provide medical attention for the kid in case of accidents.

To develop this we’ll need a LLM model, a chatbot builder and a phone number that is not linked to any existing WhatsApp account. For the LLM model, there are lots of options but we’ll use our good old OpenAI. And the chatbot builder we’ll use is Botpress. What we want to accomplish in a single sentence is this; create an AI assistant in OpenAI, link it to Botpress, and then link Botpress to WhatsApp. Create accounts on these platforms if you haven’t already. Let’s go.

Step 1

Let’s start with the AI assistant.  Go to platform.openai.com, and create an assistant. At the time of writing this, the model GPT-4o performs well enough, choose that one (models will get upgraded and will become better with time, if there’s a better upgrade capitalise on it). The more specific you are and the more details you give it, the better the AI assistant will be.

The best way to write prompts for assistants is to first draft all the kinds of people who would chat with it. For our dojo case, here’s my outline of potential client avatars.

  • People with kids that are over-age(+16years) and under-age (<6years)
  • People with injured and/or physically disabled kids.
  • Curious people, who have no kids but want information.
  • Spammers.
  • Kids acting on their own.
  • People with kids that need special attention.
  • People who want to reschedule/cancel their booking.
  • People with healthy kids who are eligible (ideal clients)

You can use ChatGPT to help you come up with more personas. Make sure there’s a portion in the prompt that tells the assistant how to respond to each kind of person. If you want to check out the entire prompt for the assistant we’re using for this demo, download the document here. Test the assistant in OpenAI’s playground until you’re satisfied and have verified that it’s responding the way you want it to.

Step 2

Let’s attach the assistant to Botpress. Manually attaching the assistant to Botpress is a little intimidating if you don’t know the code and its logic of extracting messages from OpenAI assistants’ threads. So to make life easy for you, I’ll give you a template you can just import into Botpress Studio. Download the Botpress template here (it’s in the zip file)and import it into Botpress Studio. Using this template, all the work to attach the assistant is reduced to only copying and pasting the assistant ID and OpenAI API key from OpenAI to Botpress bot settings. So do just that.

Step 3

This is the most intimidating part of all, attaching Botpress to WhatsApp. So I’ll break it down into sub-steps.

A little heads-up here: The Meta Developers dashboard changes user flows every time they add a new feature or do updates, so the steps shown here may become inaccurate if Meta decides to change/update something, but nevertheless, the overall procedure remains the same.

Sub-step 3.1: Create an app in Meta

WhatsApp is a Meta application so we only get to play super-admin for it in Meta for Developers. Go to developers.facebook.com and sign up/log in. Create a new application.

Sub-step 3.2: Configure the app

You’ll go through a series of screens asking you to choose a business portfolio, use case template, type and app details. The portfolio is optional but choose one so you get access to your business data later. Choose ‘Other’ on the template screen and ‘Business’ on the type screen. On the ‘details’ screen, you get to give your bot a name so call it whatever you like. I’m calling it ‘ArtRiver Assistant’.

Sup-step 3.3: Setup WhatsApp in your Meta App

The app is created but it’s just a skeleton with nothing on it. Meta already has a WhatsApp integration template, all we have to do is set it up in our app. Scroll on your app dashboard and you’ll see the WhatsApp integration there. Click ‘Set up’ and on the next screen choose your portfolio and click ‘Continue’.

Sub-step 3.4: Create a system user for the app

Access tokens are used to create secure connections between different applications. We want to connect our app to Botpress. Meta created our app assuming that we still want to develop it so the default access token is temporary. It only lasts 24 hours before it expires. That is why we have to create a permanent access token manually. Meta only allows the generation of permanent access tokens from a system user, so we have to create a system user first and then give that system user admin privileges over our app. Then we generate the access token.

Let’s do just that. Go back to developer.facebook.com and navigate to ‘My Apps’. The app we just created will be listed there and there’s a link to your business portfolio on it. Click that link. On the Business portfolio page, navigate to ‘System users’ and then click ‘Add’.  On the pop-up that appears name your system user and give it the ‘admin’ role. I named mine ‘ArtRIverMaphose’.

Sub-step 3.5: Assign the app to the system user and grant permissions

After creating the system user, we have to assign our app to it and give ‘Manage app’ permissions. Edit info on the system user, select your app and toggle on the ‘Manage App’ as shown below and save.

Sub-step 3.6: Generate permanent access token

Click on ‘Generate token’ and a pop-up will show up. Select your app and hit ‘Next’. For the expiration select ’60 days’. There is an option of having the access token never expire. That option is only convenient in a perfect world where there is no risk of getting hacked or exploited. So put it at 60 days so that you renew it every 2 months. That’s more work but it buys you more digital security for your app/business.

For the permissions, assign the whatsapp_business_management and whatsapp_business_messaging only. Then generate your token. Meta will show you this access token once, so save it somewhere safe.

Sub-step 3.7: Add a phone number

If you use WhatsApp, you know you need someone’s phone number to chat with them. Our bot also needs a phone number so people can chat with it. Meta gives us a test phone number for testing and development-stage purposes but our app is not that complex, it is as good for production use at this point. So we need a production-stage phone number that will be used by our bot. You can use an old SIM card you don’t use on WA or you can get a new SIM card. I got a new SIM card for this. Put the SIM card in a phone that can receive SMS messages, we’ll need that for verification.

Go to your app’s dashboard in Meta, and click on ‘API setup’. On the ‘Send and receive messages’ tab, there’s an option to add a new phone number. Go to that option and follow the instructions on the pop-up screens to add your phone number. The last screen will require that you verify the phone number. Use the SMS method, it is the easiest. And boom, we have a production-level bot phone number. Copy the phone number ID, we’ll need it in the coming sub-steps.

Sub-step 3.8: Integrate with Botpress

Now that we have our access token and phone number ID, we can use that to plug our app into Botpress. So head back to Botpress Studio, on the left side there are many options, look for ‘Integrations’ and click that. The Botpress Integration Hub will pop up. There are lots of platforms Botpress supports and fortunately for us, WhatsApp is one of them. Look for the WhatsApp integration and install it. Switch on the ‘Use Manual Configuration’ toggle button.

Sub-step 3.9: Configure integration

Paste the access token and the phone number ID as shown below. The ‘Verify Token’ can be your grandmother’s birthday or anything you want. Just put in something you’ll easily remember. I put in five zeros. Save the configuration. Copy the webhook URL in Botpress (if you don’t know webhooks, it’s ok. Just copy the URL address). Head over to your app dashboard in Meta, and go to the configuration page. Paste the webhook URL from Botpress and the same ‘Verify Token’ you wrote in Botpress, verify and save. On the same page, there is a list of subscription services. Find the ‘messages’ subscription and toggle it on.

Sub-step 3.10: Give Meta time to review your Bot number

Meta does not immediately let you use their API. They take a minimum of an hour and a max of 4 business days to approve your bot production number. So be ready to do some waiting. This is the last thing. Once the number is approved, the bot goes online and you can chat with it. Save its number in your phone and search for it in WA, say hi.

The bot we made in this demo is the one I’m playing with in the TikTok video embedded in this post.

We can develop an AI chatbot for your business

Of course, you know I was going to pitch our service. This demo was practically basic. There is a lot more that AI chatbots can do. Each business is different, so each may need a unique AI chatbot solution. An AI chatbot can train people, query/populate a database, recommend products/services, report accidents, book flights, order food, the list goes on.

 Save money and time. Collaborate with us to develop an AI chatbot for your business. Get started here.

Shares: