Hi there.
In this episode, I'm going to teach you how to build a super practical automation, which is a Gmail
inbox manager and classifier.
So this AI powered email system replies to customers automatically based on the content of their message.
So this automation a automation.
Extract names.
Understand what type of email it is like.
Service requests and consultation.
Request payments and then generate a smart reply.
This way you can respond to leads or customers instantly, even when you sleep.
Also, this automation is going to label all your incoming emails and push them into specific categories.
So you can review them later.
And you can have all emails categorized and you can have all emails organized like that.
This AI automation is very useful because your customers get an immediate reply with the next steps,
which is great customer support, so you can use it for many cases and adapt it to your needs.
This time we are going to build this awesome automation completely from scratch.
So let's create a new workflow.
All right so let's get started.
So first we are going to create a workflow.
So this is AI automation is going to read incoming emails understand what the email is about.
As always, every automation starts with a trigger node.
In that case, we want to connect our Gmail account.
So let's search for Gmail.
You can do it by adding a new node on app event and search for Gmail.
Or the second way is to add first step.
On app event and search for Gmail.
Scroll down.
Choose this one.
So our automation will activate on message received.
Now make sure to connect your Gmail account here if you haven't done it before.
Just go to the How to set up credentials section and you will find a separate tutorial on how to do
it.
You can simply if you are using a cloud or a cloud version of N810, you can just create a new credential
and sign in with Google and then hit save.
If you are using self-hosted version of N810, you need to do manual setup.
You can also find a tutorial on how to find API keys, uh, in the How to Setup credentials section.
Now, the shortest polling interval for Gmail is every minute, and that's perfect for this use case.
But if you if you like you can change it to every hour every day.
So basically this node will check your Gmail inbox In that interval.
As event we want to leave it as it is.
So message received.
I think there is no other option here.
And also disable simplify response because we want to get the full email data.
All right.
So now this node is configured.
Now let's add next node.
So now we want to extract data from the emails.
So we need to add information extractor node.
So let's search for information extractor.
Now once you successfully connected your Gmail account to N810 you can give it a test to get some data
into our flow.
So it will fetch The last emails from your Gmail inbox.
So let's test the workflow.
As you can see, workflows executed successfully.
Now let's open this node again.
And as you can see we received some data in a JSON.
You can see it in a JSON format.
Or in schema.
So use schema format in order to drag and drop variables and objects.
So now we want to extract the sender's name.
So in the reply we can use this name as a dynamic variable.
So we can create personalized emails.
And our AI automation will use the first name of the sender's.
So let's search for information extractor.
And in this step will also connect LM to give it some intelligence.
Is this one.
Now before we configure this node let's quickly add the LM.
So it will be the brain of this node.
And actually of this automation.
So here you can add different large language models.
We are going to use OpenAI GPT four mini because it's cost effective and very fast.
So let's search for OpenAI.
Personalized model.
I already connected mine OpenAI account to my N810 instance, so it's saved and I can use it in every
workflow.
If you don't know how to do it, go to how to set up credentials section and you will find a separate
tutorial.
Where I show you how to find an API keys in an OpenAI API platform account.
Here you can switch between different OpenAI models.
As you can see, you have GPT 3.5 turbo.
GPT four and GPT four roaming, etc. you also have embeddings, model and Audio models.
Let's stick with GPT three.
Now let's configure this node.
So we want to extract the sender's name right.
So in order to do that we have to add new attribute and give it a name.
So send the name.
The type will be string.
You don't need to change anything here.
And as a description.
Basically description helps the AI understand what we are asking it to look for.
And we are giving it a specific task.
So in that case you want it to extract.
And the sender's name.
From this email.
And if no name is found, because sometimes people don't, uh, use their name in greetings.
In the greetings.
So.
To avoid any potential issues, we can guide our, um.
Model to return.
An empty string.
Great.
Now, in the text field, we are going to provide the body of the email.
So GPT four mini will be able to go through this email body and extract the sender name.
So let's search for a text variable.
So let's scroll down.
Actually it's somewhere here.
Yes you can see text.
So this is the actual content of the email.
So you can simply drag this variable and drop it like that.
You can also.
Do it manually by typing two curly braces.
And I will suggest you it automatically.
So you can use JSON.
Then dot and you can find text.
Great.
So the last thing we need to configure in this node is the system prompt, which is simply means giving
clear instructions to the AI on how it should behave and what to focus on.
In that case, what to focus on when extracting the information.
And you can add system prompt in Information extractor node by adding option.
And here we have default prompt.
You are an expert extraction algorithm.
Only extract relevant information from the text.
If you don't know the value of attribute, ask to extract.
You may omit the attribute value so we can leave it like that.
So now let's uh.
But if you wish, you can also modify this prompt.
For example.
I can add something like.
Going to paste it right here.
You are an advanced extraction tool.
Only pull out the relevant details from the text.
If you are unsure about the value of any requested attribute, leave it as an empty string.
Both will work just fine.
So now let's close this node and let's move on.
Now let's hit save.
And let's give it a test so you can see the output.
Great.
So let's open it.
As you can see.
The sender name of my last email is Damien because I've sent email to myself.
Okay, so it's working perfectly fine.
Now let's add another node.
Now we need to add a bit of logic because sometimes people don't stay emails by showing their name.
So we want to account for that possibility too.
So let me show you how to handle this by using an if node.
So let's search for if node.
And then we can as you can see then we can.
Route items to different branches.
So true and false.
So let's configure this node.
So in this node we want to check if the new email includes the sender's name, so you can simply drag
and drop the sender name variable over here.
And you want to change the condition from is equal two to string and is not empty because we want to
check if the sender name variable includes the sender name or not.
So in other words, if our, uh, email body includes the sender name or not.
So in that case we are going to use this one.
All right.
That's it for this one.
Let's just move it here.
As you can see you have two branches true and false.
So if our email includes the sender name we are going to do something.
Otherwise we are going to a different path.
So if the eye on the name.
It will go down the true path.
If it didn't, it will go down the false path.
So let's handle both cases.
So we want to create an introduction message based on the name.
So for the true path let's add set node to set items to variables.
You can modify and add them using this node as well.
And now let's we can leave manual mapping as it is originally.
By default.
And now we are going to create a new variable called intro.
And actually we can test the steps so we can get some data so we can easily drag and drop variables.
As you can see we have input data.
We can output data.
Here we have configuration.
So now let's.
So now as a intro let's use the sender name.
Okay great.
So that's it for this node.
Now let's handle the second case.
If the I didn't find the sender name in the email, so click Add note.
Let's search for set note again.
Let's create a variable.
The same name.
So intro.
But in that case, because we don't know the name of the sender, we want the AI to reply by just saying
hi at the beginning of the email.
All right.
Perfect.
Now I'm going to show you a cool tip which can save you a lot of time and API calls.
I'm going to record a separate lesson About this method, but it's very handy.
So in every node, almost in every node you can pin data.
So when I have tested workflow previously I got some data into the flow.
Right.
So this is the last email I received.
And here you can pin this data.
So you don't need to fetch the new email which arrives after this one.
You can use this one to test our workflow.
You can use this data to test our workflow and build on top of that.
So if as a trigger node, you make API calls to a third party service to a third party platform which
is paid, it can takes a lot of API credits.
And.
Over time can cost you a lot of money.
So this method can save you a lot of time and money.
Also, you can pin data.
In let's say.
This node.
And when we add more nodes you can test your workflow starting from this node.
So it can save you a lot of time because we don't need to trigger our workflow.
By the trigger node.
We can test it from this step.
All right.
So now let's move on.
Perfect.
Now we have two versions of the introduction depending on the on whether a name was fond or not.
So the next step is to bring the flow back together so we can use a merge node to match the paths.
So let's search for merge node.
Let's connect the second set node to the merge node.
The second input.
Now let's configure this node.
As a mode.
As you can see how input data should be merged.
We want to combine.
So we want to merge matching items together.
Right.
Now we are going to keep the setting as matching fields.
Because both of our set nodes, the one with the name from the email I sent to myself and the one we,
uh, thought have a field called intro.
And that's what we are merging.
So now the values themselves won't actually match.
One might say they're adaptive at gmail.com and the other just high.
So to make sure the merge node keeps whichever value is available, we need to switch the option to
keep not matching.
So that way only the the one that worked gets passed through and the workflow continues with the correct
greeting.
So let's switch to keep node matches.
And also you want to drag and drop the intro value to this field.
So the fields to match.
As you have specified in the set nodes.
See.
So you have the same name in both set nodes.
And now when you test the workflow.
As you can see we ended up with the intro data at gmail.com.
So it went through this path.
Because we actually managed to extract the the sender name.
Now before we add the node to classify the emails, let's organize the data we'll need later.
So the next node will be that node again.
And now we are going to add variables to help AI to reply to emails.
So first we need message ID.
So we'll be able to reply to the email.
And let's rename it to message ID.
Also let's rename the note itself to in data.
We also need the thread id.
So again from the Gmail trigger note.
And the last one we also need the email body.
So the actual content of the email.
So that email trigger note fetches all the emails from our Gmail inbox, so it should be somewhere here.
In this note.
So yeah, as you can see we have a text here.
So let's simply drag and drop it.
Great.
Awesome.
So that's it for this note.
Now we can classify the emails.
Right now we want to use AI to figure out what the email is about and classify, um, emails based on
the email body.
So there is a dedicated node for this operation.
It's called a text classifier.
Yep.
And actually it is easy to add this node from here, rather than from the this main plus button, but
we can simply connect it like that.
All right.
Now we need to add the large language model so as a brain for this node.
So to add AI capabilities.
So we are going to use OpenAI again.
And we want to use the same model as in the previous node.
So let's keep it simple like that.
Then we want to provide the actual text we want to classify.
So the body email which is uh which as you can see.
We close in the text variable.
So we are looking for a text field and we need to drop it like that.
Okay, great.
Now we are gonna add categories with short descriptions like in this example.
So add category.
And the first one will be service request.
And the description.
Sorry this one questions about services offered or availability.
We're just going to copy and paste it.
Now let's jump into my gmail inbox and create libraries so it will be easier for you to visualize.
Visualize how it works.
Now we are inside my Gmail inbox, so let's add the corresponding labels so the AI can classify our
emails.
So the first one was a.
Service requests consultation requests also in payments and others.
So let's do it one by one.
So the first one is service requests.
Service requests.
You can also change the color of the label.
So let's say you want it to be green.
The next one consultation.
Requests.
And I want this one to be read.
Payments.
And others.
Right.
Awesome.
Let's go back to 2010.
So the first one was services requests.
Now let's add consultation request.
And as a description.
Or follow up meetings.
Let's expand it.
Yep.
The next one.
Payments.
Questions about invoices.
Payments or refunds?
Of course, you can create your own descriptions and your own categories.
It's completely up to you what categories you want.
So we have here questions about invoices payments or refunds.
And the last one orders.
So emails that don't clearly fit into the other categories.
All right.
Awesome.
Now we need to add the system prompt to guide AI.
What exactly we want to achieve.
You can leave it as it is.
I like it.
So the next step is to add Gmail nodes to apply labels to the incoming emails based on how they have
been classified.
So for example, if an email is classified as a service request.
Like here.
We want to add the service request label to it in Gmail.
Right.
So since we have already created these labels in Gmail, you should be able to select them directly
in the node.
So let's add Gmail node.
And we want to add label to message.
And when we connect the correct Gmail inbox.
So in my case it will be this one.
The label we just created in our Gmail inbox should pop up here.
So this one is a service request.
Right?
So.
Let's.
Yeah.
It's here.
All right.
Great.
Now we need to add message ID.
So let's go back to our team data node.
And you have closed the message ID in this field in this variable.
So let's copy it.
And paste it here.
I've sent an email to myself asking about automation services.
Now please go ahead and send an email to yourself.
And that could be classified as a services request just like I did.
And this will let you test if the AI is classifying the email correctly and help us get some data into
the flow.
And now you can test the workflow.
Alright, we have some bot requests.
Okay, so let's fix it.
Let's drag and drop the message ID.
Variable from here.
Right now should work.
Let's give it another test.
Yeah.
As you can see, we successfully fetch the last email I've sent to myself.
And when I go to and when I check my Gmail inbox, I can see that my last email was labeled correctly.
Services request.
I'm interested in automation services.
Now we need to do exactly the same thing for the rest of the labels, a.k.a. categories.
So let's go to our N810.
Let's add another Gmail note.
At label to message.
This is the action we want to perform.
Now I need to connect my product Gmail account.
And the label we want consultation request.
So let's find it here.
And as the message ID let's copy it.
By the way, the message ID we grabbed from the hidden data node and paste it into this node was not
working properly because I didn't switch to the expression mode, but it is exactly the same name we
specified in this node.
As you can see.
So first we need to switch to the expression node and then after dollar sign JSON dot.
We need to provide the name of the variable.
So now let's do the same for the payments.
Gmail.
Add label to message.
Connect the correct Gmail account.
Payments.
Expression.
You can also type it manually so.
Double curly braces.
JSON.
Message ID.
Yep.
And the last one.
Others.
So.
Gmail Action label to message.
Others.
Expression.
You can also expand it.
JSON.
Message ID.
Great.
Now let's rename this node.
So this is service requests.
Perfume.
This one is consultation requests.
Is going to be payments.
And the last one?
Others.
I'm going to send three separate emails.
So we can test all of them.
So the first one will be.
So in the first one we want to request a consultation then.
Ask some questions about payments and some email unrelated to to the three.
I sent a few test emails to this address to make sure each category gets picked up properly.
So let's have a look.
However, I have a question about a recent invoice I received.
Can you confirm the payment status?
We should classify it as a payment.
We have partnership.
It was moved to others.
Can we have a quick chat?
So interested in consultation.
And I'm interested in automation services.
They.
I classify this image as a service request.
So as you can see, all the images were labeled correctly and sorted into the corresponding categories
we created.
You can check right here.
Order.
And payment and service request.
Okay now let's go back to ten.
And let's create.
Now the last step to complete this setup and fully automate our email flow is to send a replay to new
emails.
So we want the AI to respond right away, even if a simple message confirming that we get back to the
customer soon.
So that alone can make a big difference in the customer experience.
So again we need to use Gmail node.
Let's search for Gmail.
But this time we want to reply to a message.
So going to be this this action.
Dissection.
Make sure you are connected to the same Gmail account.
As the resource we have message as operation Reply.
We want to change email type to text.
Now here we want to include the actual message.
But first let's add message ID.
So it will be the same as in the previous node.
Let's copy it.
Let's switch to expression and paste here.
All right.
Great.
Now I'm going to paste the message I have prepared earlier and show you how it looks like.
So let's switch to the expression and then expand it.
So for the services request I want I to reply like that.
Thank you for reaching out to adaptive AI.
We are excited to learn about your needs and how we can assist you.
Your inquiry has been received and a member of our team is reviewing the details.
We'll get back to you within the next 24 hours with more information.
In the meantime, feel free to explore our website or additional details about our services and contact
with us via WhatsApp.
And we look forward to connecting with you.
Best regards.
Damien, the founder and CEO at adaptive AI.
You also want to include the intro as a dynamic variable.
It should be included in the Clean Data node.
Is this one.
So let's drag and drop it like that.
Perfect.
Now we can close it.
And our message is ready.
So I'm going to show you the messages for the for the rest of the categories.
So let's add Gmail note again.
Reply to message.
You also need to switch email.
Type to text and paste message ID.
Don't forget to switch to the expression mode.
Place it here.
Switch expression.
Also, I'm not sure if I switch to expression in this one.
Yep.
Okay.
So.
I'm going to expand it and paste the actual message.
So this one is slightly different.
To schedule your consultation, please reply to this email with your preferred date and time, or use
our online booking link here.
And I've included my.
I've included the link to my calendar.
Once we receive your preferred time, we'll confirm the appointment or suggest alternative options if
needed.
If you have any specific topics you'd like to discuss during the consultation, feel free to include
them in your reply.
And the last one?
And the last one.
So let's search for Gmail.
Note again.
Gmail reply to a message.
Collect the correct Gmail account.
Email type you want text.
Copy the message ID.
You can also type it manually if you want.
Don't forget to switch over to expression.
Okay, great.
Switch message to the expression mode.
Expand it.
So this is the message I want my automation to send.
If someone has any questions about payments, refunds or anything similar.
So thank you for contacting us regarding your payment billing inquiry.
You have received your message and are working to address your request.
A member of our team will get back to you within two working days to provide the necessary information
or assistance.
This matter is urgent.
Please call us directly at.
Thank you for your patience and for choosing adaptive AI and sign of the Let's rename these nodes so
it's clear what each one is doing.
It will make the workflow easier to understand and maintain later.
So this one um.
Reply to.
Services.
Requests.
This one replies to the consultation requests.
And this one.
Reply to payment.
And.
Related questions.
If you don't want the AI to reply to emails classified as other.
Since we don't really know what the request is about.
Also, just so you know, you can add a human in the loop feature to this system.
That means the automation will generate a draft response and wait for your approval before sending it.
I will show you how to set that up in one of the next lessons.
All right, that's it for this tutorial.
This is a great example of a simple but powerful AI automation that can save you a lot of time.
And of course, you can tweak it however you like.
I just prompt you to add more categories, etc..
Thank you for spending time with me and see you in the next lesson.