Translate questions about emails into queries and run them
Workflow Description
An intelligent agent converts natural language questions about emails into SQL queries, executes them on PostgreSQL, and exports results to files or social media channels. Powered by Ollama for language understanding and logical query construction.
How it works
- 1.Receive user question through chat trigger or manual input
- 2.Process text with Ollama LM to extract intent and parameters
- 3.Translate question to SQL query and execute on PostgreSQL database
- 4.Filter and format results into readable structured data
- 5.Save processed data as CSV or JSON files
- 6.Share results via Twitter/X or send to user
Use cases
- Search stored emails with natural language questions without writing SQL
- Generate automated reports and analytics from email database
- Build an intelligent email assistant for non-technical users
Requirements
- PostgreSQL database with email data tables and proper schema
- Ollama language model installed and configured for local inference
- File read/write permissions for CSV and JSON export
- Twitter/X API credentials if social sharing is enabled
Service Value
Ready-made workflow template for automation delivery and service execution.
Apps Used
Details
How to Use
- 1.Click "Download Template"
- 2.Open your n8n dashboard
- 3.Go to Workflows > Import from File
- 4.Select downloaded file and configure credentials
Nodes Used (26)
Add table name to output
Set
Convert data to binary
Convert To File
Save file locally
Read Write File
Extract data from file
Extract From File
Chat Trigger
Chat Trigger
Sticky Note
Sticky Note
When clicking "Test workflow"
Manual Trigger
Combine schema data and chat input
Set
Load the schema from the local file
Read Write File
Extract SQL query
Set
Check if query exists
If
Format query results
Set
Combine query result and chat answer
Merge
List all columns in a table
Postgres
List all tables in a database
Postgres
Ollama Chat Model
Lm Chat Ollama
Postgres
Postgres
Add trailing semicolon
Set
Check for trailing semicolon
If
WorkflowTrigger
Execute Workflow Trigger
If ran manually
If
If file exists or already retried generating it
If
Sticky Note1
Sticky Note
AI Agent
Agent
Format empty output
Set
Sticky Note2
Sticky Note