PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label twilio. Show all posts
Showing posts with label twilio. Show all posts

Saturday, November 19, 2022

[FIXED] How to find relation between send and received message in twillio

 November 19, 2022     twilio, twilio-php     No comments   

Issue

I am using Copilot API of twillio to send sms. so i am able to send sms to end user. Now if user reply to that sms, i am receiving the callback (PHP Script). Using that callback URL, i am able to get the reply message.

Now i want to do is, i am trying to find a relation between sent and received(which end user reply) message. so i can then forward the reply message to their sender.

I will have UI like below, where user enter the message and number where he wants to receive reply.

But the problem is i am not able to find relation between send/receive message.

Any advice will be helpful.

enter image description here


Solution

Twilio developer evangelist here.

Other than storing the information on your server upon sending/receiving a message, you could make use of the cookies stored at Twilio.

When Twilio makes a request to your server and it returns a cookie (a Set-Cookie HTTP response header), Twilio stores this cookie and associates it with the From and To numbers for the incoming call or SMS message.

A little caveat to this is the fact that this cookie is only stored for four hours, so unless that works for you, I'd suggest using the from & the to as composite keys to find a relation.

Hope this helps you



Answered By - Marcos Placona
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I handle reaching voicemail using Twilio's <dial> verb

 November 19, 2022     twilio, twilio-php, twilio-twiml     No comments   

Issue

I know that on making a call Twilio can detect an answering machine, and react differently.

However if I use the <dial> verb, there's no obvious place to add this feature, even though it's essentially the same thing.

My intended flow is:

  • Customer enters their phone number
  • Twilio calls Customer and plays a voice message
  • Twilio dials an agent number, likely a mobile
  • If the Agent picks up, connect the customer to the agent
  • If the Agent busies the call or does not answer, call will likely go to Agent's voicemail.
    • Terminate call to Agent
    • Record voicemail from Customer
    • Email voicemail to Agent

Solution

From the official docs on the <Dial> verb (emphasis mine):

This is the simplest case for Dial. Twilio will dial 415-123-4567. If someone answers, Twilio will connect the caller to the called party. If the caller hangs up, the Twilio session ends. If the line is busy, if there is no answer, or if the called party hangs up, <Dial> exits and the <Say> verb is executed for the caller before the call flow ends.

<?xml version="1.0" encoding="UTF-8"?>
<!-- page located at http://example.com/simple_dial.xml -->
<Response>
    <Dial>415-123-4567</Dial>
    <Say>Goodbye</Say>
</Response>

Placing a <Record> verb after the <Say> verb sounds like what you are looking for. You can change the timeout from the default value of 30s like this:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Dial timeout="9001">415-123-4567</Dial>
    <Say>Please leave a message</Say>
    <Record action="/process_new_voicemail" />
</Response>


Answered By - Colin Scott-Fleming
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I pass parameters to a Twilio number voice URL with PHP?

 November 19, 2022     php, twilio, twilio-php     No comments   

Issue

Currently, I making a call using Twilio with their REST API using the Twilio php helper library, I'm dialing the a Twilio number which have a Voice URL setup, in this case, I need to send some parameters to that URL from the REST API call which I can't for the moment, because the URL is set on the Twilio console and I need to sent some user data based on the call, but I haven't seen anything that allows me to do that, in the documentation it's not saying anything about that, it's possible to achieve that?

Thank you beforehand


Solution

Twilio developer evangelist here.

You can set parameters in the Voice URL in the Twilio dashboard using URL parameters. For example, if you set the URL to be http://example.com/voice?foo=bar then you should be able to extract bar with $_REQUEST['foo'].

Twilio also sends a number of parameters to your URL with an incoming call, including the number that was dialled (useful if you have multiple incoming numbers), the number dialled from and many more. You should be able to use the information in the request from Twilio to choose where to dial your call onto. For example, if you are expecting a call from a particular number and you know you want to forward that call onto a different number, you can setup a conditional based on the From parameter.

