# Build a chatbot with RAG: n8n workflow template

> Started by an incoming Telegram message, and works across Google Docs and Telegram. It puts OpenAI behind a retrieval step, so answers are drawn from...

Source: https://millionrounds.com/workflow/build-a-chatbot-with-rag (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)

# Build a chatbot with RAG

Started by an incoming Telegram message, and works across Google Docs and Telegram. It puts OpenAI behind a retrieval step, so answers are drawn from documents you supply rather than from the model alone. 23 steps: large, and worth reading before you trust it with anything live.

Large Calls a model: OpenAI Retrieval

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fbuild-a-chatbot-with-rag)

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

**0** Branches: places the flow splits

**0** Loops or waits

**2** Services it connects to

## The flow

Starts it 2 Model 17 Logic 2 Service 2

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

- 1 **OpenAI Chat Model** Lm Chat Open Ai *Model*
- 2 **Embeddings OpenAI** Embeddings Open Ai *Model*
- 3 **Document Chunker** Text Splitter Recursive Character Text Splitter *Model*
- 4 **OpenAI Embeddings Generator** Embeddings Open Ai *Model*
- 5 **When clicking "Execute Workflow"** Manual trigger *Starts it*
- 6 **MongoDB Chat Memory** Memory Mongo Db Chat *Model*
- 7 **Embeddings OpenAI1** Embeddings Open Ai *Model*
- 8 **Recursive Character Text Splitter** Text Splitter Recursive Character Text Splitter *Model*
- 9 **Embeddings OpenAI3** Embeddings Open Ai *Model*
- 10 **Receive Message on Telegram** Telegram trigger *Starts it*
- 11 **OpenAI Embeddings Generator1** Embeddings Open Ai *Model*
- 12 **Knowledge Base Agent** Agent *Model*
- 13 **Search Documentation** Vector Store Mongo DBAtlas *Model*
- 14 **Document Section Loader** Document Default Data Loader *Model*
- 15 **MongoDB Documentation Inserter** Vector Store Mongo DBAtlas *Model*
- 16 **Google Docs Importer** Google Docs *Service*
- 17 **Search Positive Interactions** Vector Store Mongo DBAtlas *Model*
- 18 **Default Data Loader** Document Default Data Loader *Model*
- 19 **Search Negative Interactions** Vector Store Mongo DBAtlas *Model*
- 20 **Submit embedded chat feedback** Vector Store Mongo DBAtlas *Model*
- 21 **Send Message on Telegram, Wait for Feedback** Telegram *Service*
- 22 **Map feedback data** Code *Logic*
- 23 **Set feedback fields for collection storage** Set *Logic*

## How it's built

- **Starts on:** An incoming Telegram message
- **Steps:** 23
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** Google Docs, Telegram
- **Model:** OpenAI
- **Retrieval:** Answers are drawn from documents you supply, not from the model alone

## Questions

What does it need to run?

An n8n account, plus your own Google Docs 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. Its answers draw on documents you give it, not on the model alone. Model calls are billed by the provider, not by n8n.

How long does it take to set up?

Take your time. At 23 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 23 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%2Fbuild-a-chatbot-with-rag)
- **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 Docs](https://millionrounds.com/workflows?service=Google+Docs#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.

- [**Access control for AI agents (RBAC) with Airtable and Telegram** 23 steps · calls a model · Airtable, Telegram](https://millionrounds.com/workflow/access-control-for-ai-agents-rbac-with-airtable-and-telegram)
- [**Conversational AI Chatbot with Gemini and Image** 23 steps · calls a model · Telegram](https://millionrounds.com/workflow/conversational-ai-chatbot-with-gemini-and-image)
- [**Create AI Instagram Reels with OpenAI and Veo3** 23 steps · calls a model · Google Sheets, Slack](https://millionrounds.com/workflow/create-ai-instagram-reels-with-openai-and-veo3)
- [**End of turn detection for smoother AI agent chats** 23 steps · calls a model · Redis, Telegram](https://millionrounds.com/workflow/end-of-turn-detection-for-smoother-ai-agent-chats)
- [**Generate stock trading signals with Gemini and TwelveData** 23 steps · calls a model · Telegram](https://millionrounds.com/workflow/generate-stock-trading-signals-with-gemini-and-twelvedata)
- [**Save at-risk churn customers with OpenAI DeepSeek and Airtable** 23 steps · calls a model · Airtable, Gmail](https://millionrounds.com/workflow/save-at-risk-churn-customers-with-openai-deepseek-and-airtab)
