Twilio TwiML to make phone to phone call.

How to write TwiML to call phone number from twilio number

by cybersal

Today we are going to show, how to write TwiML code to dial a phone number from browse via Twilio.

<Response>
<Dial callerId="+193********" >   /*this is the caller id which we get from Twilio>*/
<Number>+1963********</Number>   /*Number on which you want to dial*/
</Dial>
</Response>

You can also get status call back by adding statusCallback URL in the above code.

<Response>
<Dial callerId="+193********" >   
<Number statusCallbackEvent="initiated ringing answered completed"
statusCallback="<YOURDOMAIN>/events.php"
statusCallbackMethod="POST">+1963********</Number>  
</Dial>
</Response>

Here, statusCallbackEvent specifies which events you want to log at our end, statusCallback is the path of the file on your domain.

Here is a sample of what your events.php code looks like

$status = implode(',',$_REQUEST) ;

$handle = fopen('log.txt','a');  /* File in which logs are written*/

fwrite($handle, $status . "\n");

echo $status;

Log file will contain all the details about your call. Sample of the same:

+9196******,CAc2c7*******,Maharashtra / Goa,US,outbound-dial,Mon, 24 Jan 2022 09:45:11 +0000,call-progress-events,OH,,0,CA99c235*******,+9196******,43037,IN,,2010-04-01,,initiated,+1740******,ACbd5*******4,IN,UTICA,,US,+1740******,UTICA,Maharashtra / Goa,43037,OH
+9196******,CAc2c7*******,Maharashtra / Goa,US,outbound-dial,Mon, 24 Jan 2022 09:45:11 +0000,call-progress-events,OH,,1,CA99c235*******,+9196******,43037,IN,,2010-04-01,,ringing,+1740******,ACbd5*******4,IN,UTICA,,US,+1740******,UTICA,Maharashtra / Goa,43037,OH
+9196******,CAc2c7*******,Maharashtra / Goa,US,outbound-dial,Mon, 24 Jan 2022 09:45:31 +0000,call-progress-events,487,OH,,2,CA99c23525a0***,+9196******,43037,IN,,2010-04-01,,no-answer,0,+174******,0,ACbd5*******4,IN,UTICA,,US,+17407*****,UTICA,Maharashtra / Goa,43037,OH
+9196******,CAc2c7*******,Maharashtra / Goa,US,outbound-dial,Mon, 24 Jan 2022 09:51:34 +0000,call-progress-events,OH,,0,CA99c235*******,+9196******,43037,IN,,2010-04-01,,initiated,+1740******,ACbd5*******4,IN,UTICA,,US,+1740******,UTICA,Maharashtra / Goa,43037,OH
+9196******,CAc2c7*******,Maharashtra / Goa,US,outbound-dial,Mon, 24 Jan 2022 09:51:34 +0000,call-progress-events,OH,,1,CA99c235*******,+9196******,43037,IN,,2010-04-01,,ringing,+1740******,ACbd5*******4,IN,UTICA,,US,+1740******,UTICA,Maharashtra / Goa,43037,OH

Related Articles

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy