PRICING
PRODUCT
SOLUTIONS
by use case
learn more
TemplatesBlogVideosYoutubeRESOURCES
COMMUNITIES AND SOCIAL MEDIA
PARTNERS
In this article, we will set up a script in Latenode to send an email to a travel agency client who has just booked a tour.
The scheme of such a scenario is simple: we know about the client his gender, age, from which city and to which city he is planning a trip. Based on these data, we will prepare an email text to tell him where to go and what to see when he arrives in town. Here's an example of the text that ChatGPT will prepare:
Welcome to the charming city of Limassol, Cyprus! As a winter tourist, there are plenty of things for you to see and do during your stay. When it comes to places to see, the top three must-see attractions are: The Limassol Castle, a medieval castle located in the heart of the city. The castle is a great place to learn about the city's rich history and also offers great views of the city and the sea. The Limassol Marina, a beautiful marina that offers a variety of shops, restaurants, and bars. It's a perfect place to take a walk, have a meal or a drink and admire the boats. The Limassol Old Town, a charming neighborhood filled with traditional architecture, quaint shops, and cozy cafes. This is a perfect place to stroll around and get a feel for the local culture. As for activities to do, the top three recommendations are: Visit the Limassol Archaeological Museum, which houses a vast collection of artifacts that shed light on the island's rich history and culture. Take a wine tour of the Limassol region, where you can sample the local wines and learn about the island's wine-making tradition. Visit the Limassol salt lake, which is a great place for birdwatching and also offers beautiful views of the city. Limassol is a city with a lot to offer and these are just a few of the many things you can see and do during your visit. Enjoy your stay in Limassol, and don't hesitate to ask locals for recommendations as they will be more than happy to help you discover the hidden gems of their city.
First, let's check the list of what we need to create a chain: a ChatGPT account and its Personal key, as well as the Mailgun account and its Private API Key;
Personal key in ChatGPT can be viewed or created here in the profile settings:
The Mailgun API key is also in the settings in the profile:
The first thing we do, as always, is to create a node: "+ Add Node" => "Http" => "Webhook";
Let's copy its address at once;
Save your changes;
Let's also prepare a request for a rest client (Postman, Insomnia):
Change the Webhook link to yours;
Next, substitute in personalTokenChatGPT your key from ChatGPT;
Next, put in apiKeyMailgun your key from Mailgun;
Also change the email to your test email, so if you have a free Mailgun plan you can send only to the email you specified when registering;
The rest you can change at will;
Create a new node: "+ Add Node" => "Code" => "JavaScript";
Insert the content into it:
Save;
Bind the nodes together;
Start and call the chain to transfer data between the nodes;
Let's open the "JavaScript" node settings again;
Check all the constructions like "data["{{1.body.personGender}}"]" that the number of the Webhook corresponds to the one from which we receive data, if not replace it with the required one (remember, 1 is the number of the node written under the node name, then if it is a query then you have to choose the object field responsible for the type of sent/received data - body for forms or query for query parameters);
Next, create an "Http request" node that will make a request to generate sentences based on text parameters from the message variable in the JS node;
Create node: "+ Add node" => "Http" => "HTTP request";
Save;
Let's link the nodes together;
Start and call the chain to transfer data between the nodes;
Let's form the "Url" field: at the beginning we'll substitute the variable "apiChatGPT" from the "JavaScript" node, and after it we'll specify /completions;
Read more about this and other calls in ChatGPT API at the end of this article;
Let's change the method to "POST";
In "raw", let's substitute the variable from the first "JavaScript" node;
In the Headers we are going to add two:
- Content-Type with value: application/json
- Authorization, in the value select a variable from the "JavaScript" node with the name: personalTokenChatGPT
Let's save the changes;
Add a "Webhook response" node to return the ChatGPT-generated text in the response: "+ Add Node" => "Http" => "Webhook response";
Save;
Bind the nodes together;
Start and call the chain to transfer data between the nodes;
Let's add the response received from the previous node "Http request", don't forget to specify the index between the square brackets;
Let's save the changes;
Last let's add one more node "Http request" to send the generated ready marketing offers through Mailgun: "+ Add node" => "Http" => "HTTP request";
Save;
Bind the nodes together;
Run and call the chain to transfer data between the nodes;
Next, let's go to the Mailgun website to the section: "Sending" => "Overview";
Copy the ready-made CURL code:
Paste it into the "Http request" via "Create from example (CURL)":
Then copy the key and domain from the Mailgun site somewhere, like a notepad;
In the Url we first put the apiMailgun variable from the first "JavaScript" node, then /your domain in Mailgun/, at the end /message;
Change the method to "POST";
In the body we will select the tab "form-data";
In the body we'll do everything like in the screenshots below:
- from: Mailgun Sandbox <postmaster@your domain in Mailgun>;
- To: your test mailbox to test, select the "JavaScript" node variable clientEmail, put it inside <>;
- subject: Time to trip?;
- text: variable from the "Webhook response" node received text after generation;
Below in the "Authorization" block by the "Password" field, insert the apiKeyMailgun variable from the first "JavaScript" node;
Save the changes;
Let's start a full chain and call it;
After that you should get a letter with the generated text to the email address you specified, check your spam folder if you haven't found it in your inbox;
Thanks for your attention, see you in new articles, there will be another one on ChatGPT! 😉