Automate Chat History Export to Google Sheets
detail.loadingPreview
Effortlessly archive your chat conversations into a structured Google Sheet. This workflow automatically retrieves chat history from your PostgreSQL database, cleans up existing data, and populates a new sheet with conversation logs, creating a searchable and easily accessible record.
About This Workflow
This n8n workflow provides a robust solution for archiving your chat history by exporting it from a PostgreSQL database to a Google Sheet. It begins by ensuring your PostgreSQL table has a created_at column for accurate timestamping of messages. The workflow then fetches all unique session IDs from your chat history and iterates through each one. For every session, it retrieves all corresponding conversations from the database. Next, it prepares a Google Sheet by clearing any previous content in a designated sheet and then copies the template sheet. Finally, it renames the newly created sheet to match the session ID and populates it with the conversation data, including the sender and message content. This automation ensures your chat logs are consistently backed up and organized for easy review and analysis.
Key Features
- Automated Data Archiving: Seamlessly export chat history from PostgreSQL to Google Sheets on a schedule.
- Dynamic Sheet Management: Automatically creates and renames new sheets for each chat session.
- Data Integrity: Ensures accurate timestamps with the
created_atcolumn. - Configurable Data Range: Clear specific ranges in your Google Sheet before adding new data.
- Secure Credential Management: Utilizes n8n's secure credential system for database and Google Sheets access.
How To Use
- Prerequisites: Ensure you have an n8n instance set up with access to your PostgreSQL database and a Google account authorized for Google Sheets.
- Database Setup: Verify your
n8n_chat_historiestable in PostgreSQL includessession_id,message.content,message.type, and importantly, acreated_attimestamp column. If not, use the 'add create_at column' node to add it. - Configure Credentials: Set up your PostgreSQL and Google Sheets OAuth2 credentials within n8n.
- Set Google Sheets Document ID: In the 'Clear Sheet Content' node, update the
documentIdwith the ID of your Google Sheet where logs will be stored. - Adjust Sheet Name and Range: Modify the
sheetNamein 'Clear Sheet Content' to dynamically use the session ID and set therangefor clearing previous data (e.g.,A2:C10000). - Review and Test: Use the 'When clicking ‘Test workflow’' trigger to run the workflow manually. Observe the output in your Google Sheet.
- Schedule Execution: Configure the 'Schedule Trigger' node to run the workflow at your desired frequency (e.g., daily at midnight).
Apps Used
Workflow JSON
{
"id": "774ab6b3-cce8-40f0-a488-78051c81f58c",
"name": "Automate Chat History Export to Google Sheets",
"nodes": 11,
"category": "Operations",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: 774ab6b3-cce8...
About the Author
DevOps_Master_X
Infrastructure Expert
Specializing in CI/CD pipelines, Docker, and Kubernetes automations.
Statistics
Related Workflows
Discover more workflows you might like
Universal CSV to JSON API Converter
Effortlessly transform CSV data into structured JSON with this versatile n8n workflow. Integrate it into any application as a custom API endpoint, supporting various input methods including file uploads and raw text.
Instant WooCommerce Order Notifications via Telegram
When a new order is placed on your WooCommerce store, instantly receive detailed notifications directly to your Telegram chat. Stay on top of your e-commerce operations with real-time alerts, including order specifics and a direct link to view the order.
On-Demand Microsoft SQL Query Execution
This workflow allows you to manually trigger and execute any SQL query against your Microsoft SQL Server database. Perfect for ad-hoc data lookups, administrative tasks, or quick tests, giving you direct control over your database operations.