Automate Email Responses with AI on Latenode

Introduction

Discover how to automate email responses using AI on the Latenode platform. This tutorial shows you each step required to create a scenario that generates draft replies based on incoming emails. Check the description for a link to the ready-made template in the shared template section, making it even easier to get started.

Creating a New Scenario

As an example of using AI nodes, let's create a scenario that triggers when receiving a new email. The result of executing this scenario will be a draft reply email with text automatically generated by AI. To start, click the Add New Scenario button. It's best to name any new scenario and save the changes.

Adding a Trigger Node

In the scenario, you need to add a trigger node so that some event can initiate its launch—in our case, the arrival of a new email. On the Triggers tab, we’ll select Gmail and choose the needed node. To configure the Gmail node, perform authorization by clicking the New Authorization button and selecting the service. Use an existing Google account to complete the authorization itself, allowing all accesses on the Latenode platform.

Once authorization is complete, fields for configuration appear in the node. If necessary, select a label, for example, Unread. Save the changes. Now, the scenario will be triggered when receiving a new email that is still unread.

Setting Up Variables

In any AI model, instructions are needed for generation, and they can change. Let’s create several variables directly in the scenario. Add an action node of the Set Variables type, which serves to add new variables to the scenario and use them within the same scenario. We’ll add three variables: message length, the role of the user responding, and message format.

Assign values to these variables. For instance, we know in advance that we need to generate a reply email text one paragraph long. The reply should come from the perspective of a manager and be in a business format. Save the changes in the scenario.

Classifying the Text

We can classify the text to determine if there’s a question in it, forming one or another variant of the response accordingly. However, a response variant should always be formed. Add two nodes for text generation; each node should connect to the Set Variables node for the scenario to execute along one route or another.

Next, configure the routes along which the scenario will execute. To do this, get data from previous nodes by running the node once and sending a test email. Check the mailbox to ensure the test email has arrived, and return to the scenario. Wait for the node to execute; now you have information about the email, including its brief content and the sender's information.

Configuring Routes and Nodes

Run the Set Variables node once as well. The output parameters are the variables and their values. Now, using the output data from these two nodes, configure the routes and the text generation nodes.

Configure the lower route first. The scenario will execute along this route if the conditions added in the condition field are true. In our case, if the result of executing this expression is the word true. Use a special operator to set up the conditions, which also allows asking various questions to AI and getting answers based on the data from the previous node. Highlight them with pluses and quotes to ensure the data is considered correctly. Name the route and save it.

For the scenario to execute along one route or another, copy the conditions and add them to the upper route. Change the equals operator to the not equals operator. Thus, if the expression in parentheses executes and the result equals anything but the word true, the scenario will follow the upper route. Name this route and save the changes.

Text Generation Nodes Configuration

Begin configuring the text generation nodes by giving instructions to the node that will generate a response to a question in the email. Select the model and fill in the user prompt field. Request generating a response to the email question, indicating that the answer is being prepared and will be announced soon as the email recipient. Specify the responder’s role, email format, and length, as defined in the variables. Save the settings.

Move on to configuring the second node. Here, ask to generate a draft using the text from the first node. Select the recipient from the first node, keeping the rest of the instructions unchanged since they depend on the variables. Save the changes and the entire scenario.

Generating the Email Draft

Add two more nodes to the scenario to generate an email draft. These are action nodes from the Gmail group Create Draft. Before configuring the node for creating the draft, run the AI nodes once so that the platform receives output data and displays it in the helper windows.

Perform authorization (if it already exists, you can use the existing one). With the AI node data displayed in the helper window, choose the email subject corresponding to the incoming email’s subject. Select the response text content from the third node, choose the recipient, and save the changes. Add a second node for another draft generation (Gmail group's reply draft generation node). Perform authorization, select the subject, and provide the email body. If necessary, run the AI node again to update its data.

Select the message ID to which you need to reply. Choose the placement method and the corresponding value from the first node. Click Save. Ensure all required fields are filled and save the scenario. To run the scenario without manually pressing the one-time launch button, perform a deploy. The scenario is now automatically active and will launch when a new email is received.

Testing the Scenario

Check the launch lines in the scenario history to confirm. Send a test email. The test email should arrive in the mailbox and be classified as interrogative based on its content. If successful, a draft is created, containing the subject and text that acknowledges the question and states that an answer will be given soon.

Send another test email of a congratulatory nature. Mark it as unread to trigger the scenario. Check the scenario's execution history to see if it classified this email correctly. If successful, a draft is created with a response to the positive review, including a simple subject and the correct recipient information. Thus, the scenario successfully classifies incoming emails and generates the necessary responses.

Conclusion

Create advanced automations with flexible logic and an AI assistant with JavaScript and a headless browser for ultimate control using Latenode. Save up to 30 times compared to other competitors. Registration is straightforward—sign up today with no credit card required and start creating automations that save you time and money. Transform your workflow with Latenode.

Other Videos