VK callback
const url = 'https://example.com/wp-json/wp2tutor-bot/vk/v1/callback/12';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"type":"message_new","secret":"callback-secret","object":{"message":{"peer_id":2000000001,"text":"Hello","out":0}}}'};
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/vk/v1/callback/12 \ --header 'Content-Type: application/json' \ --data '{ "type": "message_new", "secret": "callback-secret", "object": { "message": { "peer_id": 2000000001, "text": "Hello", "out": 0 } } }'VK community Callback API. Public URL. PHP first checks the post is wp2tutor_channel type vk, then token+group_id, then JSON: field secret must match meta wp2tutor_bot_vk_secret. type=confirmation returns the channel confirmation string; message_new with inbound text goes through AnswerService and messages.send.
Success and some errors are text/plain (VK expects raw ok / confirmation, not JSON). plain() sets Content-Type: text/plain; charset=UTF-8. A messages.send failure is logged; the client still gets 200 ok so VK does not retry-storm.
invalid_json / secret_required / forbidden from parseInbound are JSON {ok, error}: the controller only forces text/plain when response data is a string.
Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”CPT wp2tutor_channel post ID, not the VK group_id. Required (path (?P<channel_id>\d+)). Metabox URL: rest_url( wp2tutor-bot/vk/v1/callback/{post_id} ). <= 0, not wp2tutor_channel, or channel type is not vk — 404, body not_found (text/plain).
Example
12Request Body
Section titled “Request Body”object
Callback API event type. confirmation — return the confirmation string. message_new — parse inbound. Any other value (and empty type) — 200 ok after secret checks out.
Callback API secret. Compared to channel meta. Empty in channel settings — 403 secret_required. Mismatch — 403 forbidden.
For message_new: object.message (or object itself) with text and peer_id or from_id. out=1 (community outgoing) and empty text — 200 ok with no user reply.
object
Example
{ "type": "message_new", "secret": "callback-secret", "object": { "message": { "peer_id": 2000000001, "text": "Hello", "out": 0 } }}Responses
Section titled “Responses”text/plain: ok (message handled, other type, channel disabled, no text) or the confirmation string from channel meta. Not JSON.
Example
okconfig_missing — no VK token or group_id (text/plain, error code as body). invalid_json — body is not a JSON object (application/json {ok: false, error: invalid_json}).
Example
config_missingobject
True — webhook/callback accepted (including a quiet ack). false — see error.
Machine code when ok: false. Telegram/controller: bot_not_found, token_missing, secret_required, forbidden, invalid_json, telegram_api_error. VK JSON: invalid_json, secret_required, forbidden. Not a human message and not a WP_Error object.
Example
{ "ok": false, "error": "invalid_json"}secret_required — channel secret is empty. forbidden — JSON secret empty or mismatch. Both are JSON {ok: false, error}, not text/plain.
object
True — webhook/callback accepted (including a quiet ack). false — see error.
Machine code when ok: false. Telegram/controller: bot_not_found, token_missing, secret_required, forbidden, invalid_json, telegram_api_error. VK JSON: invalid_json, secret_required, forbidden. Not a human message and not a WP_Error object.
Example
{ "ok": false, "error": "forbidden"}not_found — no wp2tutor_channel post or type is not vk. Body is that string, text/plain.
Example
not_found