Ai
Daniel
No-code Expert, Latenode Ambassador
January 31, 2024
Hey! Daniel from Latenode is here! Email customer support is a very effective way of communicating with users, and it could be much more efficient with a little help from AI!
So, in this article, Iāll show you how to create an AIĀ Assistant that will answer the customer's questions via email, referring to attached files (product documentation in this case)with a detailed step-by-step instruction. All you need is ChatGPT Assistant API and Latenode- low-code automation platform.
By the way, Iāll leave a ready-to-go template of Latenodeās scenario in the end of this article, youāre welcome!
Letās start!
That is simple. Log into your OpenAI account, then go to assistants, and click the ācreateā button in the upper right corner. Youāll see the assistant's settings panel.
Here you need to:
The text file weāve added contains the first chapter of Latenode documentation. We simply converted it from HTML to text, no editing. AI doesnāt need it, so do we then. Copy the assistantās ID (you see it under the Name column), then go to API keys, create one and save it.
Now itās time for some automations!
Now we switch to Latenode.com. Here, we have to create this scenario: (You don't need to create it from scratch, just copy the template at the end of the article)
It looks for unread emails, sends their content to Assistant, and then sends generated answers to the users via Gmail. Letsās break it down step-by-step to make things clearer.
As you can see, it is separated from the main scenario. Thatās ācause weāll execute this action only once. Yes, OpenAI recommends creating a new thread for every new conversation, but if you have a great number of requests, it is just cheaper to do it once. If you want, you can just put this node between JavaScript and Create Message node.
Webhook triggers are optional - you can add it if you want to activate the scenario out of schedule.
And now letās see how to make it step-by-step:
Before creating a new scenario on latenode.com, we need to go to Authorizations, and create a new one. Search for āgoogleā here, and then choose Gmail. Then pass the registration using the email address where your users will send their questions to. Youāll get an access token that weāll use in our HTTP-request.
Then go to scenarios and create a new one. Right after that, youāll have to click āadd nodeā and add the first node. That will be ācreate Threadā.
ā
Letās start building this scenario by adding a ācreate Threadā node and activate it using the ārun onceā button inside of this node. Click āadd nodeā, then choose ChatGPT, there will be a list of available actions, ācreate threadā is what weāre searching for. All you have to do inside of this node is to insertĀ your OpenAI API key in the authorization column, and click run once after that. That will save the changes and generate a thread ID. Youāll see it in the output of this node.
Click āadd nodeā, go to tools and choose schedule in the trigger section. In nodeās settings, set the period of time your scenario will be activated at, choose the timezone and save the changes.
Now, itās time for some HTTP-request.
Again, click add node, search for HTTP and choose it. Here we need to take the URL from Google Workspace and put it in the URL field of the node.Ā
Put the needed email address instead of {userId}, and add ?q=is:unread in the end, so youāll get a list of unread messages only.Ā
Set get as a method.Ā
Then, add entry in headers, with āAuthorizationā as a key, and āBearerā as value.Ā
Then click on the Value field and add the authorization token youāve created. Youāll see it in the pop-up window if you click on the authorizations tab in it, and choose āgoogleā.Ā
Finally, click run once. That will save the changes, test the node, and send data through it. Youāll seeĀ
To add an iterator, click add node, then go to tools and choose the iterator in the action section.
It has only one field in settings, here you have to put messages array from the previous node.
Click on this field and choose the āmessagesā object in the helper widget. Donāt forget to click ārun onceā after that!
Add HTTP-request once more. This time, we can just copy the previous HTTP-request node (right-click on the node, copy. Then right click on empty space and paste) and change it a bit.
Again, use Google Workspace to fill out the URL field. Here you also have to replace {userId} with your email address. Put an ID object from the Iterator right after āmessagesā. Youāll see it in the Helper widget. At the end, the URL should look like this:
https://gmail.googleapis.com/gmail/v1/users/[email protected]/messages/{{$7.value.id}}
In addition to the first key-value pair, add the second one, with Content-Type as a value and application/JSON as a key. And of course, click ārun onceā.
Traditionally, click āAdd nodeā, go to āCodeā and choose JavaScript. Hereās the code that you can put here:
Reminder: Itās ready to use, you only have to change the number of previous node there.
But for the future, youĀ can use an AI assistant in this node that can help you with coding. Hereās a short article about it to set your AI Copilot using skills to a new level! After the code is ready, click ārun onceā.
Search for ChatGPT after you click on āadd nodeā, and you see it. To set up this node, insert your OpenAI API key in the authorization field, Thread ID from ācreate Threadā nodeās output. Put the email body object from the iterator into the message content field. After that, click ārun onceā.
In this node you also have to Insert OpenAI API key and Thread ID, but also your Assistant ID, choose the model version, and select ātrueā in the Retrieval field. And click ārun onceā.
Select Gmail āsend messageā node in the app list. To set it up, you need to select your connection token for the needed email address. Then, put email_from variable from the JS node in the āToā field. Email Body field should be filled with text value from the Create Run node. Also, you can add here fixed text. Check the other fields for further customization. Weāre almost finished!
Put this request from Google WorkspaceĀ in the URL field. Again, should be your email address, - valueID from Iterator. Method is POST here. Create the same key-value pair like in the previous node. Choose raw format of the body and insert this:
Thatās it!
Save the scenario, deploy it, and here you are! You have an AI assistant which can answer customer emails for you!
Now you know how to create your own personal assistant who will answer user questions. Just as I said, this scenario is available as a template in Latenodeās template library, so, check this out!
If you have any questions, or facing troubles during your automation journey, Iām happy to let you know that Latenode has its Discord Channel, where you always can get some help from our team and growing community of low-code and automation enthusiasts.
ā
Related articles: