kimaai_chatbot_prompt

When it fires

First thing in a chatbot request (POST /wp-json/kimaai/v1/chatbot), and in a search answer (assistantSurface search) before the answer cache is looked up. Nothing has run before it: after it come the masking of card numbers and IBANs, kimaai_chatbot_gate, the daily limit and the maximum message length, which counts the filtered message.

What the filter returns is the message from then on: the gate checks it, the provider gets it, and the chat history stores it. Return a string. In a search answer the cache key stays on the visitor’s own query.

Parameters

NameTypeDescription
promptmixedThe visitor’s message as the request sent it, a string.
dataarrayThe request’s JSON body.
requestWP_REST_RequestThe REST request.

Returns

mixed: The message to use, a string.

Example

add_filter(
  'kimaai_chatbot_prompt',
  function ($prompt, array $data, WP_REST_Request $request) {
    if (!is_string($prompt)) {
      return $prompt;
    }

    // One line, without the blank space a pasted text brings along.
    return trim((string) preg_replace('/\s+/u', ' ', $prompt));
  },
  10,
  3
);
  • kimaai_chatbot_gate: blocks a message after this filter.
  • kimaai_chatbot_ai_payload: changes the whole request to the provider, not only the message.

What are your feelings