# Create a session-based Telegram chatbot with OpenAI: n8n workflow

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

Source: https://millionrounds.com/workflow/create-a-session-based-telegram-chatbot-with-openai (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)

# Create a session-based Telegram chatbot with OpenAI

Started by an incoming Telegram message, and works across Google Sheets and Telegram. It puts OpenAI behind a retrieval step, so answers are drawn from documents you supply rather than from the model alone. 31 steps, 2 branches: 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%2Fcreate-a-session-based-telegram-chatbot-with-openai)

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

**2** Branches: places the flow splits

**0** Loops or waits

**2** Services it connects to

## The flow

Starts it 1 Model 7 Logic 8 Service 15

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

- 1 **OpenAI Chat Model** Lm Chat Open Ai *Model*
- 2 **Simple Memory** Memory Buffer Window *Model*
- 3 **Get message** Telegram trigger *Starts it*
- 4 **OpenAI Chat Model1** Lm Chat Open Ai *Model*
- 5 **OpenAI Chat Model2** Lm Chat Open Ai *Model*
- 6 **Telegram Chatbot** Agent *Model*
- 7 **Get session** Google Sheets *Service*
- 8 **Summarization Chain** Chain Summarization *Model*
- 9 **Basic LLM Chain** Chain Llm *Model*
- 10 **Send response** Telegram *Service*
- 11 **Command or text?** Switch *Logic*
- 12 **Send summary** Telegram *Service*
- 13 **Send answer** Telegram *Service*
- 14 **Update database** Google Sheets *Service*
- 15 **Disable previous session** Google Sheets *Service*
- 16 **Send current session** Telegram *Service*
- 17 **Get message1** Set *Logic*
- 18 **Get session1** Google Sheets *Service*
- 19 **Get message2** Set *Logic*
- 20 **Set new session** Google Sheets *Service*
- 21 **Trim resume** Code *Logic*
- 22 **Prompt + Resume** Code *Logic*
- 23 **Trim question** Code *Logic*
- 24 **Session activated** Telegram *Service*
- 25 **Set to expire** Google Sheets *Service*
- 26 **Response + Text** Google Sheets *Service*
- 27 **Set new current session** Google Sheets *Service*
- 28 **fullText** Code *Logic*
- 29 **Exist?** If *Logic*
- 30 **KO** Telegram *Service*
- 31 **OK** Telegram *Service*

## How it's built

- **Starts on:** An incoming Telegram message
- **Steps:** 31, with 2 branches
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** Google Sheets, 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 Sheets 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 31 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 31 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-session-based-telegram-chatbot-with-openai)
- **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 Sheets](https://millionrounds.com/workflows?service=Google+Sheets#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.

- [**Company knowledge base agent (RAG) with OpenAI** 31 steps · calls a model · Google Drive, Supabase](https://millionrounds.com/workflow/company-knowledge-base-agent-rag-with-openai)
- [**Intake Architect - Multi-Channel Professional Services Client** 31 steps · calls a model · Gmail, Google Sheets](https://millionrounds.com/workflow/intake-architect-multi-channel-professional-services-client)
- [**Record Property Maintenance Issues with Slack** 31 steps · calls a model · Gmail, Google Drive](https://millionrounds.com/workflow/record-property-maintenance-issues-with-slack)
- [**With Gemini and OpenAI** 31 steps · calls a model · Gmail, Google Drive](https://millionrounds.com/workflow/with-gemini-and-openai)
- [**Finance transaction auto record into Notion with OpenAI** 30 steps · calls a model · Notion, Telegram](https://millionrounds.com/workflow/finance-transaction-auto-record-into-notion-with-openai)
- [**Manage safety inspections and corrective actions with DeepSeek** 32 steps · calls a model · Gmail, Google Sheets](https://millionrounds.com/workflow/manage-safety-inspections-and-corrective-actions-with-deepse)
