Automation library · Chat assistants

Telegram bot reply email with OpenAI and Postgres

Started by an incoming Telegram message, and works across Email, Postgres and Telegram. It hands the judgement calls to OpenAI. 27 steps, 1 branch: large, and worth reading before you trust it with anything live.

LargeCalls a model: OpenAI

27 stepsLarge: read it before trusting it with anything live
1Branch: places the flow splits
0Loops or waits
3Services it connects to

The flow

Starts it 1Model 2Logic 6Service 18

The steps in the order they run, from what starts it.

  1. 1Email Trigger (IMAP)Email Read ImapService
  2. 2OpenAI Chat ModelLm Chat Open AiModel
  3. 3Telegram TriggerTelegram triggerStarts it
  4. 4Save Draft Text1PostgresService
  5. 5Code clear textCodeLogic
  6. 6AI AgentAgentModel
  7. 7Determine ActionFunctionLogic
  8. 8Telegram Preview (HTTP)Http RequestService
  9. 9Postgres Save EmailPostgresService
  10. 10TelegramBot_mailTelegramService
  11. 11Route ActionSwitchLogic
  12. 12Postgres Get UnrepliedPostgresService
  13. 13Get Email DetailsPostgresService
  14. 14Get Active SessionPostgresService
  15. 15Check ConfirmationFunctionLogic
  16. 16Build Inbox KeyboardFunctionLogic
  17. 17Init SessionPostgresService
  18. 18Save Draft TextPostgresService
  19. 19Get Email for SendingPostgresService
  20. 20Telegram Send List1Http RequestService
  21. 21Send Preview1TelegramService
  22. 22Telegram Preview mailHttp RequestService
  23. 23Get Draft ContentPostgresService
  24. 24Construct EmailFunctionLogic
  25. 25Send Email (SMTP)Email SendService
  26. 26Mark Replied & Clear SessionPostgresService
  27. 27Notify SentTelegramService

How it's built

Starts on
An incoming Telegram message
Steps
27, with 1 branch
Size
Large: read it before trusting it with anything live
Connects to
Email, Postgres, Telegram
Model
OpenAI

Questions

What does it need to run?

An n8n account, plus your own Email, Postgres and Telegram accounts, and a key for OpenAI. You connect your own accounts after importing it; none are included.

What starts it?

It starts on an incoming Telegram message.

Does it use AI?

Yes. It calls OpenAI. Model calls are billed by the provider, not by n8n.

How long does it take to set up?

Take your time. At 27 steps it is large: read it before trusting it with anything live.

How do I import it?

Copy the workflow, open a new workflow in n8n and paste. The steps appear on the canvas, ready for your own accounts.

Before you run it

Nothing here has been tested by us. It is somebody's working automation, read and described from its own steps. Treat the connections it wants as a list of accounts it will touch, and read the 27 steps before you point it at anything that matters.