-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#230 : Unsubscribe automation #236
Merged
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
dc86419
Added playwrite integration for unsubscribe automation
madhav-relish 801139e
Integratd unsubsxribe automation with fastify
madhav-relish b3c6052
Added Readme
madhav-relish dd619c0
Added readme content
madhav-relish 015a276
Replace google ai with vercel ai gogle provider
madhav-relish 0ef1c7e
Made potential changes
madhav-relish 31eb816
Coderabit suggestions
madhav-relish 5106536
Don't allow screenshots in prod
madhav-relish 1e9daf7
removed extra parameter from unsubscribeSchema
madhav-relish 9d40190
Coderabbit improvements
madhav-relish 4f2c34e
Changes Made
madhav-relish d737da7
Updated Readme
madhav-relish 7e17976
Merge branch 'main' into unsubscribe-automation
elie222 fcdb669
fix pnpm lock
elie222 0fb7267
Update unsubscriber deps
elie222 b764f34
rename unsubscriber
elie222 1f8d185
Use ts-oss env and tsx
elie222 48b650f
fix readme example
elie222 c931419
Update README
elie222 d490aa3
reuse consts. clean up code
elie222 438afec
clean up code
elie222 aa87227
more ai cleanup
elie222 9523adf
update readme
elie222 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
GOOGLE_GENERATIVE_AI_API_KEY= | ||
# If required, set CORS_ORIGIN to allow requests from your frontend | ||
CORS_ORIGIN="http://localhost:3000" | ||
NODE_ENV="development" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Unsubscribe Automation Service | ||
|
||
This service provides an automated solution for unsubscribing from email newsletters. It uses AI to analyze unsubscribe pages and performs automated actions to complete the unsubscribe process. | ||
|
||
## Features | ||
|
||
- AI-powered analysis of unsubscribe pages | ||
- Automated web interactions using Playwright | ||
- RESTful API endpoint for triggering unsubscribe actions | ||
- Support for both OpenAI and Google AI models | ||
- CORS support for easy integration with frontend applications | ||
|
||
## Prerequisites | ||
|
||
- Node.js (v14 or later) | ||
- pnpm package manager | ||
- A Google AI API key | ||
- An OpenAI API key | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify OpenAI API key requirement The prerequisites section mentions an OpenAI API key, but it's not included in the Consider one of the following actions:
|
||
## Installation | ||
|
||
1. Navigate to the project directory: | ||
|
||
``` | ||
cd apps/unsubscribe-automation | ||
``` | ||
|
||
2. Install dependencies: | ||
|
||
``` | ||
pnpm install | ||
``` | ||
|
||
3. Set up environment variables: | ||
Create a `.env` file in the root directory with the following content: | ||
|
||
``` | ||
GOOGLE_GENERATIVE_AI_API_KEY=your_google_ai_api_key_here | ||
CORS_ORIGIN=http://localhost:3000 | ||
``` | ||
|
||
Replace the API keys with your actual keys, and adjust the CORS_ORIGIN if needed. | ||
You can get a Google AI API Key here: https://aistudio.google.com/app/apikey | ||
|
||
## Running the Service | ||
|
||
1. Start the server: | ||
``` | ||
pnpm start | ||
``` | ||
The server will start on http://localhost:5000 by default. | ||
|
||
## Usage | ||
|
||
To use the unsubscribe service, send a POST request to the `/unsubscribe` endpoint: | ||
|
||
```bash | ||
curl -X POST http://localhost:5000/unsubscribe \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"url": "https://example.com/unsubscribe" | ||
}' | ||
``` | ||
|
||
- Replace `https://example.com/unsubscribe` with the actual unsubscribe URL. | ||
|
||
## API Endpoints | ||
|
||
- `GET /`: Health check endpoint | ||
- `POST /unsubscribe`: Trigger the unsubscribe process | ||
|
||
## Development | ||
|
||
- To run the service in development mode with hot reloading: | ||
|
||
``` | ||
pnpm run dev | ||
``` | ||
|
||
- To build the TypeScript files: | ||
``` | ||
pnpm run build | ||
``` | ||
|
||
## Troubleshooting | ||
|
||
- If you encounter any issues with Playwright, ensure that you have the necessary system dependencies installed. Refer to the [Playwright installation guide](https://playwright.dev/docs/intro#installation) for more information. | ||
- Check the console output for any error messages or logs that might indicate the cause of any issues. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "inbox-zero-unsubscriber", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "tsx --tsconfig tsconfig.json src/server.ts", | ||
"dev": "tsx watch --tsconfig tsconfig.json src/server.ts", | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"devDependencies": { | ||
"@types/dotenv": "^8.2.0", | ||
"@types/node": "22.5.4", | ||
"playwright": "^1.47.2", | ||
"tsx": "^4.19.1", | ||
"typescript": "^5.6.2" | ||
}, | ||
"dependencies": { | ||
"@ai-sdk/google": "^0.0.51", | ||
"@ai-sdk/openai": "^0.0.59", | ||
"@fastify/cors": "^10.0.1", | ||
"@t3-oss/env-core": "^0.11.1", | ||
"ai": "^3.3.36", | ||
"dotenv": "^16.4.5", | ||
"fastify": "^5.0.0", | ||
"zod": "^3.23.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createEnv } from "@t3-oss/env-core"; | ||
import { z } from "zod"; | ||
import "dotenv/config"; | ||
|
||
export const env = createEnv({ | ||
server: { | ||
NODE_ENV: z.enum(["development", "production", "test"]), | ||
PORT: z.number().default(5000), | ||
GOOGLE_GENERATIVE_AI_API_KEY: z.string().min(1), | ||
CORS_ORIGIN: z.string().optional(), | ||
}, | ||
|
||
/** | ||
* What object holds the environment variables at runtime. This is usually | ||
* `process.env` or `import.meta.env`. | ||
*/ | ||
runtimeEnv: process.env, | ||
|
||
/** | ||
* By default, this library will feed the environment variables directly to | ||
* the Zod validator. | ||
* | ||
* This means that if you have an empty string for a value that is supposed | ||
* to be a number (e.g. `PORT=` in a ".env" file), Zod will incorrectly flag | ||
* it as a type mismatch violation. Additionally, if you have an empty string | ||
* for a value that is supposed to be a string with a default value (e.g. | ||
* `DOMAIN=` in an ".env" file), the default value will never be applied. | ||
* | ||
* In order to solve these issues, we recommend that all new projects | ||
* explicitly specify this option as true. | ||
*/ | ||
emptyStringAsUndefined: true, | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Sensitive Data Detected in
.env.example
DATABASE_URL="postgresql://postgres:password@localhost:5432/inboxzero?schema=public"
DIRECT_URL="postgresql://postgres:password@localhost:5432/inboxzero?schema=public"
NEXTAUTH_URL=http://localhost:3000
GOOGLE_PUBSUB_TOPIC_NAME="projects/abc/topics/xyz"
Please ensure that these values are placeholders and do not contain actual sensitive information. It's recommended to keep all sensitive data out of version control by leaving values empty or clearly indicating they are placeholders.
🔗 Analysis chain
Overall, the .env.example file looks good. Ensure proper security practices.
The file provides a good template for required environment variables. Remember to:
CORS_ORIGIN
andNODE_ENV
appropriately for production deployments.To ensure no sensitive data is accidentally committed, run this final check:
Review any non-empty values returned by this script to confirm they are safe defaults, not actual sensitive data.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 1273