*LIVE BUILD* Inbox Management AI Agent with n8n (NO CODE, Step-by-Step Tutorial)

Dr. Violet Howard builds an automated inbox manager in n8n that uses GPT-4 to sort emails into four categories (High Priority, Customer Support, Promotion, Finance/Billing) and applies Gmail labels automatically. The tutorial covers Gmail OAuth setup, configuring the text classifier, and testing with live emails.
Chapters
All right, today we're going to be building an inbox management agent. By the end of this video, you'll have a workflow up and running that is going to be able to categorize and label your emails as they come in based on how you tell the agent to do so. So let's not waste any more time and just start building this thing. So the first thing we need to do, as always, is add a first step, which is something that triggers the workflow to actually run. This first step here is going to be a Gmail trigger. So if you type in Gmail and we're going to grab on message received, So essentially, once this workflow is activated, every time you get a new email, it'll be running. As you can see here, it's actually going to be running every minute, but the event is going to be on message received. So we need to connect the Gmail account. So I'll walk you guys through this. If you already know how to do this, feel free to skip past this part. You're going to click Create New Credential. We need to grab a client ID and a client secret. So if you click on Docs right here, You know, NNN has great docs on actually how to do this. It walks you right through it, but I'll also do this with you. So we're going to create a Google Cloud account. If you don't already have one, create one. And then you're going to go to your console. Within your console, you'll be able to make different projects, so make sure you're on the right project that you have just made. And then you're going to go over here on this left-hand side to APIs and Services, and we're going to go to Enabled APIs and Services. And once you get here, As you can see, I've got some APIs set up, but we're gonna search for Gmail. You'll see Gmail API, and then all you need to do once you're within this little section is to make sure it's enabled. So there'll be a button here. As you can see, mine's already enabled. Now we're good to go on that. Go back to APIs and Services and go to OAuth Consent Screen. You really just need to set up this screen that's telling N8N and Gmail like they have permission to talk to each other, basically. So once you, once you're setting this up, you just have to make sure— this is important— that you either publish your app, so click on publish here and push it through, or add your email down here as a test user, just like I said, so that there's permission. So make sure you do that, otherwise you'll get a message in NNN that says, you know, it's blocked, you can't go through. So just make sure you do that. And then the last step is within these APIs and Services. You're going to click on Credentials. You're going to create credentials, and it's going to be an OAuth client ID. You're going to set up a web application, name it whatever you want, and then you need to add the URI down here. So click on Add URI, hop back into NNN, and that's what you're going to grab right here. So you're going to copy this, you're going to go back into Cloud and paste that URI into there. And then you can click Create. Once you do that, you'll have an ID and a secret right here, which you will copy and paste into the respective fields in n8n. Okay, once you do that, this button will pop up. You're going to need to sign in with Google. Click on the correct email that you want to use. This is because I'm testing the app, so it's going to say it hasn't verified, but you can click Continue and Continue. Push through there and make sure you give Gmail access or any access to everything within your Gmail. So now we're connected. It went green. Good to go. Okay. So last thing we need to do in this node is change this off. We don't want to simplify it. As you can see here, this will simplify the response instead of the raw data. And we want the raw data so that the next node can sort of see all of the information that's coming through, not a simplified version. So we're good to go with this node. If we fetch a test event, we can see an email coming through, which looks like it was just a test email that I sent to myself earlier. So now we've got this set up. The next node we're going to add is the actual agent. It's going to be a text classifier. So when we're in here, the first thing that we need to set up is what text is this node classifying. So if we make sure you're on schema, and then we're going to collapse this down here under headers, and we see text. So we're going to grab this text, put it in there. And as you can see, this is sort of what the actual email that's coming through looks like. This one looks all weird because it's fake, but this is the text that we're classifying. Next, we're going to add the categories, which are going to be the actual labels that we're putting into Gmail, or that the emails will be classified as. So the first thing we want to do is go back into Gmail and make sure we have the label set up. So just for the purpose of this video, I'm doing 4. The first one's High Priority, second one is Customer Support, the third one is going to be Promotion, and the fourth one is Finance slash Billing. And now I'm just gonna change these colors so it's easier to see them come through when we're actually testing this thing. Okay, so we've got those labels set up. Now we're good to go in and in to make these different categories. So we're gonna do 4 different categories. Like I said, the first one we did, high priority, and I'm gonna copy and paste in these descriptions so you guys don't have to watch me type. but what I did is I went to ChatGPT and I said, hey, you're, you're an inbox management expert. I've got these 4 categories. Can you make descriptions for each category that basically tell an agent how to accurately correlate an email with each label? So super easy way to do it. So this first one, I'll give you the example. It said emails requiring immediate attention or action, typically from key stakeholders, clients, or decision makers. These emails often contain time-sensitive requests, deadlines, or escalated issues. And then I threw in some keywords here at the end that you might see within an urgent or high-priority email, you know, ASAP, immediate, deadline. So that's exactly how we're going to do the rest of them. So this next one, your customer support. I'll give you this one more as an example. This one says emails related to ongoing communication with current clients or customers, including service requests, feedback, support tickets, inquiries, and then the keywords: request, inquiry, support, question, feedback. Yeah, so feel free to, you know, go as detailed as you want within those category descriptions, but giving keywords is a good idea, and then obviously a very thorough description of what we're looking for. So next we've got promotions, pretty much the same exact format. I won't bore you guys with that, but paste it in that description there for promotions. And then category— sorry, category. We've got Finance and Billing as the last category. And here is our description. So keywords, as you can see, invoice payment, billing. And we're basically just saying emails related to financial matters and explaining what that means. So we've got our 4 labels that we have in Gmail set up. The last thing we need to do on this node is under Options, we're going to add an option of System Prompt Template. Now we can just leave this as is. It's a basic system prompt, but this is just telling this text classifier node to do its job, to take the email that's coming in from Gmail, to think about it with the, you know, GPT-4 model that we're about to add, and then push it out with an assigned category. So real quick, we need to add the model. Like I said, we're going to do GPT-4. So you need to create your credential here too. All we need for this one is an API key. So if you go into OpenAI on the left-hand side, API keys, you're going to create a new one and then just copy this value into N8N. And when you hit save, it'll turn green if you're good. So we're good to go here. Now we're going to choose 4.0 and we can test this thing. So I know that this is kind of a fake email, so We'll do a better example. But as you can see, high priority, nothing. Customer support, nothing. Promotions, it got labeled as a promotion. And then finance and billing, it got nothing. So let's real quick send an email that would be a high priority message. So same exact thing I did. I asked ChatGPT to make example emails that would fit into each of these categories. So we're going to send ourselves an email. and we're actually just going to put this as the subject because if you remember in this node, we're saying this is the text we're classifying, which is the text, the body of the email, not the subject. So this node is only looking at what's in the body of the email. So the subject is a bunch of gibberish, but the actual email is going to say, hey Nate, we need your immediate approval on the finance or final proposal for the Johnson project. The deadline is 5 PM. The client is expecting us to proceed. Please review and confirm as soon as possible. So that's clearly a pretty high priority email. We'll fire that off. And now if we come into here and we actually, we can just test the workflow. So it should be grabbing that new email and then it's gonna classify it. So as you can see, we've got a high priority email. Let me just move this over. And as you can see, we're looking for the text. So the text is, hi Nate, we need your approval on the Johnson project. So this is exactly what we just sent off. And it got labeled as high priority. So we know that this step is working, at least for the high priority branch, but we'll test them all out later. So we've got the node that's assigning labels. Now we need to get the nodes that actually take those emails with the labels and push it back into Gmail under those labels. So branching off the high priority, let's click on the plus and we're gonna grab a Gmail node again. This one is going to be right here at the top, add label to message. So we've already set up the Gmail account. We'll just click back into there. The resource is a message. The operation is going to be add label, and then we need an ID and we need the actual label that it's pushing it to. So for ID, we're going to grab ID right here. This is the email that is corresponding with, um, or the email that just came through. It needs to see which one to give what label. So before we add this label, um, we want to copy this node 4 times because there's data that came through right here at this dot, but no data came into these ones. So if we added a Gmail node here, we would have no information to pull into the message ID thread. Now we could just take the variable of json.id because it's always going to be JSON.ID. But you know, this is no code, so if you just grab that, copy it, copy and copy. So now we've got 4 of them and they all have that JSON.ID. Okay, so this one, back to the first one, we're going to call this one the high priority one just to stay organized. And then we need to choose the actual label within Gmail. As you can see, it's high priority. So we're going to grab the high priority label right here. So if we test this step, it's going to assign that email that we just did to high priority. And I'm pretty sure if we go back into Gmail and refresh, this email is labeled high priority. So we know that that's working. All right, so now we just need to do the same for these other ones. So we'll grab this one and you can connect it to customer support. Now we can go in here, call this one customer support, and it's already connected. We've already got the ID and now we just need to grab the customer support label. So that one should be good. Let's do the same thing for promotions. Make sure you connect promotions to this node. Keep ourselves organized. Promotion. And we've got the message ID. Now we just need to add the label of promotion. Same thing one last time. Finance and billing, connect it. Finance and billing. And the label we're giving it is finance and billing right here. Okay, so this is all that it is. Now we can get more complicated from here and we can start to decide which ones can N8N respond to by itself, sort of the low priority ones, and then obviously high priority. And maybe, you know, this one would be ones where we would get a notification about it and we would respond, but maybe a customer support one, we could give the agent access to a knowledge base to respond to this automatically. But for this agent, we're keeping it very simple. We've just got these 4 labels and that's all it's doing. So we've saved this here. Now let's, let's activate it. All right, we got it. So now that this workflow is activated, it's actually going to refresh every minute and be looking for emails and it's going to sort of do this automatically. So while you're sleeping, if you get 10 emails, you'll wake up, check your inbox, and they'll all be labeled. So let's come back into Gmail and send some emails off so we can test this. So, um, here we go. We're gonna send another one. We will just do gibberish again for the subject. I'm gonna copy in this message here. So this one's saying, hello, I'm unable to log into my account on your dashboard. I've tried resetting the password, but it isn't working. Can you help me resolve this issue? So this is clearly a customer support email. So send that off. Let's add another one. This one is going to be a promotion. So let's actually, we'll just throw in an actual subject here. And we've got our email. So, hi Nate, we're excited to offer you an exclusive 25% discount on all AI automation services this month. What a great deal. Don't miss out. Okay, so that's a, that's a promotion. We'll send that off. And then we'll do one more, which will be a finance and billing one. Um, we'll put an actual subject just so it looks more real. And then we've got, hi Nate, this is a reminder that your invoice is due October 5th. Please ensure your payment is made by due date to avoid any late fees. So this will be interesting to see, you know, that may be something urgent but really pertains more to finance and billing. So we'll send that off. So you can see this one already got labeled as customer support sort of as we were in here doing this, which was that they were unable to log into their account, tried resetting password but isn't working. So we've got customer support that was working, our high priority one we tried earlier. Let's just go back into the main inbox and if we refresh, maybe we'll see if N8N refreshed yet. Okay, so N8N did not refresh yet. Um, so let's just give it like 25 seconds and then I'll refresh again. So, okay, let's refresh again and see if we got any hits. Okay, they both got labeled now. So we've got a promotion special offer, and we've got our finance and billing invoice, um, which is due October 5th. So that they all worked as planned. Like I said, you can start to add more and more labels and just give specific instructions as to what emails will go to what label. But as you can see, that took what, you know, not even 15 minutes, and we have this whole thing up and running. And now your inbox is going to be managed by this agent using GPT-4.0. So, um, like I said, this is a— this should open your eyes to what these agents can actually do when you start to give them access to, you know, automatically respond to customer support. Or if it's a promotion, um, you know, notify my assistant about this so he can manually read through and look at it. And then I'll just be dealing with only the high priority issues. You know, you can, you can notify my accountant about these, these issues, but I just want to be focusing my time on high priority so that I can focus on growing the business. So that's all I've got for you guys today. So if you enjoyed, definitely leave a like and let me know what else you want to see. But other than that, thanks so much, guys.










