🤖💬 Cacbot
Cacbot turns a WordPress comment thread into an AI-assisted conversation. A remote processing service (the “mothership”) coordinates generation, while the conversation itself stays in WordPress: human messages and Cacbot replies are stored as ordinary comments and remain subject to WordPress’s moderation and privacy controls.
“Cacbot” stands for “Comments Are a ChatBOT.”
How it works
- A registered user posts an approved comment on a Cacbot conversation.
- Cacbot schedules delivery with WP-Cron, so the comment request does not wait for AI generation.
- The mothership retrieves a paginated snapshot of the conversation and its configuration.
- For an accepted job, the mothership can retrieve the site’s configured model-provider credential.
- The generated reply is returned to the site, sanitized, and inserted as a threaded WordPress comment.
This repository is the WordPress-side plugin. Model selection, provider calls, and generation happen in the compatible remote processing deployment.
📋 Requirements
- WordPress 7.0 or newer, with AI support enabled. The plugin uses the Connectors API introduced in WordPress 7.0. If AI support is disabled with
WP_AI_SUPPORTor thewp_supports_aifilter, activation is refused; an already-active copy does not boot and shows administrators an explanatory notice. - An Anthropic or OpenAI API key, entered under Settings → Connectors → Cacbot. The provider bills the site owner directly.
- PHP 8.0 or newer.
- HTTPS access to a compatible Cacbot mothership. HTTP can be enabled explicitly for local development only.
- Working WP-Cron and outbound HTTP requests for generated replies.
✨ Features
- Registers the public
cacbot-conversationcustom post type, available from the WordPress REST API atwp/v2/cacbot-conversations. - Can treat a post of another type as a conversation when its
_cacbot_conversationmetadata is exactly1. - Responds to newly approved comments from registered users who do not have the Cacbot role.
- Adds a Cacbot connector to Settings → Connectors for the site’s own Anthropic or OpenAI API key, and gives the key to the processing unit only for a job the mothership accepted.
- Queues mothership delivery through WP-Cron, so comment submission does not wait for the remote service.
- Stores generated replies, fixed local replies, and visible failure messages as threaded WordPress comments.
- Builds one system-instruction message from site-wide instructions, conversation instructions, and—when explicitly enabled—the post body.
- Supports a fixed local response in place of remote generation.
- Can close comments when a configured approved-comment limit is reached.
- Keeps open conversation pages in sync with their post, so new replies, edits, and the Assistant’s typing state appear without a reload.
- Under the AI Style theme, renders the conversation as a flat chat, gives logged-out visitors the same composer, and adjusts the front-end admin bar.
- Provides optional integration points for the separate Anchor Posts plugin.
🚀 Create a conversation
- In WordPress administration, go to Cacbot Conversations → Add New.
- Add a title and optional body.
- Make sure comments are enabled.
- Choose the appropriate visibility. Use Private when only authorized logged-in users should see the post.
- Publish the conversation.
- While logged in, open it on the front end and submit a comment.
The post title and body are available to the mothership as conversation context; shortcodes are removed from the body rather than executed. Only approved comments from registered, non-Cacbot users enter the response pipeline. A held comment enters the pipeline if it is later approved. Guest comments, Cacbot-authored comments, and comments on unrecognized posts do not.
⚙️ Configuration
🛠️ Settings → CACBot
Only users with manage_options can use this page. It provides the mothership URL, global system instructions, connection status, and a Reconnect action.
🛸 Mothership URL
The effective URL is selected in this order:
- The
cacbot_mothership_urloption. - The
CACBOT_MOTHERSHIP_URLconstant. https://cacbot.com.
Saving a changed URL starts reconnection. Requests containing credentials are restricted to HTTPS. Local development may opt into HTTP with CACBOT_ALLOW_HTTP; the cacbot_allow_http filter can override that decision.
define( 'CACBOT_MOTHERSHIP_URL', 'https://cacbot.example' );
🌍 How the system instruction is built
Cacbot sends the processing service one system_instructions value. It is assembled in this order:
- The site-wide instructions from the
cacbot_global_system_instructionsoption. - The conversation’s
_cacbot_system_instructionsmetadata. - The conversation post body, but only when
_cacbot_include_post_in_contextis exactly the string"1".
Each part is converted independently to plain text with WordPress’s sanitize_textarea_field. If the post body is included, shortcodes are stripped before sanitization. Empty parts are omitted, runs of more than two newlines are collapsed, and the remaining parts are joined with one blank line. For example:
Always be concise and respectful.
Answer as an expert on tea.
Our shop opens at 9 a.m.
If all three parts are empty, the context API sends null; it does not insert a built-in default prompt. The legacy SystemInstructions::defaultText() helper still exists for compatibility, but the current reply pipeline does not call it.
The global setting is available only to administrators under Settings → CACBot. Conversation instructions and the “Include this post in context” option are available in the post editor’s Cacbot box.
🔑 AI provider key (Settings → Connectors)
Cacbot’s replies are generated with the site owner’s own API key. Enter an Anthropic (sk-ant-…) or OpenAI (sk-…) key on the Cacbot card under Settings → Connectors, or set it outside the database:
define( 'CACBOT_LLM_API_KEY', 'sk-ant-…' );
The CACBOT_LLM_API_KEY environment variable takes precedence over the constant, and the constant over the stored setting (cacbot_llm_api_key). The provider is recognized from the key’s prefix. Admin keys (sk-ant-admin…, sk-admin-…) and keys in any other format are not kept. Saving checks the format only; the first reply shows whether the provider accepts the key.
WordPress shows only the key’s last four characters. Settings → CACBot shows the provider and the same four characters. The key leaves the site only through POST cacbot/v1/llm-credential, which answers the mothership’s Assistant credential for a job the mothership accepted for that comment within the last day.
Without a key in a recognized format, Cacbot does not submit a job to the mothership. The comment receives the local reply “CACBot isn’t set up to answer on this site yet.” and administrators see instructions for correcting the key. Provider-side errors, such as a rejected credential or exhausted credit, are reported through the normal remote failure path; public errors do not disclose the credential.
📝 Cacbot post editor box
Users with manage_options or the Cacbot role see a Cacbot box on cacbot-conversation posts and on non-attachment post types that support comments.
For other post types, the box includes a Cacbot Conversation checkbox. Once enabled, the box exposes:
- System Instructions (
_cacbot_system_instructions) - Include this post in context (
_cacbot_include_post_in_context) - Comment Form Placeholder Text (
_cacbot_comment_form_placeholder_text)
Clearing the conversation checkbox preserves the other settings. Saving a blank text field deletes that metadata key.
🏷️ Conversation metadata
The following post-meta fields affect behavior in this plugin. Boolean-like fields are not loosely interpreted: where the documentation says “exactly 1,” WordPress must read the stored value as the string "1".
_cacbot_conversation
Marks a post outside the cacbot-conversation post type as a conversation when exactly 1. Every cacbot-conversation post is recognized without this field.
_cacbot_system_instructions
Plain-text, conversation-specific instructions placed after the global instructions. The value is treated as text: integers are not interpreted as post IDs, and shortcodes are not executed.
_cacbot_include_post_in_context
When exactly 1, appends the post body to the compiled system instruction. Shortcodes are stripped and markup is removed during text sanitization. This is independent of the post.content field that the context API also provides.
This key is intentionally not copied from an Anchor Posts anchor to a linked post. This prevents the linked post’s placeholder body from being added to its instructions.
_cacbot_model
A plain-text model profile name or exact model ID sent as conversation_config.model. The plugin does not validate available models. A compatible processing unit decides which values it supports and what default to use for a missing, blank, or unsupported value.
_cacbot_default_response
A non-blank value is posted immediately as the Assistant’s threaded reply. No mothership job is queued for that comment. The value is filtered through the same allowed-comment-HTML policy as generated replies.
_cacbot_suppress_llm_response
The exact value "1" suppresses remote generation for newly considered comments. It does not suppress a configured _cacbot_default_response and does not cancel work already queued.
Trusted code can override the metadata-derived decision for one comment:
add_filter(
'cacbot_should_respond_to_comment',
static function (bool $shouldRespond, WP_Comment $comment, int $postId): bool {
return $shouldRespond;
},
10,
3
);
The result is cast to boolean. This setting is writable through Cacbot’s metadata route, but is neither exposed in the live-update payload nor copied by the Anchor Posts integration.
_cacbot_max_replies
Despite its historical name, this value limits the total number of approved comments, including both human and Assistant comments. After a local reply is inserted, or after the mothership accepts a job, Cacbot closes comments when:
approved comments + accepted reply still on its way >= stored limit
The plugin does not preflight this limit before processing every programmatically inserted comment; its enforcement action is to set the post’s comment_status to closed.
_cacbot_comment_form_placeholder_text
Replaces only the placeholder attribute of the comment textarea on a singular view. Missing, blank, whitespace-only, and non-text values are ignored.
With Anchor Posts active, a viewer with an effective linked conversation sees the linked post’s placeholder, falling back to the anchor’s value. The anchor value is also among the settings copied when a linked post is created.
👥 Participant metadata
The response pipeline maintains:
_cacbot_interlocutor_user_id: the first user whose comment actually starts a local or remote response._cacbot_respondent_user_id: the provisioned Assistant user selected to reply.
These values describe participants; they do not enforce a two-person conversation. The metadata REST route does not permit either field to be written.
🧩 Compatibility metadata
The plugin recognizes durable integration keys including _cacbot_reply_strategy, _cacbot_action_enabled_create_image, _cacbot_action_enabled_build_plugin, _cacbot_action_enabled_create_new_linked_post, and _cacbot_max_archives. Their presence does not mean this plugin implements those operations or provides a UI for them. Such behavior belongs to companion plugins or the remote processing deployment.
🔄 Reply lifecycle
- WordPress stores an approved, eligible human comment, or a held comment becomes approved.
- Cacbot checks the suppression and fixed-response settings. It marks the comment as processed only when it will attempt a local or remote response.
- Cacbot records the participants. It then inserts
_cacbot_default_response, when configured, or schedules one WP-Cron event. - The cron job sends the post and comment IDs to the mothership using HTTP Basic authentication with the stored mothership credential. Test fixtures may also add a correlation ID.
- The mothership reads a paginated conversation snapshot from the authenticated context endpoint and later returns a reply or terminal outcome.
- Cacbot sanitizes a successful reply and stores it as a threaded comment.
Delivery is attempted at most five times for connection failures, HTTP 429, server errors, and acknowledgements without a job ID. Other HTTP failures are terminal. If initial delivery is unavailable or ultimately fails, Cacbot inserts a visible error reply when it can assign a respondent and records an administrator notice. A mothership no_reply outcome clears the pending state without inserting a reply; a failed outcome inserts an error reply once per job.
📡 Data sent to the mothership
The initial comment-event request contains the post ID and comment ID, plus an optional test correlation ID. The authenticated conversation-context endpoint can then expose:
- Post ID, title, body with shortcodes removed, and GMT creation time.
- Approved comment IDs, parent IDs, GMT creation times, content, and pseudonymous participant labels.
- Whether each comment is human- or Assistant-authored, plus the kind of Assistant reply.
- Combined global, per-conversation, and optionally post-body system instructions.
- The conversation’s sanitized
_cacbot_modelvalue. - The anchor post ID for a valid linked post.
- Whether the triggering comment remains approved.
The context response does not include comment-author names, email addresses, IP addresses, or arbitrary comment metadata. ⚠️ Post and comment content can still contain personal or sensitive information. Site owners are responsible for disclosure, consent, retention, and the privacy terms of their configured mothership and model provider.
🤝 Optional companion plugins
⚓ Anchor Posts
The separate Anchor Posts plugin can provide a public anchor backed by a private linked cacbot-conversation for each signed-in viewer.
- Anchor Posts owns
_cacbot_anchor_post,_cacbot_linked_to, linked-post creation and selection, comment routing, link routes, and cleanup. - Cacbot contributes copyable settings through
aiplugin6647_copy_meta_keys. - Cacbot uses
aiplugin6647\effective_post_id()when that function is available. - An anchor marker alone does not make a post a Cacbot conversation. Outside Anchor Posts’ routing, an ordinary post still needs
_cacbot_conversation = 1.
⚡ Live updates (frontend data service)
On singular views for logged-in users, Cacbot polls a lightweight status endpoint every five seconds and fetches a new payload only when the post has changed. This keeps the title, comments, selected metadata, and the Assistant’s typing state current without reloading the page. The payload never includes the post body.
The AI Style theme also receives live comments, a “Cacbot is thinking” indicator, a flat chronological conversation layout, a login-oriented guest composer, and a simplified admin bar. Anchor Posts can resolve the displayed thread to a viewer-specific linked conversation.
See the frontend data service reference for REST routes, browser events, debugging controls, PHP helpers, filters, security checks, and integration details.
🔐 REST API and security
Cacbot registers routes under cacbot/v1 for metadata updates, installation probing, credential exchange, the API key, conversation-context reads, replies, and outcomes, and the read-only live-update routes under frontend-data/v1 (see Live updates).
- Conversation-context, API-key, reply, and outcome routes accept only the provisioned Assistant authenticated with a recorded mothership application password. A browser session as that user is not sufficient.
POST cacbot/v1/llm-credentialalso requires the job ID that the mothership returned for that comment, accepted within the last day, and is sent withCache-Control: no-store.POST cacbot/v1/meta-datapermits users withmanage_optionsor the Cacbot role. It can write Cacbot’s allowlisted writable keys and any post-meta key WordPress considers unprotected. Other_cacbot_keys, Anchor Posts keys, participant fields, function-registration fields, and protected keys are refused.- Metadata-route values pass through
sanitize_textarea_field. - Replies pass through WordPress’s allowed-comment-HTML policy.
- Reply and failed-outcome delivery is idempotent per remote job ID.
The metadata route is not a general function-calling engine. A compatible processing unit may be configured to update allowed metadata after producing a reply, but this plugin contains no tool plugins, action implementations, or “site doors.” Legacy values in _cacbot_function_library, _cacbot_site_doors, _cacbot_accepted_answers, and _cacbot_guess are not read by the current code.
🚨 Do not expose application passwords, enable HTTP in production, or assign the Cacbot role to untrusted users. Although that role has no ordinary WordPress capabilities, it authorizes the metadata route. The separately provisioned Assistant is assigned the WordPress Editor role.
🩺 Troubleshooting
🤐 A comment receives no generated reply
Check that:
- The commenter is logged in and does not have the Cacbot role.
- The comment is approved.
- The post is a
cacbot-conversationor has_cacbot_conversationexactly equal to1. _cacbot_suppress_llm_responseis not"1", unless a filter overrides it.- Comments are open; Cacbot may have closed them after
_cacbot_max_replieswas reached. - Settings → CACBot reports Connected, and its AI provider key row shows a connected Anthropic or OpenAI key.
- WP-Cron is running and the site can make outbound requests to the configured mothership.
🔃 Replies appear only after refreshing
Live updates run only for logged-in users on singular views. Check the browser console for cacbot:data-service:error, or switch on the debug channel with ?cacbot_debug=verbose as a user who can edit the post.
🔌 Activation or reconnection is incomplete
Review the administrator notice and PHP error log, verify that the configured mothership is reachable over HTTPS, and use Settings → CACBot → Reconnect.
🚧 Product boundaries
- This repository reads no OpenAI API-key constant.
- This repository enforces no free-token allowance.
- Provider names, model profiles, and supported model IDs belong to the remote processing deployment.
- Image creation, plugin building, RAG, shortcode execution, and arbitrary function execution are not implemented merely because compatibility metadata keys exist.
📜 License
The plugin header identifies the software as proprietary: “Copyright (C) AI_PLUGIN_DEV 2026. ALL RIGHTS RESERVED. THIS IS NOT FREE SOFTWARE.” Consult the distributor for complete license terms before redistribution or modification.
