Skip to content

The Sentiment Analysis Modifier Integration analyzes the sentiment of incoming messages in a Telex channel using NLP APIs. It detects whether messages are positive, negative, or neutral and flags or modifies toxic content before it appears in the channel

License

Notifications You must be signed in to change notification settings

telexintegrations/NLP-Sentiment-Analysis-Modifier-Integratio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telex Message Sentiment Analyzer Modifier Integration

Telex-Sentiment-Analyzer

This project is a Telex integration that analyzes the sentiment of incoming messages and modifies them based on predefined rules. It uses Amazon Comprehend for sentiment analysis and is designed to work with Telex's channel-based messaging system.


Table of Contents

  1. Overview
  2. Features
  3. Technologies Used
  4. Setup
  5. Usage
  6. Testing
  7. Deployment
  8. Contributing
  9. License

Overview

The Telex Sentiment Modifier Integration is a backend service that:

  • Receives messages from Telex channels.
  • Analyzes the sentiment of the messages using Amazon Comprehend.
  • Modifies the messages based on sentiment scores and predefined rules (e.g., adding warnings for toxic messages).
  • Sends the modified messages back to the Telex channel.

This integration is designed to help teams monitor and moderate messages in real-time, ensuring a safe and productive environment.


Features

  • Sentiment Analysis: Uses Amazon Comprehend to analyze the sentiment of messages.
  • Toxicity Detection: Flags potentially harmful messages based on a configurable toxicity threshold.
  • Customizable Settings: Allows users to configure toxicity thresholds, sensitivity levels, and more.
  • Real-Time Processing: Processes messages in real-time and returns modified messages to the channel.
  • Health Checks: Provides a health check endpoint to monitor the status of the integration and AWS connectivity.

Technologies Used

  • Backend: Node.js, Express.js
  • AWS Services: Amazon Comprehend (for sentiment analysis)
  • Libraries:
    • @aws-sdk/client-comprehend: AWS SDK for interacting with Amazon Comprehend.
    • dotenv: For managing environment variables.
    • cors: For enabling Cross-Origin Resource Sharing (CORS).
    • express-rate-limit: For rate limiting API requests.
  • Testing: Axios (for API testing), Postman

Setup

Prerequisites

Before running the project, ensure you have the following installed:

Installation

  1. Clone the repository:

    git clone https://github.com/telexintegrations/NLP-Sentiment-Analysis-Modifier-Integratio.git
    cd NLP-Sentiment-Analysis-Modifier-Integratio
  2. Install dependencies:

    npm install
  3. Create a .env file in the root directory and add the following environment variables:

    PORT=3000
    AWS_ACCESS_KEY_ID=your-aws-access-key-id
    AWS_SECRET_ACCESS_KEY=your-aws-secret-access-key
    AWS_REGION=us-east-1

Configuration

  • AWS Credentials: Ensure your AWS credentials have access to Amazon Comprehend.
  • Telex Configuration: Update the telexConfig.json file with your Telex integration settings.

Usage

API Endpoints

Endpoint Method Description
/format-message POST Receives a message, analyzes sentiment, and returns the modified message.
/health GET Returns the health status of the integration and AWS connectivity.
/integration.json GET Returns the Telex integration configuration.

Example Requests

1. Analyze and Modify a Message

Request:

POST /format-message
Content-Type: application/json

{
    "message": "This is Product is Terrible",
  "settings": [
    {
      "label": "Toxicity Threshold",
      "type": "number",
      "default": -0.5,
      "required": true
    }
  ]
}

Response:

{
    "message": "⚠️ Potentially harmful message detected (sentiment: -1.00): This is Product is Terrible",
    "metadata": {
        "processed": true,
        "sentiment_score": -0.9997839331626892,
        "processing_time": 327,
        "timestamp": "2025-02-25T16:48:43.611Z",
        "sensitivity_level": "-0.9997839331626892",
        "detailed_sentiment": {
            "sentiment": "NEGATIVE",
            "scores": {
                "positive": 0.000040529743273509666,
                "negative": 0.9997839331626892,
                "neutral": 0.00015682748926337808,
                "mixed": 0.000018765131244435906
            }
        }
    }
}

2. Health Check

Request:

GET /health

Response:

{
  "status": "ok",
  "version": "1.0.0",
  "uptime": 123.45,
  "memory": {
    "rss": 12345678,
    "heapTotal": 1234567,
    "heapUsed": 123456,
    "external": 12345
  },
  "timestamp": "2023-10-15T12:00:00.000Z",
  "aws_status": "connected"
}

Testing

To test the integration, you can use the provided test.ts file or tools like Postman.

  1. Start the server:

    npm start
  2. Run the tests:

    npm test

Deployment

To deploy the integration, follow these steps:

  1. Build the Project:

    npm run build
  2. Deploy to a Server:

  3. Set Environment Variables:

    • Ensure the .env variables are set in your deployment environment.

Contributing

Contributions are welcome! Follow these steps:

  1. Fork the repository.
  2. Create a new branch:
    git checkout -b feature/your-feature-name
  3. Commit your changes:
    git commit -m "Add your feature"
  4. Push to the branch:
    git push origin feature/your-feature-name
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Acknowledgments

  • Amazon Comprehend for sentiment analysis.
  • Telex for the integration framework.
  • My Sweet BP ❤️ - Moral Support

Author

Glenn Tanze aka Glenzzy

About

The Sentiment Analysis Modifier Integration analyzes the sentiment of incoming messages in a Telex channel using NLP APIs. It detects whether messages are positive, negative, or neutral and flags or modifies toxic content before it appears in the channel

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published