How To Connect WhatsApp to N8N (Step-by-Step Tutorial) β
n8nRecentπ
2025-04-16
Integration Flow β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INTEGRATION ARCHITECTURE β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β USER REQUEST β
β β β
β βΌ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β βββββΊ β β βββββΊ β β β
β β WhatsApp β β OpenAI β β n8n β β
β β β βββββ β β βββββ β β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β β β
β β β β β
β ββββββββββββββββββββββββββ΄ββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββ β
β β RESULT β β
β βββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββIntegration Points β
- Core concepts explained
- Step-by-step implementation
- Practical examples
Transcript β
[00:00] Hey there. In this video, I'll show you how to add AI agents to WhatsApp using N8N. This agent is capable of processing text, images, as well as voice messages, and in turn, it can also respond with text and audio as well. Our agent also has access to plenty of tools like web search, a custom knowledge base containing our documents, and we can extend it even further using MCP servers. And just to show you what this server looks like, the server is calling
[00:31] additional workflows to generate content. It can read and send emails, and it can list and update our to-dos. Now, let's try this in WhatsApp. We can send basic text messages like, "Hello, how are you?" And of course, we get a friendly response back. Let's ask it, "What are my current list of to-dos?" Great. It used our tools to retrieve this list of to-do items. Let's try sending a voice note. Please could you email the list of to-do items to
[01:03] leonest.com. All right, so we get this response back. I've emailed your current to-do list to leonest.com. If you need anything else, feel free to ask. All right, so let's go to our email. Let's go to send items. Let's refresh this. So we can see this email over here. And this indeed lists all of our to-dos. and it was indeed sent to leon@test.com. Our agent can also process images. So, I'm going to upload an image like this doll over here. And
[01:34] let's ask what does the text on her shirt say? Let's send this. And how awesome is that? It says the text on the shirt says sweetie in bold black uppercase letters. Our agent also has access to real-time data using the web search tool. So we could ask it for real-time information like what is the latest news from open AI and our agent now used the web search tool to retrieve all of this information along with the citations. The sky is the limit with an agent like this and you can extend it as
[02:06] far as you want. So in this video I will show you how to use the WhatsApp trigger to connect your agent to WhatsApp and you will then learn how to process text, images and audio using N8N. You can also download this workflow for free using the link in the description of this video. Enough talk. Let's build this. In order to integrate our agent to WhatsApp, we will need to create a meta app. So go to developers.fas.com and sign into your
[02:37] account. Then click on my apps and from the screen click on create app. Let's give our app a name like N8N tutorial. Provide a contact email and click on next. Then in the list of use cases, select other. Click next. Then select business. This will allow us to integrate with WhatsApp. Then click on next. And then let's click on create app. In this list of products, look for WhatsApp and click on set up. All right.
[03:07] You will now be asked to choose a business portfolio. If you don't have a business portfolio yet, then you have to create one. To create a business portfolio, go to business.fas.com and sign into your account. Then on this left drop-down, click on create a business portfolio. This will ask you for some very simple information like the portfolio's name and your contact details. Then simply create this business portfolio. Then back on this form, simply select that portfolio and click on continue. Now you
[03:40] should see WhatsApp on this left sidebar. Click on API setup. We will come back to this page quite a few times, but all we have to do now is to add our phone number. This will allow us to test this service. So, under this two dropdown, you might not see any numbers at this stage. So, click on manage phone number. Then click on add phone number. And then simply go through this very simple process to add your number. Once you've done that, select your number from this dropdown. And now that we've
[04:11] added our number, all we have to do is generate this access token by clicking on generate access token. Cool. We've now added our phone number and we've got an access token. Simply scroll down with this page and click on send message. And you should now receive this hello world message on WhatsApp, meaning we're ready to go. Finally, we can start building our N8N agent. Let's click on create workflow. And I'm going to rename this to WhatsApp tutorial. And for our
[04:42] trigger, let's search for WhatsApp business cloud. And let's select on message. Then under credentials, let's create a new credential. And I'm just going to rename this to WhatsApp tutorial. And now we have to provide the client ID and client secret. We can get those by going back to meta and under app settings click on basic. Then copy the app ID and add it to NN. Under client ID and then for the client secret
[05:15] we can click on show. Then let's copy the secret and add it to NN as well. Then click on save. If everything was done correctly, you will see this green connected successfully message. And we can now close this popup. Right? So this means that N8N is now listening four messages from WhatsApp. We can actually test that. So let's click on test workflow and then let's go back to WhatsApp and let's say hello. All right, going back to N8N, we can see that this message was indeed received. And if we
[05:45] open this up, we can see all the information that was received from WhatsApp. And this includes a lot of sensitive information. So, I do apologize for all the blurring in this video, but hopefully I don't leak my phone number in the process. What we're interested in is this messages array, which contains our message from WhatsApp. So, what we can do now is click on add advanced AI and let's select AI agent. For the prompt, let's select define below. And now we can simply grab that message from our
[06:17] WhatsApp trigger and add it into the prompt. Then let's add our chat model. So I'll simply use OpenAI. I'll leave it on GPT4 mini. And let's go ahead and run this agent node. Cool. So our agent responds with hello, how can I assist you today? Let's also add a system message to our agent. So let's go to expression. Let's expand this. And let's say you are a helpful assistant called Sam. Now I also want this agent to know who it's talking to. So what we can do
[06:48] is simply assign the name of the contact to the system prompt as well. So we could say something like you are currently talking to and then let's grab the name of this contact and assign it like so. What I also like to do is to tell the agent what the current date and time is. So let's say the current date and time is double curly braces. Let's select now dot to ISO string. And of course, you could extend this however
[07:19] you want. So, we could say something like respond in a natural and friendly tone. Cool. Let's go back to the canvas and let's assign a memory node as well. This way, the agent will recall our conversation history. Let's add a simple memory node. Let's change the session ID to define below. And I personally think using the mobile number would be a good session ID. So I'm simply going to add the mobile number as the key value. And for the context window length, I'll just
[07:49] pull in the last 20 messages. Cool. All we have to do now is respond back to WhatsApp. So let's add another node. Let's add WhatsApp business cloud and let's select send message. For this node, let's click on credentials. Let's create a new credential. And now we have to provide an access token and the business account ID. First I'm just going to rename this to WhatsApp tutorial. Then for the access token, we can get that by going to WhatsApp. Let's go to API setup. Then let's copy this
[08:22] access token which we generated earlier. Let's add that to access token. Then for the business account ID, we can copy it from over here. And let's add that to N as well. Cool. Let's save this. If everything is green, it was set up successfully. And if you do receive an error message at this point, it's very possible that your API key expired. So if that happens, simply click on generate access token and then update NN with that token. Cool. So for the operation, we'll leave it as send. Then
[08:54] for the sender phone number, let's select this test number. And for the recipient phone number, you can get that from messages. And this from value over here, let's add that to this field. And for the text body, we can get that from the AI agent node. So let's grab that nodes output and add it to the body. Awesome. Let's test the step. And we can see that response coming back to WhatsApp. Awesome. We've now successfully connected our AI agent to WhatsApp. But of course, we can take
[09:25] this way further. In WhatsApp, we're able to send voice messages. And of course, we can also send attachments like documents and images. So, first let's have a look at sending audio to our agent and getting our agent to respond with audio as well. So, to get this to work, I am going to make a few small changes to our flow. And all of this will make sense during the course of this tutorial. our agent will no longer grab the text from this WhatsApp trigger node as of course there's a possibility that we won't send text. We
[09:57] might send an image or audio instead. So what we'll do is add something in the middle called the set node. And I'm going to call this one text only prompt. And then I'm only going to add one field to this called text. And for its value I'm going to grab the text that we received from this WhatsApp trigger node. So, this one is super straightforward. I'm actually just going to run this node. Cool. So, now in the agent node, let's replace this prompt
[10:28] with this text property from the edit node instead. Cool. Now, if we run this and send a message on WhatsApp, everything will still work as expected. And actually, it doesn't. We get this error message saying there's an issue with the simple memory node. And this makes sense because JSON is actually referring to the note just before this agent note which is this one. And this note does not contain this object over here. So what we need to do instead is reference our WhatsApp trigger node by
[11:00] entering double curly braces. Let's select WhatsApp trigger dot item dot JSON dot messages which gives us an array of values. So we'll simply grab the first item in the array and on this object we have this from property which contains our phone number. All right, let's go back to the canvas. Let's test this workflow. So let's say again hello. And this time we get our response back.
[11:31] Cool. Now let's have a look at adding audio to this workflow. So let's wait for a message and let's say why is the sky blue? Let's send this. Going back to N8N, we can ignore the error. But what we are interested in now is to see what we get back from this WhatsApp trigger within the messages array. We now receive this audio object which contains all of these different properties. And this looks very different to when we send text via WhatsApp. So this means we have to cater for different scenarios.
[12:03] We have to change the logic slightly depending on whether we receive text, audio or images. So to process these different scenarios, we could add another node directly after the WhatsApp trigger node and let's search for switch. We can use the switch node to route the process down different paths depending on certain conditions. For instance, for the audio route, we can say that if this audio object, which we can add to value, if this audio object exists, so let's change this dropdown to
[12:37] object and exists. and then we'll go down this path. I'm just going to rename this to audio. So, let's only add this route for now. So, we've only got this one audio output. I'm just going to add the route for text as well. So, in WhatsApp, let's just say hello, right? Then in NN, let's add another route. And in messages, we can now see if this text object is available. So, if text and let's switch this to object and let's select exists. Then we want to route
[13:09] down the text path. And I'm just going to break this connection because it's the text path that needs to call this route. And let's be proactive as well. And let's assign a route for images. So let's click on test workflow. I'm just going to attach any image like this one over here. Let's just say hello. Let's send this. And back in our switch node, let's add another routing rule. And for this one, we now get this image object. So let's add this to value. And let's
[13:40] say that if the image object exists, then we want to route down this path, which we can call image. And let's process this audio route. Let's just get some data in again. So back in WhatsApp, let's say why is the sky blue? Let's send this. And inn, we can now see this audio path is being triggered. I don't want to resend messages through WhatsApp every time to test this. So for the time being, I'm actually going to pin this data by clicking on this pin node. And
[14:10] now we can easily retest this workflow by clicking on test workflow. And that will retrigger this workflow using the data that we pinned. All right. Now the first thing we need to do is to download that audio file. So let's search for WhatsApp business cloud. Let's click on download media. Let's rename this note to get audio URL. Let's rename this. Select your credentials. Under resource, make sure that you've got media selected. And for the operation, it needs to be download. You can get the ID
[14:43] under this audio object. So, let's add this ID. Let's click on test step. And this now gives us this URL. Now, this is a protected URL. So if you try to access this image directly, it will tell you that you're not authorized. So the next thing we have to do is to use that URL to download this file. So let's add the HTTP request node. Then let's add the URL to this field. And under authentication, select generic
[15:13] credential type. Under generic orth, add the orth header. And under header or go ahead and create your new credential. And let's call this WhatsApp tutorial. For the name, enter authorization. And it needs to be spelled like this exactly. Then under value, switch over to expression. Let's expand this and enter bearer space and then copy your access token and add it
[15:43] after bearer like so. Then close this popup and click on save. All right, we should now be able to download this image. So, let's click on test step. And there we go. We now have the file on the right over here. Cool. I'm actually going to rename this mode to download audio. Cool. Now that we have this audio file, we need to go ahead and transcribe it. So, we'll take the audio and convert it to text. Let's click on add actions. Let's select open AI and let's select
[16:14] transcribe a recording. We can actually leave everything on the default values and click on test step. And look at that. We now get the text back from our audio. And all we have to do, well, first I'm going to rename this node to transcribe audio. And then let's create a set node. Let's add a new field called text. And for the value, let's add the transcribed audio. Let's run the step and then let's rename this node to audio
[16:45] prompt and then let's hook up this node to our AI agent. So take note that the field name should be the same in this texton prompt. So we called it text and it should also be called text in the audio set node as well. So this means when we run our agent, the agent will now tell us why the sky is blue. Cool. is now processing the input from this audio branch node instead of this one over here. Now, if you want to, you could also respond with audio. And to
[17:15] me, that makes sense. The only reason I would send a voice note is because I'm not able to text at the moment. So, I would expect the agent to respond in audio as well. This is really simple. All we have to do is click on add. Let's search for if and let's add this if node. So in this node I want to see if we received audio from the WhatsApp trigger node and if we did we want to respond in audio as well otherwise we'll just respond with text is go to our WhatsApp trigger node and if this node
[17:47] contains this audio object so let's add it to our condition and if this object so let's go to object exists then we want to respond with audio else will respond with text so we actually have to break this connection because if the condition is false, so if an audio object does not exist, then we want to respond with normal text. I'm actually going to rename this note to respond with text. So how do we respond with
[18:18] audio? Then the first thing we need to do is to grab the output from the agent and convert that into audio. So let's actually run this if node. Okay, so it's calling the true condition. Then from here, let's add open AI and let's go to generate audio. And in the text input, let's grab the output from our agent. And if you want, you can change the voice. I'll simply leave it on Aloy. Let's test the step. And this gives us this audio file. Let's listen to it. The
[18:50] sky appears blue due to a phenomenon called scattering. So, of course, if you wanted to, you could change the voice, run the step again, and then listen to what that sounds like. The sky appears blue due to a phenomenon called scattering. I'm just going to select Aloy, right? I'm going to rename this node to generate audio. Let's rename this. Let's go back to the canvas. And then let's add another action. Let's search for WhatsApp Business Cloud. Let's select send message. Then let's
[19:21] select the test phone number again. Let's also add the phone number and very important for the message type change this from text to audio. Then change take audio from to N8N. So effectively this will grab this data binary file over here. However, there is an issue with this. Let's test the step. And now we're getting an error message that's basically saying that the mime type is not correct. we are passing a mime type of
[19:52] audio/mpp3 and according to WhatsApp that's not an allowed mime type. So what we're going to do is to manually change the mime type to something at WhatsApp expects. So in between these two nodes let's add another node. Let's search for code. And in the description of this video you can simply copy and paste this code into this JavaScript block. Really all this is doing is checking if a binary file exists and it's then converting the file from audiompp3 to
[20:23] audiomp. Let's test the step. And on the left hand side you can see the original file which had a mime type of audio mp3. And on the right hand side you can see that everything is exactly the same. We simply change the mime type to audiomp. So if we run this WhatsApp step again, everything works correctly. And in WhatsApp, we get our audio response. The sky appears blue due to a phenomenon called RA scattering. Awesome. I'm just going to rename this note to respond
[20:54] with audio. Cool. And that was actually the most difficult part of this entire video. Next, we're going to look at how to process images. But if you are enjoying this video, then please consider subscribing to my channel and hitting that like button. Now let's have a look at dealing with images. The first thing I need to remember to do is to unpin this data. So on the WhatsApp trigger node, let's click on unpin. Then let's click on test workflow and let's send an image along with some text from WhatsApp. So let's upload this image and
[21:27] let's say describe this image. Right? So, back in inn, this image path is now being triggered. I'm actually just going to move all the audio stuff up like so. And then let's add another node. Let's search for WhatsApp business cloud and let's select download media. Then in our WhatsApp trigger node, let's grab the image ID. I'm also going to rename this to get image URL. Let's execute the step. And just like with the audio file,
[21:58] we get this URL back. So I'm sure you know what comes next. Let's add another node. Let's add the HTTP request node. Let's add a URL to the URL field. Under authentication, select generic credential type. Under generic or type, select header O and simply select the header or which you created in the audio step. Let's execute this. And indeed, we get our image back. Let's also just rename this node to download image. And
[22:28] now let's use AI to analyze this image. So let's search for open AI. Under actions, let's select analyze image. I'm just going to rename this node then to analyze image. In the list of models, let's select GPT4 latest. And for the text input, I'm going to say describe this image in detail. I'm going to change the input type to binary file. And this will simply grab this binary image from over here. Cool. Let's test
[23:00] the step. And now we get this detailed description of the image. Now all we have to do is create a prompt which we can pass to our agent. So as you can guess, let's add a set node. Within the set node, let's add this text property. And for the value, I'm going to switch over to expression and write out a little bit more detail. So let's say the user provided the following image and text. Then under image description, let's add the summary of this image from the analyze image node. If the user
[23:31] provided any sort of text along with the image, let's pull that in as well. So let's just call this user message. And let me just explain what this is. If we go to the image object within the WhatsApp trigger node, this gives us the unique ID of the image which we use to retrieve the image and perform that analysis. But we also get this captions property. But this property is optional. So when we sent this image via WhatsApp, we were asked to provide some text. But we don't have to provide that text. And
[24:03] if we omit this, then this caption property won't be here. So what we can say is the user message is this value by default. But if this property does not exist then we want to fall back to a default value. So we can add this fall back by adding double pipes and in quotes let's say describe this image. So if the user didn't ask any specific questions then our agent will simply describe this image. Let's also rename
[24:33] this node to image and text prompt like so. And finally, let's attach this to the agent as well. Let's go ahead and test this. So, let's click on test workflow. And in WhatsApp, I'm going to upload an image. So, initially I'm not going to provide any text. So, it should fall back to describe this image. Let's run this. And in N8, we can see this is running. It's analyzing the image. Now our agent is running and it's responding
[25:04] with text and in WhatsApp we can see a simple description of that image. Now let's try running this by sending an image as well as a very specific question like what color is the shirt? Right? So back in N8N our image is being analyzed and now our agent is responding to our actual question. So what we can do now is simply activate this workflow. And now we don't have to click on test workflow every time we want to test this. Now that the workflow is active, we can simply chat to our agent by
[25:36] saying hello and we get a response back. Let's test its memory like what is my name? And we get our name back. I'm not going to go into any details on adding tools to this agent as I've already got plenty of videos covering that topic. And I will link to my full Nitn playlist in the description of this video. But very briefly, you can simply click on add tools. And here you get access to hundreds if not thousands of tools offered by N8N. For example, we could
[26:06] add the SER API tool which will give our agent access to Google search. So if I save this, I could now ask something like what is the latest weather in New York? and our agent will now use the SER API tool to retrieve that up-to-date information. But again, I've got plenty of videos showing you how to add emails, to-do lists, and much much more. Now, just a final note on this access token. At the moment, we have to regenerate this token every few hours, and this is really for development purposes. In
[26:37] production, you would want to get a permanent access token. Now at the moment we are in development mode and that is why we have to regenerate the access token every few hours and verifying your meta account is not something I'll be covering in this video but effectively what you have to do is go to your business portfolio and then verify your business. So if you go to this section under business verification status you can click on view details. This will take you to this section where you can go through the business verification process. And once you've
[27:09] verified your business, you can go ahead and create your permanent API key. If you found this video useful, then please hit the like button, subscribe to my channel, and watch this other video where I show you how to create an MCP server with access to my emails, to-do lists, and much, much more. I'll see you in the next one. Bye-bye.