← All N8N workflows
AI & researchAgentChat TriggerCodeEmbeddings OllamaIf

e-mail Chatbot with both semantic and structured RAG, using Telegram and Pgvector

Configured with Agent, Chat Trigger, Embeddings Ollama, OpenAI Chat Model, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
TriggerTelegram TriggerTelegram TriggerRoutingLoop Over ItemsLoop Over ItemsRoutingCame from Telegram?IfTriggerWhen chat messagereceivedChat TriggerData storePostgres PGVector StoreVector Store PgvectorSubworkflowCall the SQL composerWorkflowTool WorkflowAI & modelsEmbeddings OllamaEmbeddings OllamaTransformBeautify chat responseEdit FieldsCodeSplit text into chunksCodeMessagingRespond on Telegram inbatchesTelegramCodeEscape MarkdownCodeRoutingNo Operation, donothingNo OpData storeSimple MemoryMemory Buffer WindowAI & modelsAI AgentAgentAI & modelsOpenAI Chat ModelOpenAI Chat ModelTransformGenerate session idEdit Fields

Node categories in this workflow

  • Trigger
  • Routing
  • Data store
  • Subworkflow
  • AI & models
  • Transform
  • Code
  • Messaging

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
Telegram TriggerTriggerTelegram TriggerSee node parameters
Loop Over ItemsRoutingLoop Over ItemsSee node parameters
Came from Telegram?RoutingIfSee node parameters
When chat message receivedTriggerChat TriggerSee node parameters
Postgres PGVector StoreData storeVector Store PgvectorSee node parameters
Call the SQL composer WorkflowSubworkflowTool WorkflowSee node parameters
Embeddings OllamaAI & modelsEmbeddings OllamaSee node parameters
Beautify chat responseTransformEdit FieldsSee node parameters
Split text into chunksCodeCodeSee node parameters
Respond on Telegram in batchesMessagingTelegramSee node parameters
Escape MarkdownCodeCodeSee node parameters
No Operation, do nothingRoutingNo OpSee node parameters
Simple MemoryData storeMemory Buffer WindowSee node parameters
AI AgentAI & modelsAgentSee node parameters
OpenAI Chat ModelAI & modelsOpenAI Chat ModelSee node parameters
Generate session idTransformEdit FieldsSee node parameters

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • ollamaApi
  • openAiApi
  • postgres
  • telegramApi

Workflow notes

Chat around!

Chat around!

You can use this workflow both as a Telegram bot, or by chatting with it in n8n's interface.

🤖

🤖

This AI Agent has the mission to query both structured and vectorized databases containing all your e-mail communications.

Adjust the SQL composer Workflow to point at a copy of my Translate questions about e-mails into SQL queries and run them template.

IMPORTANT

IMPORTANT

For this step to work, you must download my other template Translate questions about e-mails into SQL queries and run them.

Response

Response

This section takes care of formatting the answer and either responding over Telegram, or in n8n's chat.

e-mail Chatbot with both semantic and structured RAG, using Telegram and Pgvector

e-mail Chatbot with both semantic and structured RAG, using Telegram and Pgvector

Purpose and structure

This folder contains the e-mail Chatbot with both semantic and structured RAG, using Telegram and Pgvector workflow. Its executable nodes use agent, chatTrigger, code, embeddingsOllama, if, lmChatOpenAi, memoryBufferWindow, noOp, set, splitInBatches, telegram, telegramTrigger, toolWorkflow, vectorStorePGVector. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

Telegram Trigger, When chat message received

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Telegram/1843_Telegram_Code_Automate_Triggered.json MIT; preserve source notices.

More in AI & research