Recipe: AI Automators comment-spam scoring and auto-unpublish
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3585304. --> Reported by: [marcus_johansson](https://www.drupal.org/user/385947) >>> <p>[Tracker]<br> <strong>Update Summary: </strong>[One-line status update for stakeholders]<br> <strong>Short Description: </strong>Ship a recipe that wires AI Automators onto the core Comment entity to score spam on a custom_field and auto-unpublish comments scoring 8 or higher, with a View for triage.<br> <strong>Check-in Date: </strong>MM/DD/YYYY<br> [/Tracker]</p> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>AI Automators is powerful but the on-ramp is still "wire it up yourself" - even for the canonical moderation use case of scoring comments for spam. We want a Drupal recipe that site builders can apply to a fresh install and get a working, AI-scored comment pipeline end to end. This also serves as the reference recipe for using AI Automators against a core content type with multi-field output and cross-field automator ordering (score &rarr; reasoning &rarr; status).</p> <p>The recipe should ship in its own repo/project rather than inside the <code>ai</code> module, so that it has an independent release cadence and a clean composer entry point. Exact project naming to be decided with the maintainers.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Create a new Drupal recipe project. When applied to a site that has the <code>ai</code> module and at least one configured chat provider, the recipe should produce the behaviour below end to end, no manual configuration required.</p> <p>It should be called ai_recipe_comment_spam under drupal.org.</p> <ul> <li>Composer-require the Custom Field contrib module (<a href="https://www.drupal.org/project/custom_field">drupal/custom_field</a>) and install it as part of the recipe.</li> <li>Enable the core <code>comment</code> module.</li> <li>Ensure the "Full comment" comment type is the default comment type (the core-shipped default).</li> <li>Attach a new Custom Field (from <code>custom_field</code>) to the Full Comment comment type, containing two sub-values: an integer <code>spam_score</code> constrained to 1-10, and a long-string <code>spam_reasoning</code> for a one-sentence explanation of why the AI chose that score.</li> <li>Configure the first AI Automator on that custom field. It reads the comment body, asks the provider to rate spam on a 1-10 scale (10 = pure spam, 1 = clearly not spam), writes the integer into <code>spam_score</code>, and writes a one-sentence reasoning into <code>spam_reasoning</code>. If the score is below 5, the reasoning is the literal string "ok" (noise reduction for the triage View).</li> <li>Configure a second AI Automator (or a deterministic automator if one fits better) that writes <code>status = 0</code> (unpublished) on the comment when <code>spam_score &amp;gt;= 8</code>. Applying to the recipe itself should not require <a href="https://www.drupal.org/project/base_field_override_ui">base_field_override_ui</a>; if that module is needed only at the site-builder configuration step, document that clearly so the recipe remains dependency-clean at apply time.</li> <li>Use direct-save for both automators, ordered so that the scoring automator runs first and the status automator runs after, otherwise the status decision runs against a stale score.</li> <li>Ship a View that lists comments the spam pipeline has acted on (e.g. comments where <code>spam_score &amp;gt;= 5</code>, or filtered to unpublished-by-spam), exposing filters so moderators can search and sort by score, reasoning, bundle, and date. This is the triage UI.</li> <li>Include a README in the recipe repo with: required dependencies, provider-configuration prerequisites, and a note about <code>base_field_override_ui</code> if needed for customising the recipe further after apply.</li> <li>Ship example fixtures (a handful of benign and spammy test comments) so the recipe can be demo'd immediately after apply without waiting for real user traffic.</li> </ul> <p><strong>Stretch goal - ECA integration.</strong> Ship an optional ECA workflow (guarded by an <code>ai_recipe_comment_spam_eca</code> companion submodule or a sibling recipe) that triggers the scoring automator on comment post-save <em>after</em> the output buffer has flushed, so the end user is not made to wait on a chat-provider round-trip during their comment-submission request. The current on-save automator path is synchronous; ECA plus <code>drupal_register_shutdown_function()</code> / a queue worker is the cleanest way to defer the call without blocking the response. Decide with maintainers whether this belongs in the main recipe or a sibling.</p> <h3 id="summary-ai-usage">AI usage (if applicable)</h3> <p>[x] AI Assisted Issue<br> This issue was generated with AI assistance, but was reviewed and refined by the creator.</p> <p>[ ] AI Assisted Code</p> <p>[ ] AI Generated Code</p> <p>[ ] Vibe Coded</p> <p>- <strong>This issue was created with the help of AI</strong></p>
issue