1. Go to this page and download the library: Download vonage/vonage_drupal 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 / vonage_drupal example snippets
namespace Drupal\my_module\Controller;
use Vonage\Client;
use Vonage\SMS\Message\SMS;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MyController extends ControllerBase
{
/**
* @var Client
*/
protected $client;
public function __construct($client)
{
$this->client = $client;
}
public static function create(ContainerInterface $container)
{
return new static($container->get(Client::class));
}
public function controllerAction(): array
{
$this->client->sms()->send(
new SMS($to, from, $message)
);
$build = [
'#markup' => 'Hello World!',
];
return $build;
}
}
namespace Drupal\my_module\Controller;
use Vonage\SMS\Webhook\Factory;
use Vonage\SMS\Webhook\InboundSMS;
use Drupal\Core\Controller\ControllerBase;
class MyController extends ControllerBase
{
public function incomingSMS(): array
{
/** @var InboundSMS $inboundSMS */
$inboundSMS = Factory::createFromGlobals();
$to = $inboundSMS->getTo();
$from = $inboundSMS->getFrom();
$text = $inboundSMS->getText();
// ...
}
}
namespace Drupal\my_module\Controller;
use Vonage\Voice\Webhook\Factory;
use Vonage\Voice\Webhook\Answer;
use Drupal\Core\Controller\ControllerBase;
class MyController extends ControllerBase
{
public function answerCall(): array
{
/** @var Answer $inboundCall */
$inboundCall = Factory::createFromGlobals();
$to = $inboundCall->getTo();
$from = $inboundCall->getFrom();
$uuid = $inboundCall->getUuid();
// ...
}
}
namespace Drupal\my_module\Controller;
use Vonage\Voice\Webhook\Factory;
use Vonage\Voice\Webhook\Answer;
use Vonage\Voice\Webhook\Event;
use Drupal\Core\Controller\ControllerBase;
class MyController extends ControllerBase
{
public function voiceEventHandler(): array
{
$event = Factory::createFromGlobals();
if ($event instanceof Event) {
// ...
} elseif ($event instanceof Notification) {
// ...
}
// ...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.