Skip to content

VK callback

POST
/wp-json/wp2tutor-bot/vk/v1/callback/{channel_id}
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.

channel_id
required
integer

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
12
Media typeapplication/json
object
type

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.

string
secret

Callback API secret. Compared to channel meta. Empty in channel settings — 403 secret_required. Mismatch — 403 forbidden.

string
object

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
key
additional properties
any
key
additional properties
any
Example
{
"type": "message_new",
"secret": "callback-secret",
"object": {
"message": {
"peer_id": 2000000001,
"text": "Hello",
"out": 0
}
}
}

text/plain: ok (message handled, other type, channel disabled, no text) or the confirmation string from channel meta. Not JSON.

Media typetext/plain
string
Example
ok

config_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}).

string
Example
config_missing

secret_required — channel secret is empty. forbidden — JSON secret empty or mismatch. Both are JSON {ok: false, error}, not text/plain.

Media typeapplication/json
object
ok
required

True — webhook/callback accepted (including a quiet ack). false — see error.

boolean
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.

string
Example
{
"ok": false,
"error": "forbidden"
}

not_found — no wp2tutor_channel post or type is not vk. Body is that string, text/plain.

Media typetext/plain
string
Example
not_found