Transcript for:
Integration of n8n with ManyChat

if you want to connect your nhn aai agent with Instagram or any other platform for that matter then this video is for you I'm going to be showing you exactly how to integrate your NN agent with many chat which allows you to connect it with not only Instagram but also Facebook WhatsApp Telegram and many more platforms I'm going to provide you with all the templates necessary completely for free at the end of this video and let's get right into it if you guys are not familiar with n8n already the link is down below you can sign up for a free trial it's basically a workflow Builder but it also allows you to create AI agents and it has become the most powerful tool and I have a ton of videos on this channel building actual in-depth AI agents I'm going to link a full course down below if you want to learn now manich chat on the other hand is an automation for Instagram originally but it also has Facebook WhatsApp Telegram and many more options it's very easy to get started just go to manychat.com link is going to be Down Below in the description as well click on get started connect your Instagram account or your Facebook page and go from there now once you have NN set up and you have many chat connected to your Instagram account you're going to be able to follow this tutorial easily now inside of NN I have a template right here this template is going to be available for free down below in the description in our free school community at school.com omn Fusion simply take this template click on the three dots and click on import from file this is going to allow you to take the file which you downloaded from the free community and upload it to N1 to see what you're seeing on screen right now now all we have here is a simple web hook node this is what we're going to be triggering from many chat we have an AI agent with open AI connected and window buffer memory and we have a respond to web hook node right here the key elements here are that for open AI we have the credentials connected you can go to platform. open.com log in using your chat GPD account generate an API key simply go on click create new credential and add your API key here click on Save and that part is going to be done and for the window buffer memory make sure that you have the context window length down here set to 10 now as for the AI agent itself if you click on it you're going to be able to see that we have a possible system message down here this is going to be the system prompt where you can follow prompt formats and guidelines to actually create a proper agent now I actually have a ton of videos where I go in depth into building the prompts including the full N8 end course but I'm just going to copy a prompt in here just to make sure that we actually have an agent to test going to go ahead and click on Save and we're now going to focus our attention to this web hook over here to actually set up the many chat integration now once you have many chat connected and you joined the community there's going to be a link there for the men chat template if you click that link it's going to allow you to import it directly into your men chat account and you're going to be able to find it in the automation tab simply go ahead and open up that many chat template and this is what you're going to see now you don't need to understand everything that's going on here but you do need to understand a couple simple details number one we have a message counter system here which allows you to reply to multiple messages with one reply message so if somebody sends hey send how are you send I'm interested send it's going to reply to all three of those messages in one go instead of replying separately to every single one the time delays that you see over here is basically the time that we wait after a message has been sent to see if a second message was sent so you can adjust this time as you wish I've kept it to the minimum for now which is 10 seconds just for the purpose of this video we usually have something between 30 and 60 seconds where we wait for a second message to come in before replying we then over here have a Google app script I'm not going to explain how to set this up in the video but there's an easy to follow tutorial inside the school Community you need to set up this Google app script in order to actually be able to process the input message that you get from many chat and format it in a way where it doesn't break the API request to na10 now once you have this set up and you added in your U URL over here we're going to redirect our attention to the send message to nhn node which is where we're going to set up everything we need for this simply go ahead and click on edit find the send message to n8n node click on it and click on the external request now we're going to go back to n8n we're going to make sure we select test URL and what's very important is that you have the web hook here set up with the post method otherwise it's not going to work we're going to copy the test URL we're going to click on listen for test event we're going to go back into many chat and we're going to paste this test URL in the top right here now what's very important is you actually need a contact for testing so right now if I look for myself there is no contact found now in order to trigger a contact for testing I'm simply going to DM myself on the Instagram account that I have connected to many chat so I'm sending the DM now and if we go back into men chat and we search for my contact right now we are going to see that it is right here and we have an Instagram contact to test with we're going to select this contact and click on test request we're now going to go back into n10 and as you can see it pulled in a ton of different information over here from the test request we're simply going to go ahead and click on the AI agent we're going to have the source for the prompt which is the user message which we're going to Define manually or you can keep it the way that it is but if you scroll down you can drag in the message right here then we're going to go ahead and click on window buffer memory and we're going to need to set up the session ID you can keep it as it is if you have the template if not you're simply going to need to go here copy the session ID into here copy it out and then paste it into the memory node since it's already done I'm just going to leave it we then have the respond to webook node where we're going to need to specify the output where we have output Json stringify and you can leave this exactly as it is in the template otherwise it's not going to work so with that being said we are now done and ready to test this live we're going to click on Save we're going to make sure that the workflow up here is set to active otherwise it's not going to work we're going to click back onto the web hook and select production URL we're going to go ahead and click and copy this URL we're going to go back into man chat we're going to replace the test URL with the production URL and we're going to go ahead and click on Save now that we've clicked on Save we can go ahead and click on update to actually save these changes now What's Happening Here in the end is when we get the reply back from n10 if we go to the response mapping section we can see that we're going to take the output and we're going to apply it to a variable inside of many chat which is called last reply so the last reply variable is going to be the message that we receive from the n10 agent we are then going to go ahead and send out this last reply to the user and if they don't reply we're going to send a message saying just checking in still interested this is a follow-up message if the contact has not responded and if you click here on the contacts reply you can set up the time interval that you want to wait for this follow-up message if you don't want to do a follow-up message at all you can also go ahead and delete this connection right here and it's not going to trigger now the final thing that we need to do is actually connect this default reply over here now for you it's going to be empty so go ahead and click on settings select your channel which in this case is Instagram and here you're going to have to click on select existing and select the many chat xnn flow which we just set up you click on it you click on pick this automation you can then click directly here to go back into the automation we select edit and this is very important click on the default reply and make sure it's set to every time if it's your first time using men chat and using a default reply it's going to be set to once per 24 Hours by default what we want to do is we want to make sure that every time somebody messages us on Instagram it's going to trigger this AI agent so we're going to set it to every time and make sure that it is turned on now we have everything we need to actually test this flow now in order to test this we're going to go back into Instagram I'm going to say hey I am interested and now inside of many chat if we go on the live chat we're going to be able to see this message if you click on the three dots you can actually show the system messages which is going to show you everything that's happening in the backend if we now go into N1 and we click on executions we're going to be able to see the execution right here at 10:17 which is right now and we're going to be able to see that the AI agent got the message which is hey I am interested the reply from the AI was generated this reply was then sent using the respond to webbook node with the output and if we go back into the live chat we can see that the message was actually sent to us and if we go into Instagram we can see that we actually got the reply as well now I can continue the conversation to show you guys how it works and I'm going to say yes sure that's cool I'm just a bit scared so I'm going to demonstrate the multiple messages and that they are working so if we go back here we're going to see yes sure that's cool I'm just a bit scared we got two messages in here and if we go into n8n right now and we go to the executions we're just going to wait a second we can see that the new execution was added right here and if we click on the AI agent we're going to see that we got both of the messages combined into one and we sent it to the AI agent so we said yes sir that's cool I'm just a bit scared we got the reply back inside of many chat it was actually sent out and if we go to Instagram it was sent as well and now we have a working integration between n8n and many chat if we want to change this to Facebook for example we could click to settings go to messenger and connect our Facebook account we would then simply go to automations go to the specific template we have we can also duplicate it if we want one for Instagram and one for Facebook and we would simply go ahead and change this over here go to the plus and here it would show Facebook if we actually had Facebook connected we could then pull in the Facebook node and make sure that we select the last reply variable by clicking here and searching for last reply which would then go ahead and send out that message and that is it for this video If you enjoyed it leave a like And subscribe to the channel join our free school Community to get access to these templates and much more free value and knowledge on I'm building AI agents and I'll see you in the next one have a good day