# Telegram bot reply email with OpenAI and Postgres: n8n workflow

> Started by an incoming Telegram message, and works across Email, Postgres and Telegram. It hands the judgement calls to OpenAI.

Source: https://millionrounds.com/workflow/telegram-bot-reply-email-with-openai-and-postgres (Millionrounds; every figure on the page links to its filing or article)

[Automation library](https://millionrounds.com/workflows) · [Chat assistants](https://millionrounds.com/workflows?category=Chat+assistants#library)

# 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.

Large Calls a model: OpenAI

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Ftelegram-bot-reply-email-with-openai-and-postgres)

**27 steps** Large: read it before trusting it with anything live

**1** Branch: places the flow splits

**0** Loops or waits

**3** Services it connects to

## The flow

Starts it 1 Model 2 Logic 6 Service 18

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

- 1 **Email Trigger (IMAP)** Email Read Imap *Service*
- 2 **OpenAI Chat Model** Lm Chat Open Ai *Model*
- 3 **Telegram Trigger** Telegram trigger *Starts it*
- 4 **Save Draft Text1** Postgres *Service*
- 5 **Code clear text** Code *Logic*
- 6 **AI Agent** Agent *Model*
- 7 **Determine Action** Function *Logic*
- 8 **Telegram Preview (HTTP)** Http Request *Service*
- 9 **Postgres Save Email** Postgres *Service*
- 10 **TelegramBot_mail** Telegram *Service*
- 11 **Route Action** Switch *Logic*
- 12 **Postgres Get Unreplied** Postgres *Service*
- 13 **Get Email Details** Postgres *Service*
- 14 **Get Active Session** Postgres *Service*
- 15 **Check Confirmation** Function *Logic*
- 16 **Build Inbox Keyboard** Function *Logic*
- 17 **Init Session** Postgres *Service*
- 18 **Save Draft Text** Postgres *Service*
- 19 **Get Email for Sending** Postgres *Service*
- 20 **Telegram Send List1** Http Request *Service*
- 21 **Send Preview1** Telegram *Service*
- 22 **Telegram Preview mail** Http Request *Service*
- 23 **Get Draft Content** Postgres *Service*
- 24 **Construct Email** Function *Logic*
- 25 **Send Email (SMTP)** Email Send *Service*
- 26 **Mark Replied & Clear Session** Postgres *Service*
- 27 **Notify Sent** Telegram *Service*

## 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.

## Run it in n8n

- **Create your n8n account** Free to start. n8n is where the workflow runs. [Create an n8n account ↗](https://millionrounds.com/n8n)
- **Download the workflow** Free with a Millionrounds account. [Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Ftelegram-bot-reply-email-with-openai-and-postgres)
- **Paste it into n8n** Open a new workflow in n8n and paste. Then connect your own accounts.

Stored with the author's traces removed: canvas notes, instance identifiers, saved credential names and any live document they had left behind.

## Connects to

Each opens the other workflows that use it.

[Email](https://millionrounds.com/workflows?service=Email#library)[Postgres](https://millionrounds.com/workflows?service=Postgres#library)[Telegram](https://millionrounds.com/workflows?service=Telegram#library)

## Workflows like it

Also chat assistants, with the same services where possible, closest in size first.

- [**ASMR YouTube shorts automation with Claude and Gmail** 27 steps · calls a model · Gmail, Google Sheets](https://millionrounds.com/workflow/asmr-youtube-shorts-automation-with-claude-and-gmail)
- [**Create & upload AI-generated ASMR YouTube Shorts with Seedance** 27 steps · calls a model · Gmail, Google Sheets](https://millionrounds.com/workflow/create-and-upload-ai-generated-asmr-youtube-shorts-with-seed)
- [**Create ASMR YouTube Shorts with OpenAI and Wavespeed Seedance** 27 steps · calls a model · Gmail, Google Sheets](https://millionrounds.com/workflow/create-asmr-youtube-shorts-with-openai-and-wavespeed-seedanc)
- [**Nano Banana/Gemini 2.5 Telegram bot with OpenAI** 27 steps · calls a model · Telegram](https://millionrounds.com/workflow/nano-banana-gemini-2-5-telegram-bot-with-openai)
- [**Proxmox AI agent with Gemini and Gmail** 27 steps · calls a model · Gmail, Telegram](https://millionrounds.com/workflow/proxmox-ai-agent-with-gemini-and-gmail)
- [**Voice notes into business reviews with Groq Whisper and OpenAI** 27 steps · calls a model · Gmail, Google Drive](https://millionrounds.com/workflow/voice-notes-into-business-reviews-with-groq-whisper-and-open)
