EzDevInfo.com

twilio-php

A PHP library for communicating with the Twilio REST API and generating TwiML. Need help? Post your questions to <a href="http://getsatisfaction.com/twilio">http://getsatisfaction.com/twilio</a> or email us at help@twilio.com twilio-php &mdash; Services_Twilio 4.2.1 documentation

Re-send a Twilio SMS Message

I store sent messages in a log table with their unique SIDs. With a periodic console task I iterate over the records having status = undelivered and request the status of it and if it's still undelivered, I'd like to re-send that very message. I don't want a new one as the message contains a verification code and we store only hash of it. Is it possible to re-send the old message having its SID?


Source: (StackOverflow)

Setting a time limit to a twilio call

I am using the twiml below to create and send a call to my users. However I want to set a time limit to this call. I know it is possible when you use the verb, as shown here. But I don' know how to do it in my situation

try {
    $to = '+' . $phone;         
    $client->account->calls->create(
        "+17********", 
        $to, 
        $url,
        array( 
            'Method' => "GET", 
            'FallbackMethod' => "GET", 
            'StatusCallbackMethod' => "GET", 
            'Record' => "false", 
        )
    );
} catch (Exception $e) {
    // log error
}

Source: (StackOverflow)

Advertisements

Twilio SMS Using PHP (Not Sending or Loading PHP page)

So this is what's on the top of the PHP file:

<?php
    // Start the session
    session_start();
?>

<?php
    // Get the PHP helper library from twilio.com/docs/php/install
    require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

    // Your Account Sid and Auth Token from twilio.com/user/account
    $sid = "ACXXXXXXXXXXXXXX"; 
    $token = "XXXXXXXXXXXXXXXXXX"; 
    $client = new Services_Twilio($sid, $token);

    $client->account->messages->sendMessage("+1234567890", "+0987654321", "Please?! I love you <3, Twilio Test");
?>

<?php
    // Start the session
    session_destroy();
?>

Then I have the <html> beneath.

The Issue I'm having is that the page just loads a white blank page and when I check the Twilio Log to see if any SMS are logged.

