Webhooks

Receive SMS as HTTP callbacks and parse them with parseWebhook.

Set a URL with $client->user->setWebhookUrl. For each SMS the server POSTs a JSON body to it: webhook_type receiving_sms for numbers, rent_sms for rents. Delivery attempts are listed by $client->user->webhookLogs.

parseWebhook

Parse an inbound webhook body from a JSON string or an already decoded array. A namespaced function, not a client method.

function parseWebhook(string|array $payload): array

Lenient: numeric fields may arrive as strings, missing or malformed fields become null, unknown fields are dropped. It throws OnlineSimError only when the input is not a JSON object.

use function s00d\OnlineSimApi\parseWebhook;

// webhook.php, the URL you passed to setWebhookUrl
$hook = parseWebhook((string) file_get_contents('php://input'));
if ($hook['webhook_type'] === 'receiving_sms') {
    error_log("operation {$hook['operation_id']}: code {$hook['code']}");
}
echo 'ok';

Payload fields

FieldTypeDescription
webhook_type'receiving_sms'|'rent_sms'|nullKind of operation.
operation_id?inttzid of the operation or rent.
user_id?intAccount id.
country_code?intCountry code of the number.
number?stringNumbers: + and the full number (+79001234567), or hidden. Rent: the full number in digits without + (79001234567).
sender?stringSender of the SMS, e.g. VK.
message?stringFull SMS text.
code?stringCode extracted from the SMS; '' when none was found.
time_start?stringNumbers: when the operation was ordered. Rent: when the SMS arrived. YYYY-MM-DD HH:MM:SS.
time_left?intTime left: seconds for numbers, minutes for rent.