1. Go to this page and download the library: Download vonage/client-core 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/ */
vonage / client-core example snippets
$client = new Vonage\Client(new Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));
$client = new Vonage\Client(
new Vonage\Client\Credentials\Basic(API_KEY, API_SECRET),
[
'base_api_url' => 'https://example.com'
]
);
$text = new \Vonage\SMS\Message\SMS(VONAGE_TO, VONAGE_FROM, 'Test message using PHP client library');
$text->setClientRef('test-message');
$response = $client->sms()->send($text);
$data = $response->current();
echo "Sent message to " . $data->getTo() . ". Balance is now " . $data->getRemainingBalance() . PHP_EOL;
$client = new Vonage\Client(new Vonage\Client\Credentials\SignatureSecret(API_KEY, SIGNATURE_SECRET, 'sha256'));
$signature = new \Vonage\Client\Signature($_GET, SIGNATURE_SECRET, 'sha256');
// is it valid? Will be true or false
$isValid = $signature->check($_GET['sig']);
$whatsAppText = new Vonage\Messages\Channel\WhatsApp\WhatsAppText(
FROM_NUMBER,
TO_NUMBER,
'this is a WA text from vonage'
);
$request = new \Vonage\Verify\Request('14845551212', 'My App');
$response = $client->verify()->start($request);
echo "Started verification with an id of: " . $response->getRequestId();
$request = new \Vonage\Verify\RequestPSD2('14845551212', 'My App');
$response = $client->verify()->requestPSD2($request);
echo "Started verification with an id of: " . $response['request_id'];
$client = new Vonage\Client(
new Vonage\Client\Credentials\Basic(API_KEY, API_SECRET),
);
$smsRequest = new \Vonage\Verify2\Request\SMSRequest('TO_NUMBER');
$client->verify2()->startVerification($smsRequest);
$client = new Vonage\Client(
new Vonage\Client\Credentials\Basic(API_KEY, API_SECRET),
);
$smsRequest = new \Vonage\Verify2\Request\SMSRequest('TO_NUMBER', 'my-verification');
$voiceWorkflow = new \Vonage\Verify2\VerifyObjects\VerificationWorkflow(\Vonage\Verify2\VerifyObjects\VerificationWorkflow::WORKFLOW_VOICE, 'TO_NUMBER');
$smsRequest->addWorkflow($voiceWorkflow);
$client->verify2()->startVerification($smsRequest);
// From a request object
$verificationEvent = \Vonage\Verify2\Webhook\Factory::createFromRequest($request);
var_dump($verificationEvent->getStatus());
// From an array
$payload = $request->getBody()->getContents()
$verificationEvent = \Vonage\Verify2\Webhook\Factory::createFromArray($payload);
var_dump($verificationEvent->getStatus());
$basic = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$keypair = new \Vonage\Client\Credentials\Keypair(
file_get_contents(VONAGE_APPLICATION_PRIVATE_KEY_PATH),
VONAGE_APPLICATION_ID
);
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Container($basic, $keypair));
$outboundCall = new \Vonage\Voice\OutboundCall(
new \Vonage\Voice\Endpoint\Phone('14843331234'),
new \Vonage\Voice\Endpoint\Phone('14843335555')
);
$outboundCall
->setAnswerWebhook(
new \Vonage\Voice\Webhook('https://example.com/webhooks/answer')
)
->setEventWebhook(
new \Vonage\Voice\Webhook('https://example.com/webhooks/event')
)
;
$response = $client->voice()->createOutboundCall($outboundCall);
$credentials = new \Vonage\Client\Credentials\Gnp(
'0777888888',
file_get_contents('./private.key'),
'0dadaeb4-7c79-4d39-b4b0-5a6cc08bf537'
);
$client = new \Vonage\Client($credentials);
$swapResult = $client->simswap()->checkSimSwap('07999999999', 500);
if ($swapResult) {
echo "Warning: SIM Swapped recently"
} else {
echo "SIM OK"
};
// Finding the swap date
echo $client->simswap()->checkSimSwapDate('07999999999');
$outboundCall = new \Vonage\Voice\OutboundCall(
new \Vonage\Voice\Endpoint\Phone('14843331234'),
new \Vonage\Voice\Endpoint\Phone('14843335555')
);
$ncco = new NCCO();
// ADD ACTIONS TO THE NCCO OBJECT HERE
$outboundCall->setNCCO($ncco);
$response = $client->voice()->createOutboundCall($outboundCall);
$outboundCall = new \Vonage\Voice\OutboundCall(
new \Vonage\Voice\Endpoint\Phone('14843331234'),
new \Vonage\Voice\Endpoint\Phone('14843335555')
);
$ncco = new NCCO();
$ncco->addAction(\Vonage\Voice\NCCO\Action\Record::factory([
'eventUrl' => 'https://example.com/webhooks/event'
]);
$outboundCall->setNCCO($ncco);
$response = $client->voice()->createOutboundCall($outboundCall);
$outboundCall = new \Vonage\Voice\OutboundCall(
new \Vonage\Voice\Endpoint\Phone('14843331234'),
new \Vonage\Voice\Endpoint\Phone('14843335555')
);
$ncco = new NCCO();
$ncco->addAction(new \Vonage\Voice\NCCO\Action\Talk('This is a text to speech call from Vonage'));
$outboundCall->setNCCO($ncco);
$response = $client->voice()->createOutboundCall($outboundCall);
$outboundCall = new \Vonage\Voice\OutboundCall(
new \Vonage\Voice\Endpoint\Phone('14843331234'),
new \Vonage\Voice\Endpoint\Phone('14843335555')
);
$ncco = new NCCO();
$ncco->addAction(new \Vonage\Voice\NCCO\Action\Stream('https://example.com/sounds/my-audio.mp3'));
$outboundCall->setNCCO($ncco);
$response = $client->voice()->createOutboundCall($outboundCall);
$outboundCall = new \Vonage\Voice\OutboundCall(
new \Vonage\Voice\Endpoint\Phone('14843331234'),
new \Vonage\Voice\Endpoint\Phone('14843335555')
);
$ncco = new NCCO();
$ncco->addAction(\Vonage\Voice\NCCO\Action\Talk::factory('Please record your name.',[
'bargeIn' => true,
]));
$ncco->addAction(\Vonage\Voice\NCCO\Action\Input::factory([
'eventUrl' => 'https://example.com/webhooks/event',
'type' => [
'speech',
],
'speech' => [
'endOnSilence' => true,
],
]));
$outboundCall->setNCCO($ncco);
$response = $client->voice()->createOutboundCall($outboundCall);
$outboundCall = new \Vonage\Voice\OutboundCall(
new \Vonage\Voice\Endpoint\Phone('14843331234'),
new \Vonage\Voice\Endpoint\Phone('14843335555')
);
$ncco = new NCCO();
$ncco->addAction(new \Vonage\Voice\NCCO\Action\Talk('We are just testing the notify function, you do not need to do anything.'));
$ncco->addAction(new \Vonage\Voice\NCCO\Action\Notify([
'foo' => 'bar',
], new Vonage\Voice\Webhook('https://example.com/webhooks/notify')));
$outboundCall->setNCCO($ncco);
$response = $client->voice()->createOutboundCall($outboundCall);
$credentials = new \Vonage\Client\Credentials\Gnp(
'tel:+447700900000',
fopen('./my-private-key'),
'my-application-id'
);
$client = new \Vonage\Client($credentials);
$date = $client->simswap()->checkSimSwapDate('07700009999')
echo $date;
try {
$insights = $client->insights()->basic(PHONE_NUMBER);
echo $insights->getNationalFormatNumber();
} catch (Exception $e) {
// for the Vonage-specific exceptions, try the `getEntity()` method for more diagnostic information
}
try {
$client->insights()->advancedAsync(PHONE_NUMBER, 'http://example.com/webhooks/number-insights');
} catch (Exception $e) {
// for the Vonage-specific exceptions, try the `getEntity()` method for more diagnostic information
}