# Telegram bot for email search using AI and SQL with dialogue support
This workflow enables answering questions about your email history via a Telegram bot using natural language. Built on an n8n-powered LangChain agent with RAG and PostgreSQL (Pgvector), it performs both semantic search across message content and precise SQL queries on structured metadata, combining results for accurate and comprehensive responses. Contextual memory allows follow-up questions within the same conversation.
## Who it´s for
- Business owners seeking quick access to email context and agreements
- Managers tracking email-based commitments through a chat interface
- Developers automating database access without building a UI
- Users who prefer querying databases in natural language
## What the automation does
- Receives user questions from Telegram or n8n’s internal chat
- Activates a LangChain agent that decides whether to use vector search, SQL, or both
- Performs semantic search in Pgvector to find relevant emails
- Validates dates, participants, or statuses via SQL query on structured email data
- Combines results into a coherent response
- Splits long responses into chunks and sends them sequentially in Telegram
## What´s included
- Ready-to-use n8n workflow
- Trigger and handler logic based on incoming messages
- Integrations with Telegram, PostgreSQL (including Pgvector), and Ollama API
- Basic setup and adaptation guide
## Requirements for setup
- n8n instance (self-hosted or cloud)
- PostgreSQL database with pgvector extension enabled
- Pre-populated email data table with metadata (ID, date, sender, subject)
- Running Ollama server with a loaded LLM or access to OpenAI Chat model
- Telegram bot token connected to n8n
## Benefits and outcomes
- Instant access to email insights without opening a mail client
- Reduced time spent searching for meetings, agreements, or task statuses
- Natural language queries instead of complex filters or SQL
- Conversation memory for contextual follow-ups
- Automatic response chunking for clean Telegram delivery
- Dual access via Telegram or n8n’s chat interface
## Important: template only
Important: you are purchasing a ready-made automation workflow template only. Rollout into your infrastructure, connecting specific accounts and services, 1:1 setup help, custom adjustments for non-standard stacks and any consulting support are provided as a separate paid service at an individual rate. To discuss custom work or 1:1 help, contact via chat
No feedback yet