PHP code example of nextgenswitch / nextgenswitch-php
1. Go to this page and download the library: Download nextgenswitch/nextgenswitch-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/ */
nextgenswitch / nextgenswitch-php example snippets
use NextGenSwitch\Client;
$client = new Client(
baseUrl: getenv('NEXTGENSWITCH_BASE_URL'),
authorizationCode: getenv('NEXTGENSWITCH_AUTHORIZATION'),
authorizationSecret: getenv('NEXTGENSWITCH_AUTHORIZATION_SECRET'),
);
use NextGenSwitch\VoiceResponse;
$voice = (new VoiceResponse())
->say('Welcome to NextGenSwitch.')
->gather(
[
'action' => 'https://example.com/gather',
'method' => 'POST',
'numDigits' => 1,
'timeout' => 10,
],
static fn ($gather) => $gather->say('Press one for sales.'),
);
$result = $client->createCall(
to: '2001',
from: '1001',
responseXml: $voice,
statusCallback: 'https://example.com/call-status',
);
$call = $result->data();
$result = $client->createCall(
to: '2001',
from: '1001',
responseUrl: 'https://example.com/call-flow.xml',
);
$updatedFlow = (new VoiceResponse())
->pause(2)
->say('Your call flow has been updated.')
->dial('1000');
$client->modifyCall('CALL-123', $updatedFlow);