Let me know if that helps at all.



Answered By - philnash
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I send a user token via SMS with Authy and PHP?

 November 19, 2022     authy, php, twilio, twilio-php, two-factor-authentication     No comments   

Issue

I am trying to run a demo for Authy in PHP. I have installed the Authy library with Composer, so now I can register a user using hardcoded values like this:

$authy_api = new Authy\AuthyApi('<TESTING API KEY>', 'http://sandbox-api.authy.com'); // actual key omitted -- using the key generated for testing, not the one for production

$user = $authy_api->registerUser('something@something.com', '999-999-9999', 30); // actual credentials omitted

if($user->ok()){
    echo "Success!";
    $id = $user->id();
    echo($id);  
}

When the above script runs, a 5-digit user id is indeed generated, so all seems to be going well, yet the SMS is never delivered to my phone.

One possible problem could be that my number is already registered as the app phone (associated with the admin account), so since (per the docs) each phone number has to uniquely identify a user, maybe mine was already registered for this app and therefore no need arose to send a new token. Should that be the case, the id of the user object may be the previously registered one.

The problem remains with other phone numbers however. So now I'm lost.


Solution

Turns out, there was nothing wrong with the code per se.

It's just the Sandbox API does not actually go through with sending the SMS. It only simulates the process for testing purposes, so that the authentication flow is the same as with the production API.

When I switched to production API URL and key, I was able to receive the SMS on my phone.



Answered By - Guybrush Threepwood
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to transfer Twilio lookup cURL code to PHP cURL

 November 19, 2022     curl, php, twilio, twilio-php     No comments   

Issue

I have this curl code:

curl -X GET https://lookups.twilio.com/v1/PhoneNumbers/(919) 410-7522\
-d "Type=carrier"
-u "{AccountSid}:{AuthToken}"

I try to convert in PHP cURL but I stack on how to send AccountSid and AuthToken.

I need this code only to check if number is valid and mobile or landline.

How to do that? Thanks!


Solution

Just use CURLOPT_USERPWD option

$ch = curl_init("https://lookups.twilio.com/v1/PhoneNumbers/(919)%20410-7522");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_POSTFIELDS, "Type=carrier");
curl_setopt($ch, CURLOPT_USERPWD, "{AccountSid}:{AuthToken}");
$response = curl_exec($ch);


Answered By - hlscalon
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to get countries where twilio numbers are available to buy using PHP library

 November 19, 2022     twilio, twilio-php     No comments   

Issue

Twilio documentation provides one example of searching numbers where they search for local numbers in US.

$client = new Services_Twilio($sid, $token);
$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
    "InRegion" => "AR"
));
foreach($numbers->available_phone_numbers as $number) {
    echo $number->phone_number;
}

Is there a way I can get all the countries where twilio numbers are available ? So I can search a number in one of those countries. Thanks


Solution

I managed to get the list of countries where twilio numbers are available

public function getAvailableCountries(){

    $client = new \Services_Twilio($this->sid, $this->token);

    $uri = '/'. $client->getVersion() . '/Accounts/' . $this->sid . '/AvailablePhoneNumbers.json';

    try{
        $numbers = $client->retrieveData($uri);

        //returns an array of countries where twilio numbers are supported
        return $numbers->countries;

    }catch(Exception $e){
        return $e->getMessage();
    }
}


Answered By - Ashfaq Ahmed
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to get countries where twilio numbers are available to buy using PHP library

 November 19, 2022     twilio, twilio-php     No comments   

Issue

Twilio documentation provides one example of searching numbers where they search for local numbers in US.

$client = new Services_Twilio($sid, $token);
$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
    "InRegion" => "AR"
));
foreach($numbers->available_phone_numbers as $number) {
    echo $number->phone_number;
}

Is there a way I can get all the countries where twilio numbers are available ? So I can search a number in one of those countries. Thanks


Solution

I managed to get the list of countries where twilio numbers are available

