Quick overview
This workflow runs manually or every 3 hours to fetch held WordPress comments, uses OpenAI to classify them with a confidence score, and marks only high-confidence spam as spam in WordPress while leaving all other comments in the moderation queue with a reason and optional draft reply.
How it works
- Runs on a manual trigger or on a 3-hour schedule.
- Fetches up to the configured number of WordPress comments that are in the “hold” (moderation) status via the WordPress REST API.
- Cleans and truncates each comment’s text to prepare it for analysis.
- Sends each prepared comment to the OpenAI Chat Completions API to classify it as spam, abusive, question, positive, or other, including a confidence score, reason, and suggested reply for questions.
- Flags comments as “auto spam” only when the category is spam and the confidence meets or exceeds the configured threshold.
- If dry run is enabled, outputs a result indicating the comment would be marked as spam; otherwise, updates the comment status to “spam” in WordPress.
- For all non-confident-spam comments, outputs a result indicating the comment is left in the moderation queue along with the classification details and suggested reply (when applicable).
Setup
- Create a WordPress Application Password for a user allowed to moderate comments and add it as an HTTP Basic Auth credential in n8n for the WordPress REST API requests.
- Add an OpenAI API credential in n8n for the Chat Completions request.
- Update the configuration values for your site URL, max comments per run, model name, spam confidence threshold, and dry-run mode before enabling the scheduled trigger.