# Host a Telegram AI bot with a local model and Redis: n8n workflow

> Started by an incoming Telegram message, and works across Redis and Telegram. It puts a local model behind a retrieval step, so answers are drawn from...

Source: https://millionrounds.com/workflow/host-a-telegram-ai-bot-with-a-local-model-and-redis (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)

# Host a Telegram AI bot with a local model and Redis

Started by an incoming Telegram message, and works across Redis and Telegram. It puts a local model behind a retrieval step, so answers are drawn from documents you supply rather than from the model alone. 41 steps, 4 branches, 2 loops or waits: large, and worth reading before you trust it with anything live.

Large Calls a model: a local model Retrieval

[Download free](https://millionrounds.com/login?next=%2Fapp%2Fworkflow%2Fhost-a-telegram-ai-bot-with-a-local-model-and-redis)

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

**4** Branches: places the flow splits

**2** Loops or waits

**2** Services it connects to

## The flow

Starts it 1 Model 5 Logic 11 Service 24

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

- 1 **Redis Chat Memory** Memory Redis Chat *Model*
- 2 **Redis Chat Memory1** Memory Redis Chat *Model*
- 3 **Ollama Chat Model** Lm Chat Ollama *Model*
- 4 **Telegram Trigger** Telegram trigger *Starts it*
- 5 **AI Agent - chat** Agent *Model*
- 6 **AI Agent - pic** Agent *Model*
- 7 **Set user telegram ID** Set *Logic*
- 8 **Hold on a moment to allow redis propagation** Wait *Logic*
- 9 **Send chat answer** Telegram *Service*
- 10 **Retrieve current context** Redis *Service*
- 11 **Set-up the ComfyUI workflow** Code *Logic*
- 12 **Check user id** If *Logic*
- 13 **Reset context clone 2** Redis *Service*
- 14 **ComfyUI HTTP Request - start** Http Request *Service*
- 15 **Create base message format** Set *Logic*
- 16 **clone context** Redis *Service*
- 17 **ComfyUI HTTP Request - check** Http Request *Service*
- 18 **Get body definition** Redis *Service*
- 19 **Check if image has been generated** If *Logic*
- 20 **Get scene definition** Redis *Service*
- 21 **ComfyUI HTTP Request - fetch** Http Request *Service*
- 22 **Check if ComfyUI errored** If *Logic*
- 23 **Send initial typing** Telegram *Service*
- 24 **Send comfy pic** Telegram *Service*
- 25 **Send pic error** Telegram *Service*
- 26 **Send pic typing** Telegram *Service*
- 27 **Switch on command type** Switch *Logic*
- 28 **6. Wait** Wait *Logic*
- 29 **reset existing context** Redis *Service*
- 30 **pop message** Redis *Service*
- 31 **Set body message** Telegram *Service*
- 32 **Set body definition** Redis *Service*
- 33 **Set scene message** Telegram *Service*
- 34 **Set scene definition** Redis *Service*
- 35 **Set base comfy entry** Set *Logic*
- 36 **Set base ollama context** Set *Logic*
- 37 **Reset context clone** Redis *Service*
- 38 **Send pop confirmation** Telegram *Service*
- 39 **Send body confirmation** Telegram *Service*
- 40 **Send scene confirmation** Telegram *Service*
- 41 **Send reset confirmation** Telegram *Service*

## How it's built

- **Starts on:** An incoming Telegram message
- **Steps:** 41, with 4 branches, 2 loops or waits
- **Size:** Large: read it before trusting it with anything live
- **Connects to:** Redis, Telegram
- **Model:** a local model
- **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 Redis and Telegram accounts, and a key for a local model. 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 a local model. 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 41 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 41 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%2Fhost-a-telegram-ai-bot-with-a-local-model-and-redis)
- **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.

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

## Workflows like it

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

- [**Create & share AI videos with Telegram and Gemini** 41 steps · calls a model · Google Drive, Google Sheets](https://millionrounds.com/workflow/create-and-share-ai-videos-with-telegram-and-gemini)
- [**Create and publish UGC social videos from Telegram with OpenAI** 41 steps · calls a model · Google Drive, Google Sheets](https://millionrounds.com/workflow/create-and-publish-ugc-social-videos-from-telegram-with-open)
- [**Generate monthly SEO analytics reports with Search Console** 41 steps · calls a model · Discord, Google Sheets](https://millionrounds.com/workflow/generate-monthly-seo-analytics-reports-with-search-console)
- [**Verify Telegram channel subscriptions with Postgres** 41 steps · Google Drive, Postgres](https://millionrounds.com/workflow/verify-telegram-channel-subscriptions-with-postgres)
- [**Automatic Instagram content creation with OpenAI and Telegram** 42 steps · calls a model · Airtable, Telegram](https://millionrounds.com/workflow/automatic-instagram-content-creation-with-openai-and-telegra)
- [**Generate Blog Posts on Autopilot with Tavily and WordPress** 42 steps · calls a model · Google Drive, Google Sheets](https://millionrounds.com/workflow/generate-blog-posts-on-autopilot-with-tavily-and-wordpress)