public function getAvailableCountries(){

    $client = new \Services_Twilio($this->sid, $this->token);

    $uri = '/'. $client->getVersion() . '/Accounts/' . $this->sid . '/AvailablePhoneNumbers.json';

    try{
        $numbers = $client->retrieveData($uri);

        //returns an array of countries where twilio numbers are supported
        return $numbers->countries;

    }catch(Exception $e){
        return $e->getMessage();
    }
}


Answered By - Ashfaq Ahmed
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to delete a phone number with Twilio PHP SDK?

 November 19, 2022     php, twilio, twilio-api, twilio-php     No comments   

Issue

I am using Twilio PHP SDK. I have the sid of a phone number. How do I delete it?

The rest API docs shows a delete method but does not have the code for it.

https://www.twilio.com/docs/api/rest/incoming-phone-numbers#list

I've seen some examples on Stack Overflow, but they all seem to be using an older version of the SDK.


Solution

Inspired from here: https://www.twilio.com/docs/api/rest/incoming-phone-numbers?code-sample=code-get-an-incomingphonenumber&code-language=php&code-sdk-version=5.x

Example code to delete() a Twilio phone number:

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

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

// Delete a Twilio number based on its sid. If you do not have a sid,
// check out the list resource examples on this page
$number = $client
    ->incomingPhoneNumbers("PN2a0747eba6abf96b7e3c3ff0b4530f6e")
    ->delete();

Warning: Once the number is deleted, any code using it, won't work. Be sure you really want to run the code above.



Answered By - Alex Baban
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to check "to number" is valid for Twillio SMS API?

 November 19, 2022     php, twilio, twilio-php     No comments   

Issue

I am using Twillio API to send SMS to my website users. But there's one issue, I want to check first, if that number is valid or not? Is there any API in Twillio which is used to check validity of 'to' numbers?


Solution

Twilio developer evangelist here.

We actually do have an API that you can use to check the validity of a phone number. Check out the Lookup API and its documentation. At the basic level it checks to see if a number looks like a valid phone number and gives you the correct national formatting for it. You can also make a request to find out carrier details about the number to see if it is likely to receive SMS messages.

The link that @dhi_m provided is a good resource to find out what Twilio does with a number when sending it a message. Ultimately, the best way to see if you can send a message to a number is to try to send a message. Then you should build in ways to respond if the message is unsuccessful.



Answered By - philnash
Answer Checked By - Mildred Charles (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I make this code say "Please hold" and play a custom mp3?

 November 19, 2022     php, twilio, twilio-php     No comments   

Issue

This is a conference line that begins when the moderator joins.

It works perfectly except I can't figure out how to make it say "Please hold, you'll be connected shortly." to all callers.

I also want to play a custom mp3 file for the hold music.

<?php
// Get the PHP helper library from twilio.com/docs/php/install

// this line loads the library
require_once '/var/www/one/conference/twilio/Twilio/autoload.php';
use Twilio\Twiml;

// Update with your own phone number in E.164 format
$MODERATOR = '+1347999999';

$response = new Twiml;

// Start with a <Dial> verb

$dial = $response->dial();

// If the caller is our MODERATOR, then start the conference when they
// join and end the conference when they leave
if ($_REQUEST['From'] == $MODERATOR) {
$dial->conference('My conference', array(
            'startConferenceOnEnter' => True,
            'endConferenceOnExit' => True,
            'beep' => True,
            'record' => True

            ));

} else {
// Otherwise have the caller join as a regular participant
$dial->conference('My conference', array(
            'startConferenceOnEnter' => False
            ));
}

print $response;

?>

Solution

Twilio developer evangelist here.

In order to get a message at the start of the call, you need to use the TwiML <Say> verb before you use the <Dial>.

To play custom music before the conference starts, you'll want to use the waitUrl attribute on the <Conference> tag. The waitUrl is a URL that points at either an MP3 or Wav file or something that returns TwiML which could include multiple <Say> or <Play> verbs.

Here's an update of your code that includes a message at the start and a waitUrl for music (notably, the moderator doesn't need a waitUrl as they start the conference):

