Animated data flow diagram

AI-Powered Tweet Sentiment Analyzer & Alerter

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

Google Cloud Natural Language Twitter MongoDB PostgreSQL Slack

Overview

Unlock Real-time Social Insights with this AI Agent

This AI Agent automates the process of monitoring Twitter for specific keywords or hashtags (initially set for '#OnThisDay'). It uses Google Cloud Natural Language for sentiment analysis, stores the tweet text and sentiment scores in MongoDB and PostgreSQL, and alerts you on Slack for tweets with positive sentiment. This empowers you to tap into social conversations, understand public perception, and react promptly.

Key Features & Benefits

  • Scheduled Tweet Monitoring: Automatically fetches tweets using the Cron node at set intervals.
  • Targeted Data Collection: Searches Twitter for specific hashtags or keywords (e.g., #OnThisDay, brand mentions, industry terms).
  • AI-Driven Sentiment Analysis: Leverages Google Cloud Natural Language to accurately assess the emotional tone (score and magnitude) of each tweet.
  • Dual Database Persistence: Stores raw tweet data and its sentiment analysis results in MongoDB for flexible querying and PostgreSQL for structured reporting.
  • Conditional Slack Notifications: Instantly alerts a designated Slack channel when tweets meet a specific sentiment threshold (e.g., positive sentiment), enabling timely engagement or awareness.
  • Data Enrichment: Combines original tweet data with its sentiment score and magnitude for comprehensive analysis.
  • Customizable & Extensible: Easily modify search terms, sentiment criteria, database configurations, and alert messages to fit your unique business needs.

Use Cases

  • B2C E-commerce: Monitor real-time Twitter sentiment for your brand or specific product launches (e.g., `#NewGadget`). Get Slack alerts for highly positive tweets to quickly engage with happy customers or identify user-generated content opportunities.
  • B2B SaaS: Track industry conversations (e.g., `#AIinBusiness`) or competitor mentions. Analyze sentiment to understand market perception, identify pain points, and refine your marketing messaging. Store findings in PostgreSQL for trend analysis.
  • Content Ideation: Discover trending topics with positive sentiment in your niche by monitoring relevant hashtags. Use insights to fuel your content calendar and blog posts.
  • Brand Reputation Management: Set up alerts for your brand name to quickly identify and respond to tweets, especially those with strong sentiment (positive or negative, by adjusting the IF node).
  • Market Research: Collect and analyze public opinion on specific themes or events relevant to your business by customizing the search query.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • Twitter API V1.1 (OAuth 1.0a) credentials.
  • Google Cloud Platform account with the Natural Language API enabled, and credentials for the 'Google Cloud Natural Language' node (typically OAuth2).
  • MongoDB instance details (connection string, database name) and credentials.
  • PostgreSQL instance details (host, database, user, password) and credentials.
  • Slack workspace and API credentials (Bot Token recommended) for sending notifications.

Setup Instructions

  1. Download the n8n workflow JSON file.
  2. Import the workflow into your n8n instance.
  3. Cron Node: Adjust the 'Trigger Times' (e.g., Hour: 6 for 6 AM daily) to define how often the workflow runs.
  4. Twitter Node: Enter your Twitter API V1.1 credentials. Modify the Search Text parameter from =#OnThisDay to your desired search query (e.g., your brand name, a relevant hashtag, keywords).
  5. MongoDB Node: Configure with your MongoDB connection string, database, and desired Collection (default is 'tweets'). Ensure the 'Fields' parameter is set to text to store the tweet content.
  6. Google Cloud Natural Language Node: Authenticate using your Google Cloud credentials. The Content field is set to ={{$node["MongoDB"].json["text"]}}, assuming the MongoDB node outputs the inserted document containing the text field.
  7. Set Node: Review the expressions. It's configured to extract score and magnitude from the Google Cloud Natural Language node's documentSentiment, and the original text from the 'Twitter' node. These values are then passed to PostgreSQL.
  8. Postgres Node: Configure with your PostgreSQL connection details. Set the Table name (default 'tweets') and ensure Columns match the data from the 'Set' node (text, score, magnitude).
  9. IF Node: The condition ={{$json["score"]}} larger 0 filters for tweets with positive sentiment. Adjust the value 0 or the operation if you want to filter for different sentiment scores (e.g., smaller for negative, or a higher/lower threshold).
  10. Slack Node: Enter your Slack API credentials. Set the target Channel and customize the notification Text using expressions like {{$json["text"]}}, {{$json["score"]}}, and {{$json["magnitude"]}}.
  11. Ensure you have created all necessary credentials (e.g., for Twitter, MongoDB, Google Cloud, PostgreSQL, Slack) within your n8n instance and link them to the respective nodes.
  12. Activate the workflow.

Tags:

AI AgentSentiment AnalysisTwitterGoogle CloudMongoDBPostgreSQLSlack AutomationSocial ListeningETL

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation