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.
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.
- 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.
- 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
Before running the project, ensure you have the following installed:
- Node.js (v16 or higher)
- npm (comes with Node.js)
- AWS Account (for Amazon Comprehend)
- Telex Account (for testing the integration)
-
Clone the repository:
git clone https://github.com/telexintegrations/NLP-Sentiment-Analysis-Modifier-Integratio.git cd NLP-Sentiment-Analysis-Modifier-Integratio -
Install dependencies:
npm install
-
Create a
.envfile 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
- AWS Credentials: Ensure your AWS credentials have access to Amazon Comprehend.
- Telex Configuration: Update the
telexConfig.jsonfile with your Telex integration settings.
| 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. |
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
}
}
}
}Request:
GET /healthResponse:
{
"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"
}To test the integration, you can use the provided test.ts file or tools like Postman.
-
Start the server:
npm start
-
Run the tests:
npm test
To deploy the integration, follow these steps:
-
Build the Project:
npm run build
-
Deploy to a Server:
- Use a platform like AWS Elastic Beanstalk, Heroku, or Vercel.
-
Set Environment Variables:
- Ensure the
.envvariables are set in your deployment environment.
- Ensure the
Contributions are welcome! Follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature-name
- Commit your changes:
git commit -m "Add your feature" - Push to the branch:
git push origin feature/your-feature-name
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
- Amazon Comprehend for sentiment analysis.
- Telex for the integration framework.
- My Sweet BP ❤️ - Moral Support
Glenn Tanze aka Glenzzy
