This project implements a production-ready Playwright bot.
The bot performs actions like commenting, ranking posts, and creating new ideas on a scheduled basis, simulating user activity.
- Comment and Rank Posts
- Create New Ideas:
- Headless Execution: Designed to run headlessly for server environments like GitHub Actions.
- Environment Variable Support: Securely manages API keys and other configurations.
- GitHub Actions Integration: Automated scheduling and manual triggering via GitHub Actions workflows.
rateidea-bot/
├── .github/
│ └── workflows/
│ └── bot.yml # GitHub Actions workflow definition
├── .env.example # Example environment variables file
├── .gitignore # Specifies intentionally untracked files
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── public/
│ └── logo.jpg # Project logo used in README
└── src/
├── bot.ts # Main bot orchestrator
├── commentAndRank.ts # Handles commenting and ranking posts
├── createIdea.ts # Creates new ideas on the site
├── utils.ts # Helper utilities
└── prompts/
├── commentAndRankPrompt.ts
└── createIdeaPrompt.ts
Follow these steps to set up and run the bot.
-
Clone the Repository:
git clone https://github.com/fsystemweb/rate-idea-bot cd rateidea-bot -
Install Dependencies:
npm install npx playwright install --with-deps # Install Playwright browsers -
Configure Environment Variables: Create a
.envfile in the root of your project based on.env.example.# .env # Your OpenAI API Key OPENAI_API_KEY="sk-..." # Set to "false" to run in headed mode for debugging # HEADLESS="true" by default in production, "false" for local debuggingImportant: Replace
"sk-..."with your actual OpenAI API Key.
To test the bot on your local machine, ensure your .env file is configured, and then run:
npm start- Headed Mode: To observe the bot's actions in a browser window, change
HEADLESS="true"toHEADLESS="false"in your.envfile. - Error Screenshots: The bot is configured to take a full-page screenshot if an unexpected error occurs during its run. These screenshots will be saved in the project root directory, named
error-screenshot-<timestamp>.png.
To automate the bot's execution on a schedule using GitHub Actions:
-
Create a GitHub Repository: Initialize a new GitHub repository and push your project code to it.
-
Add GitHub Secrets: In your GitHub repository, navigate to
Settings>Secrets and variables>Actions. Add a new repository secret:OPENAI_API_KEY: Your OpenAI API key.
Note: Since
rateidea.ussupports anonymous interaction, no user credentials (email/password) are needed or stored. -
Workflow Activation: Once the code is pushed and secrets are configured, the GitHub Actions workflow (
.github/workflows/bot.yml) will automatically become active.- Scheduled Runs: The bot is scheduled to run daily at 8:00 AM UTC.
- Manual Trigger: You can manually initiate a run from the "Actions" tab in your GitHub repository by selecting the "RateIdea.us Bot" workflow and clicking "Run workflow".
- Selectors: If the website's structure (
https://rateidea.us/) changes, you may need to update the Playwright selectors insrc/bot.ts. You can use Playwright's codegen tool (npx playwright codegen https://rateidea.us/) to help find new selectors. - Scheduling Logic: Adjust the frequency of commenting/ranking and idea creation by modifying the date checks in
src/bot.ts(currently based on days ending in 5 or 0). - OpenAI Prompts: Customize the behavior of the AI-generated comments and ideas by editing the
messagesarray within theopenai.chat.completions.createcalls insrc/bot.ts. - Website URL: The target URL is defined by the
WEBSITE_URLconstant insrc/bot.ts.