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

Saturday, November 19, 2022

[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

Friday, November 18, 2022

[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

[FIXED] How to leave a mp3 voicemail after dial session receive busy signal asynchronously with Twilio?

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

Issue

I want to create a loop of dial sessions (after one dial session end, another one is created) in order to call multiple clients at a time.

I have this method in action of my dial verb :

public function afterCall(Call $call, DialSession $ds, TwilioClient $client): VoiceResponse
{

        $voiceResponse = new VoiceResponse();
        $voiceResponse->pause(['length' => 1]);

        if ($_REQUEST['DialCallStatus'] === 'completed') {
            $call->status = Call::COMPLETED;
            $call->connected = true;
            $call->recording_link =  $_REQUEST['RecordingUrl'];
        }

        if ($_REQUEST['DialCallStatus'] === 'busy' || $_REQUEST['DialCallStatus'] === 'no-answer') {
            $call->status = Call::BUSY;
            $client->leaveVoiceMail($_REQUEST['DialCallSid']);
        }

        if ($_REQUEST['DialCallStatus'] !== 'completed' &&
            $_REQUEST['DialCallStatus'] !== 'busy' &&
            $_REQUEST['DialCallStatus'] !== 'no-answer'
        ) {
            $call->status = Call::ERROR;
        }

        return $voiceResponse;
}

When my DialCallStatus is busy or no-answer I would like to leave a saved mp3 message (voicemail)

But when I update call /w dialCallSid (in $client->leaveVoiceMail($_REQUEST['DialCallSid']);) I got this error :

Twilio\Exceptions\RestException: [HTTP 400] Unable to update record: Call is not in-progress. Cannot redirect.

Is there a way to leave a message on Dial end asynchronously from the current call ?

Thank you !


Solution

If DialCallStatus returns busy or no-answer, it means the dialed party is not answering the call. You can only leave a voice mail or play an automated announcement if the dialed parties voicemail or human actually answered the call.

https://www.twilio.com/docs/voice/twiml/dial#dialcallstatus

Maybe you would be better served using the Calls REST API resource to imitate an outbound call and use Answering Machine Detection (AMD) to facilitate the process.



Answered By - Alan
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Where is the Twiml xml for my application stored?

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

Issue

I have inherited a call center php application using twillio webrtc, and the twilio api.The trouble I'm having is the application, only makes a call to one number. I've looked through the controller using Twiml and Voice Response, and as far as I can tell a phone number gets passed from the front-end and $to_number is assigned that value.I've changed this value a million times , and it still dials the same number. It's because of this that I think that in my actual Twiml, is where it may be reset. The trouble is I can't find any Twiml in the entire application. I've also checked on twilio for any Twiml in my apps, and this is all I found. Twiml app When I try making a call using the call button, and an error is thrown.

I've been succesful in making calls to different numbers using the following request post request

In short, where is my Twiml (in xml) stored? Any ideas what may be causing this issue?


Solution

The TwiML Application SID is passed in the Access Token to the client. The TwiML Application has set of URL's, one being the Voice URL, that points to TwiML which tells Twilio what to do.

If the Access Token is being sent to the console log, you can decode it to find the Application SID (to lookup in Twilio Console) here. You can enable client side debug here.



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

[FIXED] How to Receive and Send voicemail from/on Twilio number?

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

Issue

I am creating a Twilio based application that will receive the Voicemail if the call is not picked up.

For now, I had set up the incoming call URL in the console against the phone number.

<?php
    header('content-type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";        
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    file_put_contents('incoming_call.log', "\n" .json_encode($_REQUEST) . "\n", FILE_APPEND);
?>

<Response>
    <Dial timeout="15" action="/voicemail.php">          
    </Dial>
</Response>

Whereas my voicemail.php file will has to code

<?php
// echo "hello ";exit;
    header('content-type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

    file_put_contents('incoming_voicemail.log', "\n" .json_encode($_REQUEST) . "\n", FILE_APPEND);
?>
<Response>
  <Say voice="alice">Your call could not be answered at the moment. Please leave a voice message. 
  </Say>
  <Record></Record>
</Response>

I am not receiving the voicemail. Where can I setup the recordingStatusCallback attribute in twiml?

Secondly, I am trying to send voicemail from Twilio number to phone number by dialing One calling and again dial a Second call as the second call will receive a busy status and we are able to send a voicemail, but it's not working. My code is

$call = $twilio->account->calls->create(                
    $phone_no, // To
    $from_no, // From
    array(
        "method" => "GET",
         "statusCallback" => SURL . "voicemail?to_phone_no=" . $phone_no,
          "statusCallbackEvent" => ["initiated","ringing"],
          "statusCallbackMethod" => "POST",
          "twiml" => '<Response><Say>Testing voicemail</Say></Response>'
      )
    );
    sleep(3);
    $call2 = $twilio->account->calls->create(
        $phone_no, // To
        $from_no, // From
        array(
            "url" => AURL.'Vm/audio_file'
        )
    );

Please guide me what I am doing wrong. For help thanks in advance.


Solution

Twilio developer evangelist here.

For your first question, if you don't include a number (or a SIP address, or a Client identity) to try to connect to, then the <Dial> will move straight on to the action URL, without bothering with the timeout.

If you want the <Dial> to try to connect to a phone, then you should add a phone number.

Second, if you want to receive a webhook when the recording is complete, then you need to add the recordingStatusCallback attribute, with a URL to send the webhook to, to your <Record>, e.g.:

<Response>
  <Say voice="alice">Your call could not be answered at the moment. Please leave a voice message. 
  </Say>
  <Record recordingStatusCallback="/recording-complete.php"></Record>
</Response>

Finally, we do not support the final use case of trying to dial a number twice in order to block it up and then leave a voicemail. Making calls and then dropping them is against the terms of service (see point 19 under "prohibited services". So I encourage you to consider a different way to reach out to your customers or contacts that engages with them in a legitimate way.



Answered By - philnash
Answer Checked By - Mary Flores (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