// Get the PHP helper library from twilio.com/docs/php/install

// this line loads the library
require_once '/var/www/one/conference/twilio/Twilio/autoload.php';
use Twilio\Twiml;

// Update with your own phone number in E.164 format
$MODERATOR = '+1347999999';

$response = new Twiml;

// Start with a welcome message
$response->say("Please hold, you'll be connected shortly.");

// Then add the <Dial> verb
$dial = $response->dial();

// If the caller is our MODERATOR, then start the conference when they
// join and end the conference when they leave
if ($_REQUEST['From'] == $MODERATOR) {
$dial->conference('My conference', array(
            'startConferenceOnEnter' => True,
            'endConferenceOnExit' => True,
            'beep' => True,
            'record' => True
            ));

} else {
// Otherwise have the caller join as a regular participant
$dial->conference('My conference', array(
            'startConferenceOnEnter' => False,
            'waitUrl' => 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.classical'
            ));
}

print $response;

Let me know if this helps at all.



Answered By - philnash
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] when we make call using rest api then what twiml we use on that url parameter

 November 19, 2022     twilio, twilio-api, twilio-click-to-call, twilio-php     No comments   

Issue

I am Creating the call using the rest api-

try{
        // Initiate a new outbound call
        $call = $this->client->calls->create(

            // to call.
            "num2",

            // Step 5: Change the 'From' number below to be a valid Twilio number 
            // that you've purchased or verified with Twilio.
            "num1",


            array("url" => "url-tw",
            'IfMachine'=>'Continue')

        );
        echo "Started call: " . $call->sid;
    } catch(Exception $e){
        echo "Error: " . $e->getMessage();
    }

and on the url-tw what twiml should I use which can't disconnect the call.

Before I was handling the call using the TwiML but now I have to detect the AnsweredBy option which is only available if I make the call using the REST API so.

for now I m using the same twiml I have used before when I was making calls using the twiML like use the <Dial> which let to dial again but if I dont use any twiml it disconnect the call.So any advice where I m going wrong.


Solution

Twilio evangelist here.

The value of the url parameter should be a publicly accessible URL that returns TwiML containing the instructions that you want Twilio to execute to the caller.

Your PHP to start the call would look like:

// Initiate a new outbound call
$call = $this->client->calls->create(
    "num2",
    "num1",
    array("url" => "http://example.com/answer.php", 'IfMachine'=>'Continue')
);

Then in answer.php, you can do two things:

  1. Check the AnsweredBy parameter to see if Twilio detected a machine or a human.
  2. Generate the Twiml you want to return based on that value

For example to say something different to a machine v a human, you could do something like this in your PHP:

<?php
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<?php if ($_REQUEST['AnsweredBy']=='machine'): ?>
    <Response>
        <Say>Hello machine</Say>
    </Response>
<?php else: ?>
    <Response>
        <Dial>+15555555555</Dial>
    </Response>
<?php endif ?>

Hope that helps.



Answered By - Devin Rader
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to add dynamic number in Twilio SMS API PHP

 November 19, 2022     twilio, twilio-php     No comments   

Issue

How can I add and Send SMS to number dynamically by PHP code.

I have add number from admin panel and send SMS to this static number. It works, but if I want to add number from HTML form. So how can I register number dynamically by PHP code.

$message = $client->messages->create(
   '+919711969920', // Text this number
   array(
     'from' => '(205) 358-4782', // From a valid Twilio number
     'body' => "Hello Sudhir"
   )
);

Solution

Twilio developer evangelist here.

You can absolutely take input from an HTML form. Rather than hard coding the number into your PHP you would need to retrieve the number you want to send the message to from the incoming request parameters.

You could do this with:

$message = $client->messages->create(
   $_REQUEST["to"],
   array(
     'from' => '(205) 358-4782', // From a valid Twilio number
     'body' => "Hello Sudhir"
   )
);