But the page loads just fine without the middle PHP (the part that's supposed to send the SMS through Twilio)

The Log is completely empty and shows no record of any outgoing SMS.

Any help would be appreciated!


Source: (StackOverflow)

Display Single Result from Returned List

I'm trying to work out how I can display the first returned value (phone number) only. At the moment this code returns ALL available numbers but I only want to display one to the customer.

Here's the code. I hope someone can help. I'm pretty new to this you see, I've tried a few bits but they haven't worked.

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC1f3ccf29618exxxxx"; 
$token = "{{Auth_Token}}"; 
$client = new Services_Twilio($sid, $token);

$numbers = $client->account->available_phone_numbers->getList('GB', 'Local', array(
        "Contains" => "44161"
    ));

foreach($numbers->available_phone_numbers as $number) { 
echo $number->phone_number;
}

?>

Currently I get a list as follows:

+441618503707+441618503748+441618502214+441618502601+441618502327+441618503631+441618503785+441618503437+441618503432+441618503758+441618503593+441618503404+441618503794+441618502289+441618503684+441618503519+441618503629+441618503810+441618503704+441618503742+441618503557+441618503302+441618503604+441618503539+441618503044+441618503298+441618503799+441618503753+441618503447+441618503801

I would just like to display the first value IE +441618503707

Help appreciated, I may not respond right away as this is one of many projects on at the moment. Rest assured though my other projects are on Infusionsoft, I don't dabble in API/PHP too often!


Source: (StackOverflow)

Using twilio api for making phone to phone calls?

Can I make Phone to Phone call using Twilio api? I don't want to use internet connection for making this call but I want to use Twilio api as well.. Is there a way for doing so?


Source: (StackOverflow)

Remove Twilio recording Beep

Is there anyway I could turn off default twilio beep sound for start recording. I want to use our own customer beep.

Basically we want a single beep when a MP3 completes playing. After that we want 20 seconds blank and once 20 seconds completes, we play three beeps so he can start recording his answer.


Source: (StackOverflow)

What is wrong with my jQuery and twilio Code?

I went to these two ( 1 , 2 ) site for one of my projects.
I'm a noob at PHP. So I'm not really sure how to make this work.
I once got a SSL certificate error while trying to test it. My SMS are not getting sent.
I don't get any kind of reply or alert or something when I'm testing it with my HTML.
Please help me if there's any twilio and PHP expert are out there. this the form I'm using in HTML

<form id="frm" name="frm">
   <div class="form-group">
      <label for="tel">Phone:</label>
      <input type="tel" class="form-control" id="phoneNumber" name="phoneNumber" required>
   </div>
   <button class="btn" type="submit" id="submit">Submit</button>
</form>

My script

$("#frm").submit(function(e){
   e.preventDefault();
   $.post("sendnotifications.php", $("#frm").serialize(),
   function(data){
   if(data.sms_sent == 'OK'){
   alert("Message Sent");
   } else {
   alert("Message Not Sent");
   }
   }, "json");
});

and here is my sendnotifications.php file

<?php/* Send an SMS using Twilio. You can run this file 3 different ways:


*
 * - Save it as sendnotifications.php and at the command line, run
 * php sendnotifications.php
 *
 * - Upload it to a web host and load mywebhost.com/sendnotifications.php
 * in a web browser.
 * - Download a local server like WAMP, MAMP or XAMPP. Point the web root
 * directory to the folder containing this file, and load
 * localhost:8888/sendnotifications.php in a web browser.
 */

// Step 1: Download the Twilio-PHP library from twilio.com/docs/libraries,
 // and move it into the folder containing this file.
 require "Services/Twilio.php";

// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
 $AccountSid = "ACexxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 $AuthToken =  "fafyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";

// Step 3: instantiate a new Twilio Rest Client
 $http = new Services_Twilio_TinyHttp(
    'https://api.twilio.com',
    array('curlopts' => array(
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_SSL_VERIFYHOST => 2,
    ))
);

 $client = new Services_Twilio($sid, $token, "2010-04-01", $http);

// Step 4: Get phone number from the test-sms form
 $phone=$_POST["phoneNumber"];

// Step 5: Create SMS
 $sms = $client->account->sms_messages->create(

// Change the 'From' number below to be a valid Twilio number
 // that you've purchased, or the (deprecated) Sandbox number
 "717-xxx-xxxx",

// the number we are sending to - Any phone number
 $phone,

// the sms body
 "Get our app now: http://bit.ly/ourapp"
 );

// Display a confirmation message on the screen
 $sms_check='OK'; //Use Twilio's callback here
 $return_json = '{"sms_sent":"' . $email_check . '"}';

echo $return_json;
?>  

Please someone tell me what do I need to change to get my site working.
I have changed the $http in sendnotifications.php after going to the github faq of twilio to prevent the ssl certificate error. What else do I need to do??

Edit: I have solved the problem using the below code.

    <?php 
// Step 1: Download the Twilio-PHP library from twilio.com/docs/libraries,
// and move it into the folder containing this file.
 require_once "Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
 $AccountSid = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 $AuthToken = "04dxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 // Twilio REST API version
 $version = "2010-04-01";
// Step 3: instantiate a new Twilio Rest Client
 $client = new Services_Twilio($AccountSid, $AuthToken, $version);
// Step 4: Get phone number from the test-sms form
 $phone=$_POST["phoneNumber"];

try{
$message = $client->account->messages->create(array(
    "From" => "+1xxxxxxxxxx",
    "To" => $phone,
    "Body" => "This code is for testing!",
));
$sms_check='OK';
}
catch (Exception $e) {
    $sms_check = 'Error';
}
$return_json = '{"sms_sent":"' . $sms_check . '"}';
echo $return_json;
?>

But I'm now getting an error in my server..
The SMS is getting sent but this error shows up..

Error: Could not decode response body as JSON. This likely indicates a 500 server error

Does anyone know any way of solving this problem.. My website is hosted on altervista.

Edit I have solved the 500 error

By replacing the tinyHttp.php file inside "Services/Twilio"with a edited tinyhttp.php file from github.. The link of the edited github file is in the comment section..


Source: (StackOverflow)

Replying to certain message in Twilio

I am making an event organisation platform. Whenever user creates an event, the candidate gets an email notification as well as sms notification asking whether the suggested time fits or not. The problem is that since it is event organisation, there may be more than one occurance of candidate's mobile phone. So I need to have some unique information to identify to which event candidate is responding to.

I have tried identify using Message SID, but then I realised that Message SID is different on reply message.

So my question would be: is there any way to authenticate to which message candidate is replying to?


Source: (StackOverflow)

Twilio : Dial with two Audio, each for From and To numbers : PHP

I have to use twilio to use two audio file, one for the person who is calling, and second audio is for the person who is being called.

Its like terms and condition,

terms_conditions_v1.mp3 for person1

terms_conditions_v2.mp3 for person2

person1 will call on twilio number which will be forwarded to person2.

both audio files should end in same time, say 20 seconds.


Source: (StackOverflow)

Twilio redirect a call from sub -account to master account

I have a master account and a sub account. Let's say a caller calls a number in the sub account. The sub account will process this call by outputting some TwiMl and based on some business rules it might need to redirect the flow of this call to the master account (for accounting purposes).

An easy way to do this is simply to dial a number belonging to the master account. This will transfer the call flow from the sub account to the master account. No complications there...

However, in order for me to identify what client this call belongs to on the master account I need to have some unique identifier. When I receive this call on the master account I have to way to match it to a client. Ideally I would like to get the initial CallSid the one originated on the sub account but it seems like that is not possible. So I was looking into passing custom parameters but no luck there either.

It only makes sense that you should be able to somehow link data from sub account to master account. Any ideas on how to accomplish this?


Source: (StackOverflow)

Twilio REST API How to get Sid

I am still new to Twilio. I am writing a PHP script which will connect to Twilio and parse some information about calls. I am using the code from this page:

https://www.twilio.com/docs/api/rest/call

Here is my code:

require_once '../twilio-library/Services/Twilio.php';

// Twilio REST API version
$version = '2010-04-01';

// Set our AccountSid and AuthToken
$sid = 'abc132xxxxx';
$token = 'xxxxeeffv';

// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($sid, $token, $version);

// Loop over the list of calls and echo a property for each one
foreach ($client->account->calls as $call) {
    echo "->".$call->Sid."<- <br/>";


}

The browser just outputs many blanks. No Sid values. What am I doing wrong?


Source: (StackOverflow)

Does the Twilio PHP helper library use the deprecated SMS/Messages resource? How to update?

Twilio recommends that developers switch from using the old SMS/Messages API resource to the new /Messages one (see the API documentation, as well as problems with SMS status when using the old version).

I'm using the twilio-php helper library, which is Twilio's official recommendation for PHP development. It appears that this library is sending requests to /2010-04-01/Accounts/{sid}/SMS/Messages/ (e.g, here and here).

Questions:

  1. Am I correct in thinking that the library is using the old API resource?
  2. Is there an expedient way to update it, or anyplace I can find an updated version?
  3. Is there a guide to any changes that might be necessary when switching to the new resource?

Source: (StackOverflow)

How to send One Time Password using Twilio in JavaScript?

I need your help to create One Time Password (OTP) using Twilio in JavaScript to generate OTP and verify it using JavaScript.

I have surfed about this in Twilio. They have given Two Factor Authentication to send OTP in PHP, Ruby, C#, Python and Java, but not for JavaScript.

Any one please help me to achieve this Two Factor Authentication using JavaScript.


Source: (StackOverflow)

Trying to figure out a how call works in twilio

As subject says I am reading api docs for twilio but even after brainstorming for 2 hours I am still unable to figure out exactly how can I receive a call from twilio on my web application and answer the call with my own voice like we do in a real phone.

I know how to respond a call when someone call your twilio number but that's only text to speech conversion like their "Hello Monkey" example application but nothing so far about answering a call using their API.

Can anyone please explain how can we do that? Not everything, just main concept and few references if possible

I am using Laravel so would be good if it's in php


Source: (StackOverflow)

SSL error in twilio php codeignitor

class send_sms {
public function send() {
    require('twilio-php/Services/Twilio.php');
    $account_sid = 'xxx'; 
$auth_token = 'xxx'; 
$http = new Services_Twilio_TinyHttp(
    'https://api.twilio.com',
    array('curlopts' => array(
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_SSL_VERIFYHOST => 2,
    )));

$client = new Services_Twilio($account_sid, $auth_token, "2010-04-01", $http); 
try {
    $message = $client->account->messages->create(array(
        "From" => "xxx",
        "To" => "xxx",
        "Body" =>"Test message",
    ));
} catch (Services_Twilio_RestException $e) {
    echo $e->getMessage();
}
}
}

It still gives error

Fatal error: Uncaught exception 'Services_Twilio_TinyHttpException'
with message 'SSL certificate problem: self signed certificate in
certificate chain' in
C:\xampp\htdocs\lab_reporting_system\application\libraries\twilio-php\Services\Twilio\TinyHttp.php:119
Stack trace: #0
C:\xampp\htdocs\lab_reporting_system\application\libraries\twilio-php\Services\Twilio.php(181):
Services_Twilio_TinyHttp->__call('post', Array) #1
C:\xampp\htdocs\lab_reporting_system\application\libraries\twilio-php\Services\Twilio.php(181):
Services_Twilio_TinyHttp->post('/2010-04-01/Acc...', Array,
'From=%2B1501475...') #2
C:\xampp\htdocs\lab_reporting_system\application\libraries\twilio-php\Services\Twilio\ListResource.php(92):
Base_Services_Twilio->createData('/2010-04-01/Acc...', Array) #3
C:\xampp\htdocs\lab_reporting_system\application\libraries\twilio-php\Services\Twilio\Rest\Messages.php(24):
Services_Twilio_ListResource->_create(Array) #4
C:\xampp\htdocs\lab_reporting_system\application\libraries\send_sms.php(20):
Services_Twilio_Rest_Messag in
C:\xampp\htdocs\lab_reporting_system\application\libraries\twilio-php\Services\Twilio\TinyHttp.php
on line 119

Source: (StackOverflow)