Ai
Daniel
No-code Expert, Latenode Ambassador
January 31, 2024
A low-code platform blending no-code simplicity with full-code power šŸš€
Get started free
January 31, 2024
ā€¢
10
min read

Stop replying to email manually! Customer Support AI Assistant on Latenode

Daniel
No-code Expert, Latenode Ambassador
Table of contents

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!

Step 1: Creating Assistant & API key

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:

  1. Give your assistant a name
  2. Give it instructions on how you want it to answer, and some context. We recommend you to ask it to use attached files, ā€˜cause otherwise, it can forget to do it.
  3. Choose a model
  4. Select available tools and add files that the assistant can use. Donā€™t forget to turn retrieval on to make file adding possible.

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!

Step 2: Creating scenario

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.

Scenario breakdown:

  1. Schedule trigger: Activates the scenario at any period of time set.
  2. HTTP-request: Get list messages. This HTTP-request node gets the list of unread messages from our mailbox using a GET request from Google Workspace.
  3. Iterator: Allows to process every element in the array.
  4. HTTP-request: Get messages. Now we use HTTP-request node to get the data from every unread message.
  5. JavaScript node: Creates variables for senders emails and email bodies.
  6. Create Message: Generates a message for the assistant using created variables.
  7. Create Run: Sends this message to bot, generates the answer.
  8. Gmail node: Sends this answer to the user via Gmail.
  9. HTTP-request: Modify message. Marks messages as read.
  10. Create a Thread.Ā 

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:

Authorization token

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ā€.

ā€

Creating a 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.

Schedule trigger

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.

Get list messages

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Ā 

Iterator

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!

Get messages

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ā€.

JavaScript node

Traditionally, click ā€œAdd nodeā€, go to ā€œCodeā€ and choose JavaScript. Hereā€™s the code that you can put here:


export default async function run({ execution_id, input, data }) {
  let headers = JSON.parse(data["{{6.`body`.`payload`.`headers`}}"]); // Corrected the data path
  // from
  const email_from = headers.find((item) => item.name === "From");
  const email_from_value = email_from.value.match(/<([^>]+)>/)[1]; // Use regex to extract email

  // snippet (content)
  const email_content = data["{{6.`body`.`snippet`}}"]; // Corrected the data path

  return {
    "email_from": email_from_value,
    "email_content": email_content
  };
}

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ā€.

Create message

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ā€.

Create Run

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ā€.

Gmail node

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!

Modify messages

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:


{
  "removeLabelIds": ["UNREAD"]
}

Thatā€™s it!

Save the scenario, deploy it, and here you are! You have an AI assistant which can answer customer emails for you!

Conclusion

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:

Related Blogs

Use case

Backed by