Make sure your form then has an input field with the name "to" and when you submit the form you will be able to get the parameter from the request with the code above.

<input type="tel" name="to" id="to" />

Let me know if that helps at all.



Answered By - philnash
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How does one nest Twilio Twiml <Play> inside <Gather> using Twilio\Twiml php

 November 19, 2022     twilio, twilio-php     No comments   

Issue

How would I nest Play inside Gather ? I have the following Twiml xml:

 $twiml = new Twiml();
    $twiml->gather('gather',array());
    $twiml->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5));
    $response = Response::make($twiml, 200);
    $response->header('Content-Type', 'text/xml');
    return $response;

required result:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather input="speech" action="/completed">
  <Play loop="5">https://api.twilio.com/cowbell.mp3</Play>
</Gather>


Solution

Use this:

$twiml = new Twilio\Twiml();
$gather = $twiml->gather(array('input' => 'speech', 'action' => '/completed'));
$gather->play('https://api.twilio.com/cowbell.mp3', array("loop" => 5));

$response = Response::make($twiml, 200);
$response->header('Content-Type', 'text/xml');
return $response;


Answered By - Andy
Answer Checked By - Clifford M. (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] What is Twilio's SMS verification gradle dependency?

 November 19, 2022     android, twilio, twilio-php     No comments   

Issue

I am using Twilio for SMS verification to my android app using Android Studio, and I found this Dependency from Twilio official documentation(compile 'com.twilio: verification:+'), here is the link: https://www.twilio.com/docs/guides/twilio-verification-sdk-integration-guide/integrating-twilio-verification-sdk-using-sample-backend#step-3-add-twilio-verification-sdk-for-android

but as add this dependency, the Gradle shows error and can not be built, here I have already asked my answer: Error:Failed to resolve: com.google.android.gms:play-services-auth-api-phone:10.2.5

Is there anyone who knows what is the exact dependency of Twilio Verification to add in my Android Studio to use Twilio SMS verification.


Solution

another Twilio developer evangelist here.

The issue with that document is that it fails to mention that you will need to use a local Google Play services SDK for the time being until Google releases it out in the wild.

To get that, all you need to do is fill up the form in this page to get the SDK, and the in your code you will do the following:

  1. Open ~/.gradle/gradle.properties
  2. add PARTNER_SDK_DIR=/Users/{USER_NAME}/workspace/partner-sdk
  3. Import the SDK

So you should end up with somthing that looks like this:

allprojects {
    repositories {
        maven {
            url PARTNER_SDK_DIR
        }
        jcenter()
    }
}

We have a sample application on our github repository which you can download and test. You will find it here

Hope this helps you!



Answered By - Marcos Placona
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to bypass audio playing before recording in twilio php api?

 November 19, 2022     twilio, twilio-api, twilio-php     No comments   

Issue

I am working in twilio api recording process. I need to play a custom audio before recording . User can listen fully(after they listen fully recording start with beep) or bypass that audio by pressing '#' , then recording start with beep sound. Is it possible to acheive ?

Thanks


Solution

Yeah that's pretty easy.

Nest your <play> verb within a <gather>verb, add an action url to the gather verb which points to your TwiML that initiates the call recording, also add a <redirect> verb at the end of your TwiML which also points to the TwiML which initiates your call recording.

The default finish on key for a gather is #, so if your caller presses that then Twilio will redirect to the record TwiML url straight away.

If the caller presses nothing then Twilio will continue to process the current TwiML, which is why you need a <redirect> verb at the end. As this also points to the TwiML that initiates recording then users who press nothing will still be redirected to the recording TwiML once your <play> audio has finished.



Answered By - miknik
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do I configure skip_if on Twilio Taskrouter Workflow

 November 19, 2022     twilio, twilio-api, twilio-php     No comments   

Issue

I'm developing Twilio Taskrouter.

I cannot configure skip_if on console and also Update API. https://www.twilio.com/docs/api/taskrouter/worker-presence

