Skip to content
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 23 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/unsubscriber/.env.example
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"
Comment on lines +1 to +4
Copy link
Contributor

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

  • The following environment variables contain non-empty values:
    • 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:

  1. Keep actual API keys and sensitive data out of version control.
  2. Update CORS_ORIGIN and NODE_ENV appropriately for production deployments.
  3. Educate team members on the importance of environment variable management and security.

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:

#!/bin/bash
# Description: Verify no actual sensitive data in .env.example

# Test: Check for non-empty values in .env.example
rg -g '.env.example' '=.+' --no-filename

Length of output: 1273

88 changes: 88 additions & 0 deletions apps/unsubscriber/README.md
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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Clarify OpenAI API key requirement

The prerequisites section mentions an OpenAI API key, but it's not included in the .env setup instructions later in the README. This might confuse users.

Consider one of the following actions:

  1. If the OpenAI API key is required, add it to the .env setup instructions.
  2. If it's not required, remove it from the prerequisites list.
  3. If it's optional, clarify this in the prerequisites section.

## 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.
30 changes: 30 additions & 0 deletions apps/unsubscriber/package.json
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"
}
}
33 changes: 33 additions & 0 deletions apps/unsubscriber/src/env.ts
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,
});
Loading