[WEBHOOK] You can use this example as a basis for your own PHP Webhook

C:\xampp824\htdocs\phongkhamnet\callback.php

<?php
$entityBody = file_get_contents('php://input');
$messages = json_decode(utf8_encode($entityBody));
if (json_last_error()) {
    $warning = "JSON parsing error: " . json_last_error();
    print $warning;
    error_log($warning);
    return;
}
foreach ($messages as &$message) {
    if ($message->{'type'} === 'RECEIVED') {
        printf ("Message received from [%s] ID [%s] body [%s]", $message->{'from'}, $message->{'id'},
            $message->{'body'});
    } else if ($message->{'type'} === 'SENT') {
        printf ("Message sent to [%s] ID [%s] body [%s]", $message->{'to'}, $message->{'id'},
            $message->{'body'});
    }
}
php -S localhost:8188
curl -X POST -H 'Content-Type: application/json' -d '[ {  "id": "30000000001", "type": "RECEIVED", "from": "44987654321", "to": "44123456789", "body": "This is a test", "encoding": "TEXT", "protocolId": 0, "messageClass": 2, "numberOfParts": 1, "creditCost": 0, "submission": { "id": "2-30000000001", "date": "2019-08-05T11:30:12Z"}, "status": { "id": "DELIVERED.null", "type": "DELIVERED" }, "relatedSentMessageId": null, "userSuppliedId": null } ]' http://localhost:8188/callback.php

Last updated