PHP code example of telnyx / telnyx-php

1. Go to this page and download the library: Download telnyx/telnyx-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

telnyx / telnyx-php example snippets




\Telnyx\Telnyx::setApiKey('YOUR_API_KEY_HERE');

// Get a list of messaging profiles
$result = \Telnyx\MessagingProfile::all();

// Output list of messaging profiles
print_r($result);

// set up your tweaked Curl client
$curl = new \Telnyx\HttpClient\CurlClient();
$curl->setTimeout(10); // default is Telnyx\HttpClient\CurlClient::DEFAULT_TIMEOUT
$curl->setConnectTimeout(5); // default is Telnyx\HttpClient\CurlClient::DEFAULT_CONNECT_TIMEOUT

echo $curl->getTimeout(); // 10
echo $curl->getConnectTimeout(); // 5

// tell Telnyx to use the tweaked client
\Telnyx\ApiRequestor::setHttpClient($curl);

// use the Telnyx API client as you normally would

// set up your tweaked Curl client
$curl = new \Telnyx\HttpClient\CurlClient([CURLOPT_PROXY => 'proxy.local:80']);
// tell Telnyx to use the tweaked client
\Telnyx\ApiRequestor::setHttpClient($curl);

\Telnyx\Telnyx::setLogger($logger);

$order = \Telnyx\NumberOrder::create(['phone_number' => '+18665552368']);
print_r($order->getLastResponse()->headers);

$curl = new \Telnyx\HttpClient\CurlClient([CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1]);
\Telnyx\ApiRequestor::setHttpClient($curl);

\Telnyx\NumberOrder::all([], [
    'api_key' => 'KEY0123...'
]);

\Telnyx\NumberOrder::retrieve("12ade33a-21c0-473b-b055-b3c836e1c292", [
    'api_key' => 'KEY0123...'
]);

\Telnyx\Telnyx::setMaxNetworkRetries(2);

\Telnyx\Telnyx::setAppInfo("MyCustomPlugin", "1.2.3", "https://customplugin.yoursite.com");
bash
$ composer 

docker-compose run --rm php composer test

docker-compose run --rm php composer test-coverage