course 01

Cusdis + n8n automation

Learn the practical workflow for receiving comments and filtering spam. Automate the entire process including drafting and posting replies.

What this course builds
  1. Start with Cusdis Cloud as the comment layer
  2. Receive new comment events through an n8n webhook
  3. Use Gemini to classify spam and draft a reply
  4. Wait a bit, then approve and reply automatically
What you leave with
  1. Bilingual prompt examples
  2. Production-minded JavaScript post-processing
  3. A Cloudflare Tunnel exposure path for self-hosted n8n
  4. A clear sense of publish vs production URL behavior
1 / 13
why cusdis

Why Cusdis is easy to start with

It is lightweight, privacy-first, and easy to set up. This makes it a perfect first step for blog comment automation.

Core notescusdis.com ↗
  1. A privacy-first, open-source alternative to Disqus
  2. The embed SDK is about 5KB gzipped
  3. Built-in i18n and dark mode support
  4. Webhook events and Quick Approve links out of the box
Cloud starting pointpricing ↗
  1. Free Cloud includes one site
  2. 100 approved comments per month
  3. 10 quick approves per month
  4. Move to paid or self-host as volume grows
When self-host starts making sense

Once traffic grows or you want more control over operations and data, self-hosting becomes the natural next move.

2 / 13
system flow

End-to-end automation architecture

Automation using webhook mechanisms and n8n workflows

Cusdis comment
Webhook node
Gemini analysis
Code cleanup
If branch
Wait delay
HTTP Request
Complete workflow

When a comment is posted, Cusdis sends an event to the configured webhook API URL. We show how to set up a webhook in n8n to receive these events and build a workflow for automated processing.

Key points
  • Convert `approve_link` into an API endpoint before calling itGemini node
  • The LLM returns `NORMAL` or `SPAM` plus a reply draft as JSONGemini node
  • Waiting before replying makes the behavior feel less roboticWait node
3 / 13
n8n hosting

n8n Cloud vs self-host

If speed matters most, n8n Cloud is the smoother path. Self-hosting with Docker Compose means you own the exposure, upgrades, and security decisions.

If you choose Cloud
  1. Domain and HTTPS setup mostly disappears
  2. You can focus on the workflow instead of installation
  3. External webhook integrations stay simpler
VS
If you choose Docker ComposeDocker docs ↗
  1. n8n officially recommends Docker for self-hosting
  2. You own upgrades, security, storage, and recovery
  3. You still need a stable public HTTPS URL for webhooks
Environment values to rememberdocs ↗
WEBHOOK_URL=https://your-domain.com/
N8N_PROXY_HOPS=1

Replace 'your-domain.com' with the domain your n8n instance is running on.

If you are new to operations, start on n8n Cloud and move to self-hosting after the workflow has proven itself.

4 / 13
public https

Giving self-hosted n8n a public HTTPS domain

Cusdis webhooks need a reachable HTTPS URL. Expose your n8n instance safely using modern tunneling technology.

You can skip this slide: If you use n8n Cloud, or your n8n is already running on a public server with HTTPS, skip this page and move on.
Why a public URL is required

Self-hosted instances are usually hidden behind local networks. Since n8n practically requires HTTPS for security and reliable communication, setting up a Domain+HTTPS path is critical. Using Cloudflare is one of the easiest and most reliable ways to achieve this.

Why Cloudflare Tunnel

If your domain is already managed by Cloudflare, one Tunnel is all you need to expose an internal service safely — no extra server required. Unlike ngrok, the URL is stable and free.

Setup steps
  1. Go to Cloudflare Networks > Connectors and click "Create a tunnel".
  2. Map your domain to your internal n8n address (Route). If you are running n8n via Docker, specify the port it uses.
  3. Set up the HTTPS domain so webhooks land safely. Enter "n8n" in the subdomain field (e.g., n8n.yourdomain.com). Set Service Type to http and enter the address where n8n is running. (e.g., if your IP is 192.168.219.101 and the Docker port is 5678, enter 192.168.219.101:5678 in the URL field.)
5 / 13
cusdis webhook

Connect the webhook in Cusdis Site settings

Connect your comment system to your automation engine. Let's set up the webhook URL so n8n knows when a new comment arrives.

Webhook field inside Cusdis Site settings
Checklist
  • Turn on the Webhook switch in Site settings
  • Paste the URL from the n8n Webhook node
  • Use the test URL while debugging, then switch Cusdis to the production URL later
  • The Cusdis webhook payload includes an `approve_link`. We will use this link in the n8n workflow to handle approvals.
  • Note: Cusdis approval page links expire after 31 days.
6 / 13
n8n workflow · 1 / 6

Webhook Node — the first node in the workflow

The Webhook node starts the entire automation flow. It is the entry point that listens for incoming signals from Cusdis.

  • The Webhook node exposes different test and production URLs
  • The test URL only stays active after `Listen for test event`, and the docs say it stays live for 120 seconds
  • The production URL is registered only after the workflow is published / activated
  • Cusdis sends a `POST`, so the method should also be `POST`
1. Entry point for creating a workflow
2. Adding the Webhook node
3. Webhook URL and POST settings
7 / 13
n8n workflow · 2 / 6

Gemini Analysis Node — spam detection and reply drafting

The important part is constraining the model to return a clean JSON contract.

1 Adding the Gemini Message node
  • Create credentials with an API key from Google AI Studio
  • Recommend the current stable model code `gemini-2.5-flash-lite`
  • The screenshot may show an older model name, so trust the live model picker in the UI
  • Turn on both `Simplify Output` and `Output Content as JSON` so the next node stays simple
