|
| 1 | +# WDIO Discord Bot |
| 2 | + |
| 3 | +A Node.js bot that bridges Stack Overflow and Discord for the WebdriverIO community. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Monitors Stack Overflow** for new questions tagged with a configurable tag (default: `webdriver-io`). |
| 8 | +- **Posts new questions** as rich embeds to a specified Discord channel via webhook. |
| 9 | +- **Prevents duplicate notifications** by persisting sent question IDs. |
| 10 | +- **Configurable** via environment variables. |
| 11 | +- **Easy to extend** for other tags or notification channels. |
| 12 | + |
| 13 | +## Getting Started |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | + |
| 17 | +- Node.js v22+ (for native fetch and ESM support) |
| 18 | +- npm |
| 19 | +- Access to a Discord server where you can create a webhook |
| 20 | + |
| 21 | +### Installation |
| 22 | + |
| 23 | +1. **Clone the repository:** |
| 24 | + ```sh |
| 25 | + git clone <repo-url> |
| 26 | + cd wdio-discord-bot |
| 27 | + ``` |
| 28 | + |
| 29 | +2. **Install dependencies:** |
| 30 | + ```sh |
| 31 | + npm install |
| 32 | + ``` |
| 33 | + |
| 34 | +3. **Configure environment variables:** |
| 35 | + |
| 36 | + Create a `.env` file in the project root with the following content: |
| 37 | + |
| 38 | + ``` |
| 39 | + DISCORD_WEBHOOK_ID=your_discord_webhook_id |
| 40 | + DISCORD_WEBHOOK_TOKEN=your_discord_webhook_token |
| 41 | + TAG_TO_MONITOR=webdriver-io |
| 42 | + # Optional: STACKEXCHANGE_KEY=your_stackexchange_api_key |
| 43 | + ``` |
| 44 | + |
| 45 | + - `DISCORD_WEBHOOK_ID` and `DISCORD_WEBHOOK_TOKEN` are from your Discord channel webhook. |
| 46 | + - `TAG_TO_MONITOR` is the Stack Overflow tag to monitor. |
| 47 | + - `STACKEXCHANGE_KEY` is optional but recommended for higher API rate limits. |
| 48 | + |
| 49 | +4. **Run the bot:** |
| 50 | + |
| 51 | + - For development (with TypeScript): |
| 52 | + ```sh |
| 53 | + npm run dev |
| 54 | + ``` |
| 55 | + - For production: |
| 56 | + ```sh |
| 57 | + npm start |
| 58 | + ``` |
| 59 | + |
| 60 | +## How It Works |
| 61 | + |
| 62 | +- On each run, the bot: |
| 63 | + 1. Loads the list of previously notified question IDs from `data/sentIds.json`. |
| 64 | + 2. Fetches the latest questions from Stack Overflow tagged with your configured tag. |
| 65 | + 3. Filters out questions already sent. |
| 66 | + 4. Formats and posts new questions to Discord as embeds. |
| 67 | + 5. Updates `sentIds.json` and auto-commits/pushes the file (if using git). |
| 68 | + |
| 69 | +## Development Advice |
| 70 | + |
| 71 | +- **TypeScript:** The project is written in TypeScript. Use `npm run dev` for live development. |
| 72 | +- **Persistence:** Sent question IDs are stored in `data/sentIds.json`. To reset notifications, delete or clear this file. |
| 73 | +- **Auto-commit:** Each time new questions are sent, the bot auto-commits and pushes the updated `sentIds.json`. Ensure your environment has git configured and permissions set. |
| 74 | +- **Extending:** To monitor a different tag, change `TAG_TO_MONITOR` in your `.env`. |
| 75 | +- **Formatting:** The embed includes a snippet of the question body, with code blocks formatted for Discord. |
| 76 | +- **Error Handling:** If the bot fails to send a message or update sent IDs, errors are logged to the console. |
| 77 | +- **API Limits:** For higher Stack Exchange API limits, set `STACKEXCHANGE_KEY` in your `.env`. |
| 78 | + |
| 79 | +## Project Structure |
| 80 | + |
| 81 | +``` |
| 82 | +src/ |
| 83 | + config/ # Environment variable validation |
| 84 | + services/ # Stack Overflow, Discord, and persistence logic |
| 85 | + utils/ # HTML formatting for Discord |
| 86 | + index.ts # Entry point |
| 87 | +data/ |
| 88 | + sentIds.json # Tracks sent question IDs |
| 89 | +``` |
| 90 | +
|
| 91 | +## Troubleshooting |
| 92 | +
|
| 93 | +- **No new questions:** If there are no new questions, the bot will log "No new questions." |
| 94 | +- **Webhook errors:** Double-check your Discord webhook credentials. |
| 95 | +- **Git errors:** Ensure your environment has git installed and configured for auto-commits. |
| 96 | +
|
| 97 | +## License |
| 98 | +
|
| 99 | +MIT |
| 100 | +
|
| 101 | +Feel free to further customize this README for your community or deployment environment! |
0 commit comments