# Create a RAG Telegram bot with Google Drive and PostgreSQL: n8n workflow

> Started by another system calling it, and works across Google Drive, Postgres and Telegram.

Source: https://millionrounds.com/workflow/create-a-rag-telegram-bot-with-google-drive-and-postgresql (Millionrounds; every figure on the page links to its filing or article)

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

# Create a RAG Telegram bot with Google Drive and PostgreSQL

Started by another system calling it, and works across Google Drive, Postgres and Telegram. 29 steps, 4 branches, 1 loop or waits: large, and worth reading before you trust it with anything live.

Large

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fcreate-a-rag-telegram-bot-with-google-drive-and-postgresql)

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

**4** Branches: places the flow splits

**1** Loop or waits

**3** Services it connects to

## The flow

Starts it 2 Logic 11 Service 16

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

- 1 **Telegram Webhook** Webhook *Starts it*
- 2 **Google Drive Trigger** Google Drive trigger *Starts it*
- 3 **Get User** Postgres *Service*
- 4 **Download File** Google Drive *Service*
- 5 **User State Router** Code *Logic*
- 6 **Extract Text** Code *Logic*
- 7 **Is New User?** If *Logic*
- 8 **Split Into Chunks** Code *Logic*
- 9 **Register New User** Postgres *Service*
- 10 **Is Verified?** If *Logic*
- 11 **Loop Chunks** Split In Batches *Logic*
- 12 **Send PIN Request** Telegram *Service*
- 13 **Has Text?** If *Logic*
- 14 **PIN Correct?** If *Logic*
- 15 **Embed Chunk** Http Request *Service*
- 16 **Log Ingestion** Postgres *Service*
- 17 **Embed Query** Http Request *Service*
- 18 **No Text Message** Telegram *Service*
- 19 **Mark User Verified** Postgres *Service*
- 20 **Wrong PIN Message** Telegram *Service*
- 21 **Format Chunk Embedding** Code *Logic*
- 22 **Format Query Embedding** Code *Logic*
- 23 **Send Welcome** Telegram *Service*
- 24 **Store Chunk** Postgres *Service*
- 25 **Search Documents** Postgres *Service*
- 26 **Build Prompt** Code *Logic*
- 27 **Ask LLM** Http Request *Service*
- 28 **Send Answer** Telegram *Service*
- 29 **Log Query** Postgres *Service*

## How it's built

- **Starts on:** Another system calling it
- **Steps:** 29, with 4 branches, 1 loop or waits
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** Google Drive, Postgres, Telegram
- **Model:** None. This is plumbing, not judgement

## Questions

What does it need to run?

An n8n account, plus your own Google Drive, Postgres and Telegram accounts. You connect your own accounts after importing it; none are included.

What starts it?

It starts on another system calling it.

Does it use AI?

No. Every step is fixed logic or a call to a service, so it does the same thing every time.

How long does it take to set up?

Take your time. At 29 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 29 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%2Fcreate-a-rag-telegram-bot-with-google-drive-and-postgresql)
- **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.

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

## Workflows like it

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

- [**Detect semantic duplicate website pages with Google Drive** 29 steps · Google Drive, Postgres](https://millionrounds.com/workflow/detect-semantic-duplicate-website-pages-with-google-drive)
- [**Post to Bluesky social with Gmail and Google Drive** 29 steps · Gmail, Google Drive](https://millionrounds.com/workflow/postar-no-bluesky-social-with-gmail-and-google-drive)
- [**Split shared rental utility bills with Postgres and Gmail** 29 steps · Discord, Gmail](https://millionrounds.com/workflow/split-shared-rental-utility-bills-with-postgres-and-gmail)
- [**Automate LinkedIn content creation with OpenAI and Notion** 29 steps · calls a model · Gmail, Google Drive](https://millionrounds.com/workflow/automate-linkedin-content-creation-with-openai-and-notion)
- [**Create faceless videos with Gemini and ElevenLabs** 29 steps · calls a model · Google Drive](https://millionrounds.com/workflow/create-faceless-videos-with-gemini-and-elevenlabs)
- [**GPT-4o, RunwayML, ElevenLabs for Social Media with Gemini** 29 steps · calls a model · Google Drive, Google Sheets](https://millionrounds.com/workflow/gpt-4o-runwayml-elevenlabs-for-social-media-with-gemini)
