I am currently using version 4 of the Twilio PHP Helper Library and list messages using the following call:
$twilio = new Twilio();
$twilio->account->messages->getPage(0, 300, array(
'From' => $myPhoneNumber
));
I am able to get all incoming messages from a specific phone number with the above.
Is there anyway to search for all incoming messages from multiple phone numbers? Something like:
$twilio->account->messages->getPage(0, 300, array(
'From' => array($myPhoneNumberOne, $myMyPhoneNumberTwo, $myPhoneNumberThree)
));
If this isn't possible with the V4 version of the library, I am open to using version 5.
Twilio evangelist here.
Unfortunately today the underlying REST API does not support this type of searching but it's certainly an interesting idea.
Hope that helps.
Related
I have a Twilio phone number configured to direct inbound calls to a PHP webhook. The webhook uses some of the addon information to try and find a useful caller name. I'm also using Twilio's built-in CNAM lookups, but they don't work right in Canada (I always get the caller's number as their name).
The webhook is designed to forward calls to a Twilio SIP Domain first, where I expect I'll be answering most of the calls. Other calls, if deemed urgent, will be forwarded via PSTN.
I've reached the point where I can pull out a relevant name, but I'm having difficulty trying to forward that information to my FXS (HT802). As per the device's documentation:
http://www.grandstream.com/sites/default/files/Resources/ht80x_administration_guide.pdf
Auto: When set to “Auto”, the HT801/HT802 will look for the caller ID in the order of P-Asserted Identity Header, Remote-Party-ID Header and From Header in the incoming SIP INVITE
I'm not able to find a means to pass these headers via a SIP noun in TwiML. Based on Twilio's documentation:
https://www.twilio.com/docs/voice/twiml/sip#custom-headers
UUI (User-to-User Information) header can be sent without prepending x-
https://www.twilio.com/docs/voice/api/sending-sip#sip-x-headers
If you send headers without X- prefix, Twilio will not read the header. As a result, the header will not be passed in the output.
For context, here's a reduced snippet of the PHP code I'm using so far. Note: I'm not actually doing anything with the $callerName value yet.
<?php
// Simple "starting value", in case we can't resolve the name.
// (will also resolve the numbers used for unknown/blocked IDs)
$callerName = FriendlyFormatPhoneNumber($_POST['From']);
use Twilio\Twiml;
$addOns = null;
if (array_key_exists('CallerName', $_POST)) {
$callerName = $_POST['CallerName'];
} elseif (array_key_exists('AddOns', $_POST)) {
$addOns = json_decode($_POST['AddOns']);
$teloName = $addOns->results->telo_opencnam->result->name;
// If we pulled a telo name, and it doesn't seem to be a phone number
// (in case that could happen), use the telo name.
if (isset($teloName) && preg_match('/.*[0-9]{4,}, $teloName') == 0) {
$callerName = $teloName;
}
}
$response = new TwiML;
$dialParams = array(,
'timeout' => 20,
'hangupOnStar' => false,
'answerOnBridge' => true,
'action' => API_BASE_URL . '/dial-callback.php'
);
$dialer = $response->dial($dialParams);
$dialer->sip('sip:101#mytwiliodomain.sip.us1.twilio.com;transport=tls');
echo $response;
Long story short: How do I pass a custom caller name to my SIP devices using TwiML and the Twilio SIP Domains? I don't want to overwrite the number, just the name. And only on the inbound calls to the devices registered to my Twilio SIP domain.
In case it helps: Don't worry about translating to PHP if that's not your field; I can translate from TwiML :)
Unfortunately, this is not possible with Twilio SIP Domains. Currently, there is no way to set the Caller Name via TwiML.
i've successfully make a voice call with twilio like this:
$call = $client->calls->create(
$toNumber, $fromNumber,
array("url" => "http://demo.twilio.com/docs/voice.xml")
);
the above code will call to the $toNumber with twilio demo message, when i try to use TwiML to create the dynamic message like this:
$response = new TwiML();
$response->say('Votre otp est 2234', ['voice' => 'woman', 'language' => 'fr']);
$call = $client->calls->create(
$toNumber, $fromNumber,
$response
);
i got an error like this:
[HTTP 400] Unable to create record: Url parameter is required. For
more information, see http://www.twilio.com/docs/api/twiml
Twilio developer evangelist here.
You can't send the TwiML to Twilio when you make a call like that. You need to send a URL that Twilio will send an HTTP request to when the call connects (like in the original example). So, to fix your code you should replace the demo URL with your own URL.
$call = $client->calls->create(
$toNumber, $fromNumber,
array("url" => $YOUR_URL_HERE)
);
That URL can be your own application, or something like a TwiML Bin or Twilio Function. Check out this article to see how to respond with TwiML to a request from Twilio.
I notice that you are building something for one time passwords too. You might be interested in checking out the Authy API that can implement and deliver OTP codes via calls, SMS and app.
I have this code in laravel
$client->calls->create(
array(
'from'=> '+6326263667',
'to'=> ???,
'url'=> 'twilio bin url'
)
);
I don't know what to put in the "to" array. I'm copying the node version of this like:
client.calls.create({
from: from,
to: process.argv[2],
url: url
})`
it there any other way if not like this?
Twilio Developer Evangelist here.
The to field is expecting the telephone number (in E.164 format) you wish to call.
In your Node example there, process.argv[2] is referring to the first argument passed to a command line operation.
If you want to learn more, I recommend you check out the Programmable Voice Quickstart for PHP.
I am working on a program where I will text a message to my Twilio number and have it send the message out to a group of people. I want the numbers to read from either a SQL database (so that people can sign up on a website via PHP) or through a Google Sheets spreadsheet. I really don't know where to start and was wondering if I could get some input from the pros.
Thank you!
Anthony
Twilio developer evangelist here.
If what you're looking for is using Google Spreadsheets, we actually have a pretty comprehensive tutorial on how to use Google Spreadsheets with PHP here.
But the gist is the following:
Enable your spreadsheet for programmatic access
Start reading the data from it and loop through your records.
Looping through your records can be as easy as this:
// Get our spreadsheet
$spreadsheet = (new Google\Spreadsheet\SpreadsheetService)
->getSpreadsheetFeed()
->getByTitle('Phone Numbers');
// Get the first worksheet (tab)
$worksheets = $spreadsheet->getWorksheetFeed()->getEntries();
$worksheet = $worksheets[0];
$listFeed = $worksheet->getListFeed();
/** #var ListEntry */
foreach ($listFeed->getEntries() as $entry) {
$phone = $entry->getValues();
}
On the loop above, you could also use the Twilio REST api to start sending SMS messages with Twilio as follows:
$sms = $client->account->messages->create(
// the number we are sending to - Any phone number
$phone,
array(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased
'from' => "YOUR_NUMBER",
// the sms body
'body' => "Hey $name, Monkey Party at 6PM. Bring Bananas!"
)
);
So it's just a matter of using the two together. you can read more about sending messages with PHP here.
Hope this helps you out
I am new to Twilio. To learn the basics, I followed the instructions here:
https://www.twilio.com/docs/howto/walkthrough/click-to-call/php/laravel#12
At first, my phone would ring, and I would receive a generic message. Impressed, I upgraded my account. Now I receive a call where a voice says "We're sorry an application error has occurred."
I checked my Alerts in Twilio, and found Error: 12100 - Document parse failure
So I checked the url of my outbound.php and realized that there is a PHP error here. The error is
Fatal error: Class 'Response' not found in
/home/......./outbound.php on line 16
After some searching, I can't find anyone else discussing this same problem. Finally, the worst part, I can't even find any reference to a Response class in the Twilio Helper Library.
Here is my entire code block for the page in question.
<?php
error_reporting(E_ALL);
require_once 'twilio-library/Services/Twilio.php';
// A message for Twilio's TTS engine to repeat
$sayMessage = 'Thanks for contacting our sales department. If this were a
real click to call application, we would redirect your call to our
sales team right now using the Dial tag.';
$twiml = new Services_Twilio_Twiml();
$twiml->say($sayMessage, array('voice' => 'alice'));
// $response->dial('+12345675309');
$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;
?>
If I change this file to static, well formatted XML then the error stops.
Twilio developer evangelist here.
The tutorial you were following was based within the Laravel framework, which is where the Response class was expecting to come from.
If you are using the PHP TwiML builder in just a plain PHP file, you should be able to just print the $twiml. I'd probably add a Content-Type of text/xml as well, just to be safe. Like this:
<?php
error_reporting(E_ALL);
require_once 'twilio-library/Services/Twilio.php';
// A message for Twilio's TTS engine to repeat
$sayMessage = 'Thanks for contacting our sales department. If this were a
real click to call application, we would redirect your call to our
sales team right now using the Dial tag.';
$twiml = new Services_Twilio_Twiml();
$twiml->say($sayMessage, array('voice' => 'alice'));
// $twiml->dial('+12345675309');
header('Content-type: application/xml');
print $twiml;
?>
Let me know if this helps at all!