I’m building a Telegram-to-OpenAI translation workflow in n8n. Here’s what happens:
A user sends a long Arabic text to the bot.
Telegram automatically splits it into multiple messages (e.g., per paragraph).
In n8n, each split reaches the Telegram Trigger, which triggers multiple workflow executions.
The messages often get translated and replied in the wrong order — e.g., paragraph 3 replies before paragraph 1.
How can I solve this please help me find the perfect way!
I am working on the cloud, and with version 1.110.0
These are my workflow nodes( Telegram Trigger → OpenAI (Assistant) → Telegram Send Message)
As far as I know, there isn’t a build-in telegram thing or an easy way to tell whether a user’s message is just a single one, or if it was originally a long message that got split into multiple messages (max 4096 characters).
To solve this, I think you’ll need an additional layer (database) to store some metadata specifically the update_id, message_id, date.
With that information, each incoming message can be analyzed to determine whether it’s a standalone message or part of a larger one..
Based on this logic, you can then handle the message properly before passing it to the AI, and after process it successfully.
Hi @mohamed3nan Thank you for your reply.
I was thinking of some kind of using a database, but all the examples or resources i checked were using redis. So I am thinking if there is a way to solve this without a need to use and pay for a cloud db.
I think you can start with Supabase or even Google Sheets first to test the logic.
The whole issue really comes down to the logic that will determine whether the incoming message is:
Who it’s coming from
A standalone message or part of a long message
Honestly, this problem is quite unique, it’s the first time I’ve ever encountered it for real.
But something just came to my mind that we could say if you’re not ready to deal with the idea above yet:
You could add an option in the bot asking the user whether the message they’re about to send is longer than 4096 characters or shorter.
Then, you can redesign the workflow to handle this case, and in that scenario, you might not even need a database.
You can add system prompt to the AI Agent to ‘split’ each 4096 char or less, add -cuttext- to each 4096 or less chars.
After that, do simple split('-cuttext-) with code node, it will shows array, you can use that for looping
The issue comes from Telegram!
Telegram automatically splits a message into multiple parts (message) if it exceeds 4096 characters.
This means you’ll get more than one trigger for each part of the message.
Although the parts are ordered, if one execution finished before another, the overall order may appear incorrect.
I will check this thanks alot.
The idea of checking with the user about the length of the text would be not recommended, cause my goal with this workflow is to make there work easier just copy paste, that is why i want to make it user friendly, accurate and with less steps possible
I imagine the logic should be about determining whether the message is standalone or part of a long message based on the date
I noticed that the messages that were originally one message but then got split into multiple messages usually share the same date time.
So, if you take that into account along with the message_id(for orders), you can figure out whether the message is standalone or fragmented.
That’s why I think you’ll need 2 triggers/workflows:
One that listens to the Telegram messages and saves them into the database.
The other listens to the messages being saved in the database, then reprocesses and passes them along in the correct way to OpenAI then to the telegram user again..