I tried Update API, response JSON has skip_if.

But, console JSON has no skip_if.

How do I configure skip_if?

Thank you @philnash. My codes are below.

   public function test_retrieveWorkflow()
    {
        $account_sid = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        $auth_token = "xxxxxxxxxxxxxxx";
        $client = new Client($account_sid, $auth_token);

        $workspace_sid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        $workflow_sid = 'WWxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        $workflow = $client->taskrouter
            ->workspaces($workspace_sid)
            ->workflows($workflow_sid)
            ->fetch();

        $configurations = json_decode($workflow->configuration, true);
        $filters = $configurations['task_routing']['filters'];
        foreach ($filters as &$filter) {
            foreach ($filter['targets'] as &$target) {
                $target['skip_if'] = 'workers.available == 0';
            }
        }

        $configurations['task_routing']['filters'] = $filters;
        $configurations = json_encode($configurations);
        $workflow = $workflow->update(['configuration' => $configurations]);
        var_dump($workflow);
    }

Sorry,I forgot to write expect result. Before, execute above code.

{
"task_routing": {
    "filters": [
        {
            "targets": [
                {
                    "queue": "WQyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
                    "expression": "task.email==worker.email",
                    "timeout": "10"
                },
                {
                ...
                }
            ],
            "filter_friendly_name": "filter by email",
            "expression": "1==1"
        }
    ],
    "default_filter": {
        "queue": "WQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }
}

After, execute above code, result is expected JSON.

{
    "task_routing": {
        "filters": [
            {
                "targets": [
                    {
                        "queue": "WQyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
                        "expression": "task.email==worker.email",
                        "timeout": "10",
                        "skip_if": "workers.available == 0"
                    },
                    {
                    ...
                    }
                ],
                "filter_friendly_name": "filter by email",
                "expression": "1==1"
            }
        ],
        "default_filter": {
            "queue": "WQxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        }
    }
}

But, my twilio console shows before execute JSON.


Solution

TaskRouter PM here. I've updated the docs for this feature, which should answer all your questions:

https://www.twilio.com/docs/api/taskrouter/worker-presence

(it won't currently show in the console in either view - see note in docs)



Answered By - Al Cook
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to interrupt an audio recording with the twilio php api

 November 19, 2022     twilio, twilio-api, twilio-php     No comments   

Issue

I'm using the twilio php api and I can't seem to find any way to interrupt the audio files from playing immediately a gather key is pressed.

This is what I have currently

$voiceResponse->gather(['method' => 'POST', 'action' => $storeResponseURL, 'finishOnKey' => '#']);
$voiceResponse->redirect($noResponseURL, ['method' => 'POST']);

Please, I need help on this.


Solution

Twilio developer evangelist here.

In your <Gather> from your example you have the finishOnKey attribute set to "#". So the <Gather> will only finish when your caller presses "#" not any other key.

Your <Gather> doesn't appear to contain any other TwiML either. If you want to be able to interrupt audio then you need to nest a <Say> or <Play> element inside the <Gather>.

If you want to complete the input after just one character, then your best bet is to actually use the numDigits attribute and set it to 1.

Putting that all together, your TwiML generation should look like this:

$voiceResponse = new Twiml();
$gather = $voiceResponse->gather(['method' => 'POST', 'action' => $storeResponseURL, 'numDigits' => '1']);
$gather->play('/gather_audio.mp3');
$voiceResponse->redirect($noResponseURL, ['method' => 'POST']);

Let me know if that helps!



Answered By - philnash
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How I can get info countries with allowed sms-sending from twilio.com in PHP?

 November 19, 2022     twilio, twilio-php     No comments   

Issue

How I can get countries via API with allowed sms-sending from twilio.com in PHP?

On image below highlighted what I need. Is this possible via API? enter image description here


Solution

Twilio developer evangelist here.

I'm afraid we don't have an API for that information. You can find out which countries' numbers support features like SMS from this page though: https://support.twilio.com/hc/en-us/articles/223183068-Twilio-international-phone-number-availability-and-their-capabilities



Answered By - philnash
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, November 18, 2022

[FIXED] How to record-from-answer-dual with Twilio's object oriented interface?

 November 18, 2022     twilio, twilio-api, twilio-php     No comments   

Issue

I understand how to enable the 'record-from-answer-dual' with the XML style command set, but I'm not finding any way to accomplish the same thing with the more object-oriented style code, such as:

<?php
require_once 'twilio-php-master/Twilio/autoload.php';
$response = new Twilio\Twiml();

$sayMsg = 'Attention!  Attention!  The network operations 
center has opened a ticket concerning an ATMS failure in the Eastern 
region. The ticket number is ECHO,1,5,7,4.  I repeat, the ticket number is 
ECHO,1,5,7,4. Thank you.';

$response->record();
$response->say($sayMsg, array('voice' => 'alice'));
$response->hangup();
echo $response;

I've tried adding it to the new line, and the record line as an array-style entry, similar to enabling the Alice voice. No dice.

I want to record the entire call, from answer, including the message spoken by Twilio.

Thanks for any information anyone can provide!


Solution

Twilio developer evangelist here.

<Record> is used to record messages from a call, not to record the TwiML that follows. It's more useful if you are building a messaging or voicemail system for voice.

Given that your message sounds like some kind of announcement, I am guessing that you are generating this call from the REST API. In that case, you can use the Record parameter when you place the call and the entire call will be recorded. In PHP, that would be something like this:

require_once '/path/to/vendor/autoload.php';
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/console
$sid = "your_account_sid";
$token = "your_auth_token";
$client = new Client($sid, $token);

$call = $client->calls->create(
    $to, $from,
    array(
        "url" => $url,
        "record" => true
    )
);

Check out the documentation on the parameters you can use when making a call, including Record here.

Let me know if that helps at all.

Update from Jeffrey's comment

This is the Perl version, using the unofficial Twilio Perl module:

use WWW::Twilio::API;
my ($twilaccountsid, $twilauthtoken, $fromnum, $tonum, $twiml_uri) = @_;
my $twilio = WWW::Twilio::API->new(AccountSid => $twilaccountsid, AuthToken => $twilauthtoken);
my $response = $twilio->POST( 'Calls', From => $fromnum, To => $tonum, Record => 'true', Url => $twiml_uri);
return $response->{content}; 


Answered By - philnash
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How long would a message take to say

 November 18, 2022     twilio, twilio-api, twilio-php, twilio-twiml     No comments   

Issue

In the twilio API is it possible to figure out how long a message is going to take?

My Requst come from that I need to figure out if a verbal message has been said.

a API endpoint to get the time of a special Twiml or asking on a call if it did all the say would be the best option.

We are logging length of call etc but we still need to see if they have heard all of message or hang up before it is all done.


Solution

Twilio developer evangelist here.

There's no way to know how long a message will take, but I have another idea.

If you set up your <Say> message with a <Redirect> after it, then the user will have heard all the message if the <Redirect> url receives a request.

<Response>
  <Say>This is an important message.</Say>
  <Redirect method="POST">https://example.com/results/success</Redirect>
</Response>

Let me know if that helps at all.

Update

So, the above didn't exactly work as Twilio seems to read ahead and load the <Redirect> URL before the <Say> has completed. However, we can still use this to help.

In the response to the <Redirect> URL, we can make Twilio call to another URL somehow. For example, the following TwiML will call out to a URL to fetch a file to <Play> to the user. Rather than call directly to an mp3 file you can make this call to a server that notes the call got this far and then returns a short, maybe silent, mp3 file. Then we can hangup because we've done what we needed to do.

<Response>
  <Play>https://example.com/record_call_complete_and_return_mp3</Play>
  <Hangup/>
</Response>

This is a bit of a hack, but it seems to work as the <Play> URL is only requested when Twilio starts the response to the <Redirect>.



Answered By - philnash
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing