# ChatBot hooks

> Actions and filters of the ChatBot module: messages and replies, leads, knowledge gaps, AI context, access labels, AI Actions, rate limits, site search and the launcher.

Source: https://www.wpbot.pro/help/dev-chatbot-hooks/  
Section: Developers › Hooks  
Updated: 2026-11-26

The ChatBot module's hooks start with `qcld_wpbot_chat/`. The function `qcld_wpbot_chat()` returns the running module. Every conversation, from the chat window and from other channels, goes through the same engine, so these hooks see all of them.

## Conversations

| Hook | Type | Parameters | What it is for |
| --- | --- | --- | --- |
| `qcld_wpbot_chat/message_received` | action | `Message $message` | A visitor message arrived |
| `qcld_wpbot_chat/message_sent` | action | `Reply $reply`, `Message $message` | The bot answered |
| `qcld_wpbot_chat/ai_failed` | action | `Reply $reply`, `Message $message` | The AI provider failed; visitors got the friendly message |
| `qcld_wpbot_chat/session_saved` | action | `$session_id`, `$wpbot_user_id`, `bool $is_new` | A chat session was saved |
| `qcld_wpbot_chat/pipeline_steps` | filter | `Step[] $steps` | The answer steps in order: Simple Text Responses, Dialogflow, site search, knowledge base, AI, fallback. Add your own step object with `id()`, `enabled()` and `handle( Message, Context )` returning a `Reply` or `null` |

