PHP code example of webonaute / twilio-bundle

1. Go to this page and download the library: Download webonaute/twilio-bundle 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/ */

    

webonaute / twilio-bundle example snippets


$bundles = array(
	// ... other bundles
	new Webonaute\TwilioBundle\WebonauteTwilioBundle(),
);

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Twilio\Rest\Client;

class TestController extends Controller
{
    public function smsAction()
    {
        /** @var \Twilio\Rest\Client */
    	$twilio = $this->get('twilio.client');
        
        $date = date('r');
        
        $message = $twilio->messages->create(
            '+12125551234', // Text any number
            array(
                'from' => '+14085551234', // From a Twilio number in your account
                'body' => "Hi there, it's $date and Twilio is working properly."
            )
        );

        return new Response("Sent message [$message->sid] via Twilio.");
    }
}

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Twilio\Rest\Client;

class TwilioTestCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('twilio:test:sms')
            ->setDescription('Test the Twilio integration by sending a text message.')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        //** @var \Twilio\Rest\Client */
        $twilio = $this->get('twilio.client');
         
         $date = date('r');
         
         $message = $twilio->messages->create(
             '+12125551234', // Text any number
             array(
                 'from' => '+14085551234', // From a Twilio number in your account
                 'body' => "Hi there, it's $date and Twilio is working properly."
             )
         );
        
        $output->writeln("Sent message [$message->sid] via Twilio.");
    }
}