Using Twilio PHP SDK

If you are using the Twilio PHP SDK, you can swap out the URL to point to the MessageBird Twilio Adapter, by using a custom HTTP Client.

<?php

class MyTwilioAdapterClient extends Twilio\Http\CurlClient
{

    public function options(
        string $method,
        string $url,
        array $params = [],
        array $data = [],
        array $headers = [],
        string $user = null,
        string $password = null,
        int $timeout = null
    ): array {
        $adapterUrl = str_replace("https://api.twilio.com/", "https://eu-west-1.twilio.to.nest.messagebird.com/", $url);

        return parent::options($method, $adapterUrl, $params, $data, $headers, $user, $password, $timeout);
    }
}

// Your Account SID and Auth Token
$accountSid = "ACXXXXXX";
$authToken = "YYYYYY";

$httpClient = new MyTwilioAdapterClient();
$client = new Twilio\Rest\Client($accountSid, $authToken, null, null, $httpClient);

You can try it out with the following example:

Last updated

Was this helpful?