Automate Twitter Sentiment Analysis with n8n ETL Pipeline

Discover how this n8n ETL pipeline automates extracting tweets with #OnThisDay, analyzes their sentiment using Google Cloud Natural Language, stores results in MongoDB and Postgres, and posts positive tweets to Slack — saving hours of manual monitoring and enabling timely insights.
twitter
googleCloudNaturalLanguage
postgres
+6
Workflow Identifier: 1609
NODES in Use: Twitter, MongoDB, Google Cloud Natural Language, Set, Postgres, IF, Slack, NoOp, Cron
Automate Twitter sentiment with n8n and Google Cloud

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Automation Does

This workflow fetches tweets tagged #OnThisDay each morning at 6 AM.
It saves raw tweets to MongoDB, then analyzes tweet emotions with Google Cloud NLP.
It stores sentiment scores and tweet text in Postgres.
When tweets have a positive feeling, it sends messages to a Slack channel.
Negative or neutral tweets do not generate alerts.
This saves time and helps teams see moods quickly.


Tools and Services Used

  • Twitter API (OAuth1): Gets tweets with #OnThisDay.
  • MongoDB: Stores raw tweet texts.
  • Google Cloud Natural Language API (OAuth2): Performs sentiment analysis.
  • Postgres Database: Saves analyzed tweet data with sentiment.
  • Slack API: Sends positive sentiment alerts to a channel.
  • n8n automation platform: Runs and connects all nodes.

Inputs, Processing Steps, and Outputs

Inputs

  • Search term ‘#OnThisDay’ from Twitter API every day at 6 AM.
  • MongoDB database connection for storing raw tweets.
  • Google Cloud NLP API credentials for sentiment evaluation.
  • Postgres database for saving final sentiment records.
  • Slack channel destination for positive sentiment alerts.

Processing Steps

  1. Extract tweets by searching latest 3 tweets with #OnThisDay.
  2. Insert raw tweet text into MongoDB collection named ‘tweets’.
  3. Run sentiment analysis on tweet text using Google Cloud NLP.
  4. Structure sentiment score, magnitude, and original text via Set node.
  5. Insert sentiment data and tweet text into Postgres ‘tweets’ table.
  6. Use IF node to check if sentiment score is greater than 0.
  7. If sentiment is positive, send message to Slack channel.
  8. If sentiment is not positive, proceed silently with NoOp node.

Outputs

  • Raw tweets saved in MongoDB.
  • Sentiment scores and text saved in Postgres.
  • Slack notifications showing positive tweets with scores.
  • No Slack messages for neutral or negative tweets.

Who Should Use This Workflow

This workflow is for social media analysts who check tweet moods daily.
It fits teams wanting fast, error-free sentiment reports without manual work.
Users who want automatic alerts about positive tweets benefit a lot.


Beginner Step-by-Step: How to Use This Workflow in n8n

Download and Import Workflow

  1. Click the Download button on this page to get the workflow file.
  2. Open n8n editor and choose “Import from File”.
  3. Select the downloaded workflow file to add it to your workspace.

Configure Credentials and Settings

  1. Add credentials for Twitter API with OAuth1.
  2. Add credentials for Google Cloud NLP API with OAuth2.
  3. Connect MongoDB and Postgres database credentials.
  4. Set Slack API token and confirm Slack channel name.
  5. Update table names, channel names, or IDs if your setup differs.

Test and Activate Workflow

  1. Run the workflow manually once to check the data flow.
  2. Look at output logs to ensure no errors.
  3. Toggle the active switch in n8n to turn the workflow on.
  4. Monitor the workflow at 6 AM daily for data and alerts.

For users controlling their own servers, check self-host n8n for hosting options.


Customizations and Extensions

  • Change sentiment threshold by editing IF node (e.g., score > 0.2) to show only stronger positives.
  • Increase the tweet fetch limit in Twitter node (e.g., from 3 to 10) for more data.
  • Add tweet timestamp or user info fields into MongoDB insertion for richer raw data.
  • Add an IF branch to notify on negative sentiment (scores below -0.5) for alerting bad buzz.
  • Modify Cron node to run multiple times per day such as 6 AM, 12 PM, and 6 PM for frequent tracking.

Troubleshooting

Twitter Node Returns No Tweets or Authorization Error

Cause: Twitter OAuth1 token expired or invalid.
Solution: Re-authenticate Twitter OAuth1 API credentials inside n8n.

Google Cloud Natural Language Node Fails Authentication

Cause: Missing or wrong OAuth2 credentials.
Solution: Generate new OAuth2 credentials in Google Cloud Console and update in n8n.

Postgres Node Insert Errors due to Schema Mismatch

Cause: Table columns do not match Insert fields.
Solution: Verify Postgres table has exactly columns named “text”, “score”, “magnitude”.


Pre-Production Checklist

  • Ensure Twitter API keys have read permissions.
  • Check database connections and schema match for MongoDB and Postgres.
  • Test Google Cloud NLP API separately to confirm expected responses.
  • Confirm Slack channel exists and API token can post messages.
  • Perform a manual test run of the workflow before scheduling.
  • Backup database data before running workflow in production.

Deployment Guide

Activate workflow by toggling “active” in n8n after setup finishes.
Watch execution logs regularly to catch errors or slow runs.
Update Cron timing if different schedule is wanted.


Summary and Results

✓ Automates daily tweet fetching, analyzing, and saving with #OnThisDay.
✓ Gives instant alert for positive tweets via Slack.
✓ Removes manual work and errors from social sentiment reporting.
→ Enables teams to quickly see and act on tweet moods every morning.
→ Saves multiple hours weekly in tweet analysis tasks.


Automate Twitter sentiment with n8n and Google Cloud

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

Edit the search text field in the Twitter node to the new hashtag or keyword.
Yes, sentiment analysis uses billable credits based on API request volume, so monitor the API quota.
Re-authenticate Twitter OAuth1 API credentials in n8n to refresh expired or invalid tokens.
Yes, change the Cron node to run multiple times daily like 6 AM, 12 PM, and 6 PM.
Author
Written By
Ritu Sanjali

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.