**`Message`** has `text`, `session_id`, `name`, `language`, `channel` (`web`, `messenger`, `whatsapp`, `telegram` …), `history`, `page_url`, `page_title` and `extra`. **`Reply`** has `source` (which step answered: `str`, `search`, `ai`, `dialogflow`, `fallback` or an extension's id), `text`, `html`, `data` and `meta` (provider, model, tokens).

## Leads and forms

| Hook | Type | Parameters | What it is for |
| --- | --- | --- | --- |
| `qcld_wpbot_chat/lead_captured` | action | `array $lead`: `name`, `email`, `phone`, `url` (some sources add `channel`, `consent`) | A lead was saved in the chat. AI Marketing listens to it too |
| `qcld_mailing_list_subscription_success` | action | `$name`, `$email` | Older hook for the same event, still fired |
| `qcld_wpbot_chat/ai_form_saved` | action | `$post_id`, `$title`, `array $fields` | An AI Actions form entry was saved |
| `qcld_wpbot_chat/action_ran` | action | `$outcome`, `array $data`, `Message $message` | An AI Action ran |
| `qcld_wpbot_chat/actions` | filter | `array $actions` | The Actions the AI may run (`id => { name, description, fields, steps, reply, … }`) |

### Example: send every lead to your CRM

```
add_action( 'qcld_wpbot_chat/lead_captured', function ( array $lead ) {
	if ( empty( $lead['email'] ) ) {
		return;
	}
	wp_remote_post( 'https://crm.example.com/api/leads', array(
		'timeout' => 10,
		'body'    => array(
			'email' => $lead['email'],
			'name'  => isset( $lead['name'] ) ? $lead['name'] : '',
			'page'  => isset( $lead['url'] ) ? $lead['url'] : '',
		),
	) );
} );
```

## Knowledge gaps and Train

| Hook | Type | Parameters | What it is for |  |
| --- | --- | --- | --- | --- |
| `qcld_wpbot_chat/knowledge_gap` | action | `string $question`, `string $reason`, \`Message\\ | null $message\` | A question nobody answered. `$reason`: `no_answer`, `not_sure`, `thumbs_down`, `handoff`; the Help Center adds `docs_search`, `not_helpful` and `ai_search`. Fire it yourself to add a question to **ChatBot → Train** |
| `qcld_wpbot_chat/gap_answered` | action | `$gap`, `string $answer` | The owner answered a gap in Train |  |
| `qcld_wpbot_chat/gap_write_article` | filter | `string $url`, `$gap` | The address that "Write article" opens for a gap |  |
| `qcld_wpbot_chat/person_request_pattern` | filter | `string $regex` | How WPBot recognises a visitor asking for a person |  |
| `qcld_wpbot_chat/not_sure_phrases` | filter | `string[] $regexes` | Phrases that mark an AI answer as "not sure" |  |

## Answers and AI

| Hook | Type | Parameters | What it is for |
| --- | --- | --- | --- |
| `qcld_wpbot_chat/ai_context` | filter | `string[] $parts`, `Message $message` | Extra system text sent to the AI with a question, for example today's opening hours from your booking plugin |
| `qcld_wpbot_chat/answer_scope` | filter | `string $scope` | `business_only`, `business_first` or `anything` for one reply |
| `qcld_wpbot_chat/answer_cache` | filter | `bool $use`, `string $question`, `array $args` | Whether an answer may come from or go into the answer cache. Never return `true` for answers that used personal data |
| `qcld_wpbot_chat/citations_enabled` | filter | `bool $on` | Whether knowledge-based replies list their sources |
| `qcld_wpbot_chat/page_context_allowed` | filter | `bool $ok`, `WP_Post $post`, `string[] $labels` | Whether the AI may read the page the visitor is on (membership plugins can say no) |
| `qcld_wpbot_chat/page_context_max` | filter | `int $chars`, `WP_Post $post` | How much of the page text is sent |
| `qcld_wpbot_chat/handoff_buttons` | filter | `array $buttons` | Buttons offered when the bot is not sure |
| `qcld_wpbot_chat/debug_allowed` | filter | `bool $allowed` | Whether replies carry the admin debug details (default: administrators) |

### Example: add live facts to every AI question

```
add_filter( 'qcld_wpbot_chat/ai_context', function ( array $parts, $message ) {
	$parts[] = 'Today the shop is open from 9:00 to 17:00.';
	return $parts;
}, 10, 2 );
```

## Access labels

`qcld_wpbot_chat/visitor_labels` (filter: `string[] $labels`, `Message $message`, `WP_User|null $user`) lists what the visitor may see in the knowledge base. Everyone has `public`; logged-in visitors also have `logged_in` and `role:<role>`. Add labels such as `membership:gold` or `course:42` from your membership or LMS plugin; knowledge items with labels the visitor lacks are left out before the search. Messages from Messenger, WhatsApp or Telegram have no WordPress user and see public knowledge only. See [Feed your own data to the chatbot's knowledge base](/help/dev-extend-the-knowledge-base/).

## Limits and security

| Hook | Type | Parameters | What it is for |
| --- | --- | --- | --- |
| `qcld_wpbot_chat/rate_limit` | filter | `[ requests, seconds ]`, `string $bucket` | Limits per bucket: `ai` (default 60 a day for guests), `message`, `session`, `lead`, `feedback`, `report`, `token` |
| `qcld_wpbot_chat/rate_limit_text` | filter | `string $text` | Text shown when the AI limit is reached |
| `qcld_wpbot_chat/visitor_ip` | filter | `string $ip` | The visitor IP used for limits; set it from a trusted proxy header if your site is behind one |
| `qcld_wpbot_chat/allowed_hosts` | filter | `string[] $hosts` | Domains the chat's requests may come from. Add your other domains when one site answers on several (for example one domain per language) |

## Site search

| Hook | Type | Parameters | What it is for |  |
| --- | --- | --- | --- | --- |
| `qcld_wpbot_chat/search_post_types` | filter | `string[] $types` | Post types the chatbot's site search covers |  |
| `qcld_wpbot_chat/search_limit` | filter | `int $limit` | Results per page |  |
| `qcld_wpbot_chat/search_terms` | filter | `string[] $terms`, `string $keyword` | Words searched for (synonyms are added here) |  |
| `qcld_wpbot_chat/faq_match` | filter | \`array\\ | null $best`, `string $text`, `string $language\` | The FAQ entry that answers a question |

## Loading and caching

| Hook | Type | Parameters | What it is for |
| --- | --- | --- | --- |
| `qcld_wpbot_chat/lazy_widget` | filter | `bool $on` | Return `false` to load the full chat with the page instead of on the first interaction |
| `qcld_wpbot_chat/launcher_config` | filter | `array $config` | The launcher's mode (`interaction`, `idle`, `now`), selectors and files |
| `qcld_wpbot_chat/icon_delay` | filter | `int $ms` | Delay before the chat icon shows |
| `qcld_wpbot_chat/prefetch_delay` | filter | `int $ms` | Fetch the chat's files in the background after this delay (0 = off, the default) |
| `qcld_wpbot_chat/purge_cache_on_save` | filter | `bool $on` | Return `false` to stop WPBot clearing your page and object caches after its settings are saved |
| `qcld_wpbot_chat/cache_purged` | action | `string[] $cleared` | Caches WPBot cleared after a save |

The constant `WPBOT_LAZY_WIDGET_DISABLE` (set to `true` in `wp-config.php`) also turns the on-demand loading off.

## Module Manager and Abilities

- `qcld_wpbot_chat/register_modules` (action, `$registry`): register a feature that the owner switches on in the [Turn modules on and off in the Module Manager](/help/module-manager/) with `$registry->register( array( 'id', 'name', 'description', 'default', 'path', 'order' ) )`.
- `qcld_wpbot_chat/abilities` (filter): the chatbot's WordPress Abilities. See [WordPress Abilities for the chatbot and the Help Center](/help/dev-wordpress-abilities/).

## Availability

In every edition, including WPBot Free. WPBot Pro adds channels (Messenger, Instagram, WhatsApp, Telegram; **Master**), whose messages pass through the same hooks with their own `channel` value, and Pro Actions (store, REST and WordPress function steps; **Professional** and **Master**).
