Deep Chat message endpoint
const url = 'https://example.com/wp-json/wp2tutor-bot/deepchat/v1/chat/123';const options = { method: 'POST', headers: { 'X-Wp2tutor-Bot-Secret': '<X-Wp2tutor-Bot-Secret>', 'Content-Type': 'application/json' }, body: '{"messages":[{"role":"user","text":"Hello"}]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://example.com/wp-json/wp2tutor-bot/deepchat/v1/chat/123 \ --header 'Content-Type: application/json' \ --header 'X-Wp2tutor-Bot-Secret: <X-Wp2tutor-Bot-Secret>' \ --data '{ "messages": [ { "role": "user", "text": "Hello" } ] }'Deep Chat connect contract. Public POST: cookie/nonce are not checked. Header X-Wp2tutor-Bot-Secret must match meta wp2tutor_bot_dc_secret. CORS is open (request Origin or *); the dc_origins whitelist is not applied in this controller.
Request body is {messages: [{role, text}, …]} (widget shape). PHP requires a non-empty messages array and at least one role=user message with non-empty text. Success body is {text} only (string from LlmAnswerService / ChatProxyService). Layer errors are {error} with a human-readable string, not WP_Error {code,message,data} and not Telegram/VK machine codes.
Limit: 20 requests / 60 s per key deepchat|{IP}|{channel_id} (RequestRateLimiter). WP2Tutor Ai module must be enabled.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”CPT wp2tutor_channel post ID of type deepchat. Required (path (?P<channel_id>\d+)). Metabox URL and connect example: …/deepchat/v1/chat/{post_id}. Not the widget session id. <= 0, not wp2tutor_channel, or type is not deepchat — 404 {error}.
Example
123Request Bodyrequired
Section titled “Request Bodyrequired”object
Deep Chat widget messages. Required and non-empty, otherwise 400. PHP scans from the end for the first role=user with non-empty text; the LLM gets a window of the last ~12 turns (user / ai|assistant / system).
object
Role in the widget chat: user, ai or assistant, system. Not a WordPress user role. Inbound parse needs at least one user.
Widget turn text. PHP skips user messages with empty text.
Example
{ "messages": [ { "role": "user", "text": "Hello" } ]}Responses
Section titled “Responses”Model reply. Body is {text} only — PHP string $reply. No upstream extra fields.
object
Assistant reply text. The only 200 field: PHP WP_REST_Response( [ 'text' => $reply ], 200 ).
Example
{ "text": "Short assistant reply"}Empty body, not JSON, no messages array, no user text (Empty request body. / Invalid JSON. / messages array is required. / No user message found.), or Could not build a prompt from messages. Body {error}.
object
Human-readable string (__() / WP_Error message / LLM text). PHP: {error: $message}. Not a Telegram/VK machine code and not {code,message,data}.
Example
{ "error": "messages array is required."}Invalid secret. — header empty or does not match the channel secret (channel found and secret is set in meta).
object
Human-readable string (__() / WP_Error message / LLM text). PHP: {error: $message}. Not a Telegram/VK machine code and not {code,message,data}.
Example
{ "error": "Invalid secret."}Forbidden. — reserved for DualRest/capability rejection if the request is treated as an authenticated cookie session (this endpoint is secret-gated and normally returns 401 for a bad secret).
object
Human-readable string (__() / WP_Error message / LLM text). PHP: {error: $message}. Not a Telegram/VK machine code and not {code,message,data}.
Example
{ "error": "Forbidden."}Channel not found. — no wp2tutor_channel post or type is not deepchat.
object
Human-readable string (__() / WP_Error message / LLM text). PHP: {error: $message}. Not a Telegram/VK machine code and not {code,message,data}.
Example
{ "error": "Channel not found."}Too many requests. Please try again later. — more than 20 requests in 60 s from this IP for this channel.
object
Human-readable string (__() / WP_Error message / LLM text). PHP: {error: $message}. Not a Telegram/VK machine code and not {code,message,data}.
Example
{ "error": "Too many requests. Please try again later."}Failed to encode prompt. — wp_json_encode of the prompt did not return a string.
object
Human-readable string (__() / WP_Error message / LLM text). PHP: {error: $message}. Not a Telegram/VK machine code and not {code,message,data}.
Example
{ "error": "Failed to encode prompt."}Channel disabled (Channel disabled.), channel secret not set (Channel secret is not configured.), Ai module unavailable/disabled, LLM failure, or empty model reply. Body {error} with the PHP message.
object
Human-readable string (__() / WP_Error message / LLM text). PHP: {error: $message}. Not a Telegram/VK machine code and not {code,message,data}.
Example
{ "error": "WP2Tutor Ai module is not available."}