paint-brush
Using an API to Return a Daily Poem in Telegram to Celebrate World Poetry Dayby@lorena
362 reads
362 reads

Using an API to Return a Daily Poem in Telegram to Celebrate World Poetry Day

by LorenaMarch 22nd, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Learn how to create an automated workflow with n8n that gets international poems, translates them into one language, and sends a poem in Telegram every day.

Company Mentioned

Mention Thumbnail
featured image - Using an API to Return a Daily Poem in Telegram to Celebrate World Poetry Day
Lorena HackerNoon profile picture

March 21st is World Poetry Day, a day dedicated to one of the most treasured ways of expression around the world and linguistic diversity. I have always loved reading poetry with creative rhymes and melodic rhythm, and lately, I have come to appreciate free verse poetry as well. In any case, I would like to make time to read more poetry and discover new international poets. To achieve this goal, I created an n8n workflow that sends a poem translated into Romanian in my Telegram chat every day. In this article, I’ll show you how to set it up.

Workflow

If this is your first n8n workflow, have a look at our quick start guide first to learn how to install n8n. Once you have your n8n Editor UI open, there are two ways to follow this tutorial: either copy the workflow from here into your Editor UI and deactivate the nodes, so that you can execute and test each node separately, or add the nodes one at a time.

This workflow consists of four nodes:

1. Cron node: triggers the workflow every day at 10:00. You can change the time and interval based on your use case.

2. HTTP Request node: makes an HTTP request to the Poemist API that returns random poems.

3. LingvaNex node: translates the returned poems into Romanian. You can choose from over 100 languages.

4. Telegram node: posts the translated poems in the chat.

Now let’s see how to set up each node.

1. Set the time

First, you need to set the time and interval at which you want to receive poems in the chat. For this, set up the Cron node, where you can choose from seven modes and set the exact hour and minute. For this example, the workflow will be triggered every day at 10:00.

2. Get the poems

Now, you need to get the poems. For this, set up the HTTP Request node to get data from Poemist. Paste the Poemist URL and execute the node to test that it’s working.

3. Translate the poems

The Poemist API includes poems in different languages, which on one hand is great for linguistic diversity, but on the other hand, it can be challenging if you don’t know the language.

To make sure you can read all poems, translate them into a language of your choice using the LingvaNex node. For this, you need to sign up on LingvaNex to get credentials. You can find detailed instructions here. Copy your credentials in LingvaNex API, then set Translate to Romanian (or any other language you prefer).

In the Text field, select:

The title: Current Node > Input data > JSON > 0 > title

The author: Current Node > Input data > JSON > 0 > poet > name

The poem: Current Node > Input data > JSON > 0 > content

Now execute the node to test that it’s working.

4. Send poems to Telegram

Finally, you need to send the requested poems to your Telegram chat. In your Telegram account, start a chat with Botfather and follow the instructions to create a bot and get credentials. Then, go to the Telegram node and add the credentials to Telegram API.

Next, you need to fill in the Chat ID of the newly created bot. There are two ways to get your Telegram Chat ID: with the Telegram Trigger node or with a Telegram bot. You can find instructions for both methods here.

After completing the Chat ID, you need to set up the text you want to send to the chat. Open the Text field and select the poem translation from Current node > Input Data > JSON > result. You can add more text or emojis to prettify the message.

Now execute the whole workflow and check your Telegram for an incoming message:

Finally, save and activate the workflow, so that it runs every day at the scheduled time.

Next steps

That was it! Now you know how to get international poems, translate them, and send them to a Telegram chat to get your daily dose of poetry. If you run into issues while following this tutorial, you can message me on Twitter or ask for help in our community forum.