2 Model, prompt, and JSON output settings
Prompt, copy and paste it
You are an AI assistant helping the blog owner.
Read the comment below, decide whether it is spam, and if it is a normal comment, write a short thank-you reply. (The reply should be friendly, 1-2 sentences long, and match the language of the comment.)
Comment: "{{ $json.body.data.content }}"

[Output rules]
Return exactly one pure JSON object with the structure below. Do not wrap it in Markdown.

Comment: "{{ $json.body.data.content }}"

[Output rules]
1. Return only JSON (rfc8259), with no explanation and no markdown fences.
2. Follow the JSON schema below exactly.
{
  "result": "NORMAL" or "SPAM",
  "reply": "The drafted reply text (empty string for SPAM)",
  "approved_link": "{{ $json.body.data.approve_link }}"
}
8 / 13
n8n workflow · 3 / 6

Code Node — clean up Gemini output with JavaScript

JavaScript avoids extra Python setup on a self-hosted box. Parse failures are intentionally absorbed as `ERROR`.

1. Adding the Code node
2. Run once for all items / JavaScript settings
  • Use `Run once for all items` to loop through the Gemini output payload
  • Strip markdown fences and verify the result with `JSON.parse`
  • Copy & past "JavaScript post-processing"
JavaScript post-processing
for (const item of $input.all()) {
  try {
    // Result from gemini : $json.content.parts[0].text
    let rawText = item.json.content.parts[0].text;

    // 2. Remove markdown letters and trim
    rawText = rawText.replace(/```json/g, "").replace(/```/g, "").trim();

    const parsedData = JSON.parse(rawText);
    const originalLink = parsedData.approved_link;
    const apiLink = originalLink.replace("/open/approve", "/api/open/approve");
    item.json.ai_result = parsedData.result;
    item.json.ai_reply = parsedData.reply;
    item.json.ai_api_link = apiLink;
    item.json.ai_approve_link = parsedData.approved_link;

  } catch (error) {
    item.json.ai_result = "ERROR";
    item.json.ai_approve_link = "";
  }
}
return $input.all();
9 / 13
n8n workflow · 4 / 6

If Node — filtering for normal comments

The clean path only proceeds if Gemini says the message is "NORMAL". This keeps spam from ever hitting your blog or causing delays in n8n.

Configuring the If node branch conditions
  • Check if `ai_result` exactly matches the string 'NORMAL'
  • The workflow only continues to the Wait/Request nodes on the True path
  • Simple logic prevents AI-generated spam from cluttering your blog
10 / 13
n8n workflow · 5 / 6

Wait Node — random delay for a natural feel

Replying instantly feels robotic. A random delay makes the response feel like it came from a real person.

Random delay in the Wait node
Wait Amount expression
{{ Math.floor(Math.random() * (60 - 10 + 1)) + 10 }}
  • Enter the expression in the `Amount (Seconds)` field using Expression mode
  • `Math.floor(Math.random() * (60 - 10 + 1)) + 10` → 10 to 60 minutes randomly
  • Set the unit to Minutes, not Seconds
  • For high-volume blogs, you can widen the range further
11 / 13
n8n workflow · 6 / 6

HTTP Request Node + Publish — send approve / reply and deploy

The final payload is ready to go! Send the approval and reply, then publish your workflow for live operation.

HTTP Request JSON body
{"replyContent":"{{ $json.ai_reply }}"}
  • URL: `{{ $json.ai_api_link }}` (the API path transformed by the Code node)
  • Method: `POST`, Body Content Type: `JSON`, Send Body: On
  • Set the `replyContent` key to `{{ $json.ai_reply }}`
  • The production URL will not go live until you Publish / Activate the workflow
Approve + reply via HTTP Request
Publish / activate the workflow
12 / 13
wrap-up

Operating notes and next moves

Congratulations! Your blog now has a smart automation loop for comment moderation.

Ops checklist
  • Validate on Cusdis Cloud first, then move to paid or self-hosting only when the volume justifies it
  • Auto-replies are convenient, but you should still review voice consistency and false positives regularly
  • Keep refining the Gemini prompt so it matches the tone of the blog over time

Was this useful? If there is another lecture you want next, email [email protected].

Follow along here as well

13 / 13
Lecture index
Spam filtering and auto-approval with n8n
Course Summary

Cusdis Automation

Build an end-to-end comment moderation flow with n8n, Gemini, and Cusdis.

A practical beginner-friendly course for automating blog comment operations, from webhook wiring and AI moderation to conditional routing, approval APIs, and ops checklists.

Deliverable: a production-minded workflow that analyzes, delays, approves, and replies to safe comments automatically.

What this deck covers

  • Wire Cusdis webhooks into n8n so comment events become the trigger for automation.
  • Design prompts that force Gemini into a JSON contract and post-process the output safely.
  • Combine clean-comment branching, random delay, and approval API calls into one workflow.
  • Prepare a deployment checklist and identify recovery points needed for live operations.

Chapter outline

0120m

Setup and understand the full flow

Clarify the roles of Cusdis, n8n, and Cloudflare Tunnel before touching the workflow details.

0215m

Create the webhook trigger

Connect Cusdis comment events to the first Webhook node in n8n.

0330m

Gemini analysis and JS normalization

Force the AI into a strict JSON contract and normalize it with defensive JavaScript.

0425m

Conditional routing and approval API

Route only safe comments forward, wait for a natural delay, then send approval and reply requests.

0510m

Ops review and extension ideas

Review the failure points, rollout checks, and next automation ideas needed for production.