How to Build a WhatsApp AI Chatbot in Minutes Using Flowise

17.4k views3395 WordsCopy TextShare
Leon van Zyl
This has been a highly requested video. In this video you will learn how to create and integrate an ...
Video Transcript:
<b>Are you ready to bring your AI chatbot</b> <b>directly into WhatsApp? In</b> <b>this video, I'll show you how</b> <b>to build a no-code chatbot with Flowwise</b> <b>and seamlessly integrate</b> <b>it into WhatsApp for instant</b> <b>access. Today we're taking chatbot</b> <b>development to the next level by</b> <b>integrating it directly</b> <b>into WhatsApp.
Whether you need a single</b> <b>conversational bot or</b> <b>an advanced AI-driven</b> <b>solution, Flowwise makes it super easy. </b> <b>There's no coding required</b> <b>either. By the end of the video,</b> <b>you'll have a chatbot that not only</b> <b>integrates into WhatsApp but also</b> <b>remembers past conversations</b> <b>and allows you to monitor interactions</b> <b>for continuous</b> <b>improvement.
Let's get started. </b> <b>There are two ways in which you can</b> <b>access Flowwise in the</b> <b>cloud. The first option is to</b> <b>sell flowwise and I've already created a</b> <b>video on deploying Flowwise to Reindeer,</b> <b>and you'll find a link to that video in</b> <b>the description.
</b> <b>Alternatively, you can sign up</b> <b>for Flowwise Cloud. This is a paid</b> <b>service, but if you sign up now, you will</b> <b>receive a free trial</b> <b>period. And if you use the link in the</b> <b>description, you will be</b> <b>supporting my channel as I will</b> <b>receive a small commission.
After</b> <b>clicking my referral link, you will be</b> <b>taken to this sign-up</b> <b>screen over here. Simply sign up with</b> <b>GitHub, Google, or your</b> <b>email address. There will be a</b> <b>short wait for your instance to spin up,</b> <b>but afterwards you will</b> <b>receive access to the Flowwise</b> <b>dashboard.
If you're new to Flowwise, you</b> <b>can use it to create all</b> <b>sorts of AI applications,</b> <b>whether you want to create simple</b> <b>conversational chatbots or advanced</b> <b>multi-agent applications. </b> <b>So if you would like to learn more about</b> <b>Flowwise, then I highly recommend</b> <b>checking out my full</b> <b>Flowwise playlist on my channel. First</b> <b>things first, let's switch</b> <b>over to dark mode as this white</b> <b>background is blinding me.
Then under</b> <b>chatflows, let's click on add</b> <b>new. Let's then click on save. </b> <b>Let's give our flow a name, like WhatsApp</b> <b>chatbot.
We can use</b> <b>Flowwise to create some advanced</b> <b>chatbots, but for this tutorial, we'll</b> <b>just create a simple rag</b> <b>chatbot that can answer questions</b> <b>about our business. So for my business, I</b> <b>created this simple FAQ</b> <b>document in Word that simply</b> <b>contains questions and answers about my</b> <b>business. And what we want is</b> <b>to create a chatbot that will</b> <b>be able to answer questions about our</b> <b>business using rag.
Let's</b> <b>start by adding a new note to</b> <b>the canvas and let's add an agent. And</b> <b>under agents, let's add a</b> <b>tool agent. Let's add an AI</b> <b>model to this project by clicking on add</b> <b>notes.
Then under chat</b> <b>models, let's add the chat open</b> <b>AI node and let's connect this model to</b> <b>our tool agent, like so. For</b> <b>this chat open AI node, let's</b> <b>go ahead and select our open AI</b> <b>credentials. Then let's select our model</b> <b>by changing it to GPT</b> <b>40 mini and we'll change the temperature</b> <b>to 0.
7. We want our</b> <b>assistant to be able to recall</b> <b>information from the conversation history</b> <b>so that the user can ask follow up</b> <b>questions. For that to</b> <b>work, we need to add a memory node.
Let's</b> <b>go to add nodes, then under</b> <b>memory, let's add the buffer</b> <b>memory node and let's attach it to the</b> <b>tool agent as well. For the</b> <b>tool, we will add a retriever</b> <b>tool which will allow the agent to fetch</b> <b>information from a</b> <b>knowledge base. So under tools,</b> <b>let's add the retriever tool and let's</b> <b>attach this retriever tool</b> <b>to the tool agent as well.
</b> <b>Let's give the tool a name like</b> <b>restaurant info. For the description,</b> <b>let's say use this tool to</b> <b>fetch information about the restaurant. </b> <b>This retriever tool takes</b> <b>in a retriever as input.
</b> <b>So let's go to add nodes, then vector</b> <b>stores and let's add the in</b> <b>memory vector store and let's</b> <b>attach it to the retriever tool. Then</b> <b>this in memory vector store</b> <b>requires a document as well</b> <b>as an embeddings function. Let's start</b> <b>with the embeddings</b> <b>function.
So under add nodes,</b> <b>let's go to embeddings and let's add the</b> <b>open AI embedding node and</b> <b>let's attach it to the vector</b> <b>store. For the embeddings node, let's</b> <b>also select our credentials and I'll</b> <b>leave the model as the</b> <b>default value. All we need to do now is</b> <b>to attach our knowledge base</b> <b>to this document input.
Now</b> <b>there are many different ways to add</b> <b>information to the vector store. First,</b> <b>under add nodes, you</b> <b>can go to document loaders and view all</b> <b>the different</b> <b>integration options over here. So</b> <b>you can add pdf documents, plain text,</b> <b>word documents, you can</b> <b>scrape websites, etc.
But what</b> <b>I prefer to do is to go back to the</b> <b>dashboard, then go to</b> <b>document stores, then let's create</b> <b>a new document store. Let's give it a</b> <b>name like oak and barrel. </b> <b>Let's click on add, then let's</b> <b>click on the document store that we just</b> <b>created.
Let's click on add document</b> <b>loader. Now I'll select</b> <b>the file on my pc, then under text</b> <b>splitters, let's select the recursive</b> <b>character text splitter. </b> <b>Let's change the chunk size to something</b> <b>like 400 with a chunk</b> <b>overlap of 50 and let's click on</b> <b>preview chunks.
Right, and we can see</b> <b>that the document was</b> <b>chunked into 13 smaller documents. </b> <b>Let's go ahead and process this. </b> <b>Fantastic!
We now have a super simple way</b> <b>to manage our knowledge</b> <b>base. If we wanted, we could add</b> <b>additional document</b> <b>loaders to this document store,</b> <b>but this is all I need for now. Let's go</b> <b>back to chat flows, let's</b> <b>open up our chatbot, then let's</b> <b>go to add nodes, document loaders, and</b> <b>let's add the document store</b> <b>node.
We can then select the</b> <b>document store that we just created, and</b> <b>let's attach this document</b> <b>store node to the vector store. </b> <b>Great! We're actually done with our</b> <b>chatbot.
Let's save it. After saving the</b> <b>flow, you will notice</b> <b>this green button will appear, and this</b> <b>will allow us to upsell the</b> <b>data from that document store</b> <b>into our vector database. We only have to</b> <b>execute this once.
Let's</b> <b>click on upsell, and we can see</b> <b>that the 13 records from the document</b> <b>store were now loaded into</b> <b>our in-memory vector store. We</b> <b>can now test out our chat, so let's ask</b> <b>it something about the</b> <b>business, like what are your</b> <b>specials? And we do get this response</b> <b>back, and we can see that</b> <b>there is the round info tool was</b> <b>indeed used to retrieve that context.
Now</b> <b>that we have an awesome</b> <b>chatbot that we can run with</b> <b>inflow-wise, we now want to move on and</b> <b>integrate this chatbot into</b> <b>WhatsApp. That's why you came</b> <b>here after all. So let's go over to</b> <b>developers.
facebook. com, and</b> <b>let's click on My Apps. You</b> <b>will need to sign in with a Facebook</b> <b>account, and afterwards you should see a</b> <b>dashboard similar to</b> <b>this.
Let's start by creating a new app. </b> <b>On this screen, you will be</b> <b>asked to select a business</b> <b>portfolio. When this is your first time</b> <b>running through this</b> <b>process, you won't have any business</b> <b>portfolios in this list.
But in order to</b> <b>use WhatsApp with this</b> <b>application, we do need to</b> <b>create a business portfolio. You might</b> <b>see a link on the screen</b> <b>that will allow you to create a</b> <b>business portfolio, but if you don't see</b> <b>anything like that, then you can go over</b> <b>to business. facebook.
com,</b> <b>and on the left hand side, click on this</b> <b>drop down, and then click on</b> <b>Create a Business Portfolio. </b> <b>After you've created a business</b> <b>portfolio, you can simply refresh this</b> <b>page, and you should see your</b> <b>business portfolio show up in this list. </b> <b>Then select your business</b> <b>portfolio, and click on Next.
</b> <b>On this screen, let's click on Other, and</b> <b>let's click on Next. On</b> <b>this screen, let's click on</b> <b>Business, which will give us access to</b> <b>WhatsApp. Let's click on</b> <b>Next.
Let's give our app a name,</b> <b>like Flow-wise Chatbot, enter your email</b> <b>address, and again, select</b> <b>your business portfolio. Let's</b> <b>click on Create App. Great, we're making</b> <b>good progress.
On this</b> <b>screen, find WhatsApp, and click</b> <b>on Set Up. From this screen, you can</b> <b>either click on Start Using the API, or</b> <b>on the left hand side,</b> <b>click on API Setup. This screen might</b> <b>look intimidating, but I</b> <b>promise you, it's not that</b> <b>bad.
We will use this access token in a</b> <b>minute, but when we scroll</b> <b>down, we can see a From number,</b> <b>as well as a To number. The From number</b> <b>is the mobile number that</b> <b>your users will see when they</b> <b>receive messages from your chatbot. Then</b> <b>the To number is a test</b> <b>number which we can use while</b> <b>building this application.
Initially,</b> <b>when you click on this drop down, you</b> <b>won't see any numbers</b> <b>here, and to add your number, simply</b> <b>click on Manage Find Number List. Then</b> <b>enter your phone number,</b> <b>and then the rest of the process is quite</b> <b>simple. Once you've added your number,</b> <b>simply select it from this list, and if</b> <b>you click on Send</b> <b>Message, you should receive this</b> <b>Hello World message to WhatsApp,</b> <b>indicating that it is working.
But of</b> <b>course, if we send a reply,</b> <b>nothing will happen. Now let's have a</b> <b>look at how we can</b> <b>receive messages from the user,</b> <b>and send responses back to the user as</b> <b>well. For this, we will use</b> <b>Make.
com. You will find the</b> <b>link to Make. com in the description of</b> <b>this video, and if you</b> <b>use that link, you will be</b> <b>supporting my channel as well.
We will</b> <b>use Make. com to effectively</b> <b>glue Flowwise and WhatsApp</b> <b>together. Go ahead and sign up for a new</b> <b>account, or log in.
After</b> <b>signing in, click on Scenarios,</b> <b>then click on Create a New Scenario. Then</b> <b>let's add a new app by searching for</b> <b>WhatsApp Business Cloud, and let's select</b> <b>Watch Events. From the</b> <b>webhook, let's click on Add.
</b> <b>Let's give our webhook a name. I'll just</b> <b>call mine Flowwise YouTube Tutorial. </b> <b>Then under Connection, click on Add.
Then</b> <b>give your connection a</b> <b>name. Again, I'll just call</b> <b>mine Flowwise YouTube Tutorial. Then for</b> <b>the permanent token, go</b> <b>back to Meta, then copy the</b> <b>temporary access token, and paste it into</b> <b>this field.
Then for the WhatsApp</b> <b>Business Account ID,</b> <b>let's copy the WhatsApp Business Account</b> <b>ID from over here. And</b> <b>let's paste it into Make. Let's</b> <b>save this.
Let's also enter a verify</b> <b>token, and this can be</b> <b>anything you want. I'll just call</b> <b>mine Flowwise. Under Events, let's listen</b> <b>for messages, and let's</b> <b>click on Save.
Now let's</b> <b>copy this webhook that was generated, and</b> <b>let's go back to Meta. Then</b> <b>let's click on Configuration. </b> <b>Within Configuration, we can now paste in</b> <b>that webhook URL, and</b> <b>let's enter the verify token,</b> <b>which I called Flowwise.
And then let's</b> <b>click on Verify and Save. </b> <b>Within the webhook fields,</b> <b>scroll down to Messages, and enable this</b> <b>toggle over here. This is</b> <b>all we have to do to start</b> <b>receiving messages from WhatsApp.
Let's</b> <b>go back to Make. com. Let's</b> <b>click on Run Once.
Make is now</b> <b>listening for messages from WhatsApp. So</b> <b>let's go back to WhatsApp,</b> <b>and let's send any message. </b> <b>I'll just send Hello.
And if we go back</b> <b>to Make, we can see that we</b> <b>received the message. And if</b> <b>we go to Messages, and let's scroll down</b> <b>within Messages, let's</b> <b>click on Text, and here we can</b> <b>see the message Hello. Now that we're</b> <b>receiving messages from</b> <b>WhatsApp, we can now do a whole</b> <b>bunch of cool stuff.
As an example, let's</b> <b>send a hard coded response</b> <b>back by adding a new module. </b> <b>Let's click on WhatsApp Business Cloud,</b> <b>and let's click on Send a</b> <b>Message. Select the connection</b> <b>that you created earlier.
And for the</b> <b>sender ID, we'll select the test number. </b> <b>And for the receiver,</b> <b>let's click on Messages. And let's add</b> <b>the sender phone number.
</b> <b>Let's scroll down. And for the</b> <b>message type, let's select Text. And for</b> <b>the body, I'll simply enter Hi, how are</b> <b>you?
Let's save this. </b> <b>Let's click on Run Once. Then back in</b> <b>WhatsApp, let's send Hi.
</b> <b>And look at that. We received</b> <b>the response from Make. Great.
Now what</b> <b>we want to do is pass the</b> <b>message from the user to our</b> <b>FlowWise chatbot, this guy over here, and</b> <b>then take the response off</b> <b>the chatbot and send it back to</b> <b>the user. Thankfully, FlowWise makes it</b> <b>incredibly easy to integrate</b> <b>with these chatbots. When we</b> <b>click on this API endpoint button, we can</b> <b>see many different integration options</b> <b>over here.
What we're</b> <b>interested in is this curl option over</b> <b>here, which gives us</b> <b>this URL and some additional</b> <b>parameters. Let's copy the URL. So it's</b> <b>everything from HTTP up until</b> <b>the end of these characters.
</b> <b>And in Make, let's add a new module. So</b> <b>let's click on Add a Module. </b> <b>And let's search for the HTTP</b> <b>module, which will allow us to call the</b> <b>FlowWise endpoint.
Under HTTP, let's</b> <b>select Make a Request. </b> <b>And let's paste in that FlowWise URL. </b> <b>Let's change the method to</b> <b>Post.
Let's also add a header. </b> <b>And we can see exactly which values to</b> <b>pass in by copying this</b> <b>header value over here,</b> <b>which is Content Type. And for the value,</b> <b>let's also copy this</b> <b>Application JSON section</b> <b>and add it over here.
Now for the body</b> <b>type, let's select</b> <b>Raw. For the Content Type,</b> <b>let's select Application JSON. And for</b> <b>the request content, we</b> <b>can actually copy the example</b> <b>provided by FlowWise, like so.
And let's</b> <b>paste it into this field. </b> <b>This is simply a property called</b> <b>Question with a value of, hey, how are</b> <b>you? Now, obviously, we</b> <b>don't want to hardcode this value</b> <b>over here, but instead we want to pass in</b> <b>whichever message the user sent.
So on</b> <b>the left, let's click</b> <b>on Messages. Let's open up text. And</b> <b>let's add this body value over here.
And</b> <b>be sure to add these</b> <b>within these double quotes. Let's click</b> <b>on OK. Let's test this out.
</b> <b>So I'm going to click on Run</b> <b>once. In WhatsApp, let's say, hey. And</b> <b>back in Make, we can see</b> <b>that this FlowWise executed</b> <b>successfully.
And if we look at the</b> <b>response from the HTTP</b> <b>module, we can see in the output,</b> <b>this data structure with the text, hello,</b> <b>how can I assist you today? </b> <b>And a whole lot of other data</b> <b>as well. Also, if we go back to FlowWise</b> <b>and under Settings, if</b> <b>we go to View Messages,</b> <b>we can also see the conversation that was</b> <b>just sent to FlowWise.
Now</b> <b>let's see how we can pass</b> <b>this response from the AI model back to</b> <b>the user via WhatsApp. Now,</b> <b>of course, we could open the</b> <b>WhatsApp module and simply grab that</b> <b>output from the model. So</b> <b>instead of this hardcoded value,</b> <b>let's go to the HTTP output.
Let's go to</b> <b>data. In fact, let's add</b> <b>this data value over here. Let's</b> <b>click on OK.
Let's click on Run once. </b> <b>Back in WhatsApp, let's</b> <b>say, hey, again. And we do get</b> <b>a response back.
But this is really not</b> <b>very helpful. All we</b> <b>want is the value of text,</b> <b>not all this other crap as well. Now,</b> <b>unfortunately, this</b> <b>data value is this long,</b> <b>messy string of values.
And all we really</b> <b>want is the value of text. </b> <b>So what we need to do is take</b> <b>the string value and pass it into a</b> <b>structure where we can</b> <b>selectively grab the values that we</b> <b>need. Let's select Add a Module.
Let's go</b> <b>to JSON. And let's select</b> <b>parse JSON. Now, for the JSON</b> <b>string, we can actually add this data</b> <b>value.
And this one, I'll split the</b> <b>string up into properties</b> <b>that we can use. Let's click on OK. So</b> <b>let's run this again.
I'll</b> <b>just say, hey, again. Now,</b> <b>if we have a look at the output of this</b> <b>JSON module, we can see</b> <b>that we now have these</b> <b>individual values coming through. So</b> <b>we've got text, the</b> <b>message ID, et cetera.
So now,</b> <b>in the WhatsApp Business Cloud module,</b> <b>all we need to do is I'm</b> <b>actually going to delete this data</b> <b>entry over here. And now from the JSON</b> <b>parse module, we can add</b> <b>the text, like so. Let's give</b> <b>this a spin.
Let's click on Run once. And</b> <b>this time, we should receive</b> <b>a proper message. Let's say</b> <b>hello.
And look at that. We now get the</b> <b>AI's response back. </b> <b>However, we can still greatly</b> <b>improve this chatbot by adding memory to</b> <b>it as well as a</b> <b>personality.
But first, if you do enjoy</b> <b>this video, then please hit the Like</b> <b>button and consider</b> <b>subscribing to my channel for more</b> <b>Flow-wise content. Let's ask a question</b> <b>about our business. What</b> <b>are the current specials?
</b> <b>And of course, I shouldn't forget to</b> <b>click on Run once. I'll</b> <b>just select Use Existing Data,</b> <b>and we do get a response back. So our RAG</b> <b>chatbot is definitely</b> <b>working.
Now, let's have a look at</b> <b>adding conversation memory to this</b> <b>chatbot. If I say something like, my name</b> <b>is Leon, we do receive</b> <b>a response. But if I didn't ask it, what</b> <b>is my name?
Our chatbot</b> <b>will tell us that it actually</b> <b>does not know our name. And that is</b> <b>because it's got no view of the</b> <b>conversation history. Thankfully,</b> <b>this is super easy to set up as well.
So</b> <b>what we can do is use the</b> <b>user's phone number to uniquely</b> <b>identify that user and then return all</b> <b>the previous messages</b> <b>that were sent by that user. </b> <b>That way, the chatbot will be able to</b> <b>answer follow-up questions</b> <b>and recall information about</b> <b>the user. This is really simple to set</b> <b>up.
Let's double-click on the HTTP</b> <b>module. And in the request</b> <b>content, let's add a few more things. I'm</b> <b>just going to move these</b> <b>curly braces.
And at the end</b> <b>of question, let's enter comma and below</b> <b>question, let's enter</b> <b>override config, then colon, then</b> <b>opening and closing curly braces, and</b> <b>then a property called</b> <b>session ID colon. And now we can</b> <b>specify a unique ID for this user. And we</b> <b>can use the user's phone</b> <b>number for this.
So under</b> <b>messages, let's add the sender number</b> <b>like so. And let's click</b> <b>on OK. Right.
Let's click on</b> <b>run once. I'm actually going to clear</b> <b>this chat and let's see if our memory</b> <b>works. First, I'll say,</b> <b>hey, we do get a response back.
Let's</b> <b>say, my name is Leon. And now let's ask</b> <b>it, what is my name? </b> <b>And look at that.
Our chatbot remembered</b> <b>my name. And of course,</b> <b>if we go back to flow wise</b> <b>and view messages, we will be able to</b> <b>view the conversations that</b> <b>are linked to the user's phone</b> <b>numbers. Now that our chatbot is working,</b> <b>we can go to make and turn</b> <b>on scheduling.
And we can set</b> <b>it to immediately as data arrives. Now we</b> <b>don't have to click on run</b> <b>once every time we want to</b> <b>chat to our chatbot. Let's also save</b> <b>this.
Then let's test this out by</b> <b>sending, hey, and I get a</b> <b>response back immediately. Fantastic. </b> <b>Another improvement we can</b> <b>make to our chatbot is to go</b> <b>back to flow wise.
And within the tool</b> <b>agent, we can click on additional</b> <b>parameters. Here we can</b> <b>set the behavior of our model. Like let's</b> <b>give it a name.
Something</b> <b>like your name is Max. You work</b> <b>as a customer support agent for a</b> <b>restaurant called Oak and Barrel. And</b> <b>just for fun, let's say</b> <b>something like include the emojis in your</b> <b>responses.
Let's save</b> <b>this flow. And in WhatsApp,</b> <b>let's try this out. It's enter.
Do you</b> <b>sell steaks? And we get our response</b> <b>back, which also includes</b> <b>emojis. Wonderful.
Now at the moment, we</b> <b>are using a temporary access</b> <b>token within Meta. And this</b> <b>token will expire after 24 hours. Now I'm</b> <b>not going to cover the process of</b> <b>verifying your business</b> <b>on Meta, but there are plenty of other</b> <b>videos on YouTube that will take you</b> <b>through that process.
</b> <b>But I hope that you do find this video</b> <b>useful nonetheless, as</b> <b>these WhatsApp chatbots can be</b> <b>extremely valuable to yourself or your</b> <b>customers. If you want to</b> <b>learn how to build advanced,</b> <b>multi agent applications within flow</b> <b>wise, then check out</b> <b>this other video over here.
Copyright © 2024. Made with ♥ in London by YTScribe.com