[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 ============= 2 Phone Calls 3 ============= 4 5 Making a Phone Call 6 =================== 7 8 The :class:`Calls` resource allows you to make outgoing calls: 9 10 .. code-block:: php 11 12 $client = new Services_Twilio('AC123', '123'); 13 $call = $client->account->calls->create( 14 '9991231234', // From this number 15 '8881231234', // Call this number 16 'http://foo.com/call.xml' 17 ); 18 print $call->length; 19 print $call->sid; 20 21 Adding Extra Call Parameters 22 ============================ 23 24 Add extra parameters, like a `StatusCallback` when the call ends, like this: 25 26 .. code-block:: php 27 28 $client = new Services_Twilio('AC123', '123'); 29 $call = $client->account->calls->create( 30 '9991231234', // From this number 31 '8881231234', // Call this number 32 'http://foo.com/call.xml', 33 array( 34 'StatusCallback' => 'http://foo.com/callback', 35 'StatusCallbackMethod' => 'GET' 36 ) 37 ); 38 39 A full list of extra parameters can be found `here 40 <http://www.twilio.com/docs/api/rest/making-calls#post-parameters-optional>`_. 41 42 Listing Calls 43 ============= 44 45 It's easy to iterate over your list of calls. 46 47 .. code-block:: php 48 49 $client = new Services_Twilio('AC123', '123'); 50 foreach ($client->account->calls as $call) { 51 echo "From: {$call->from}\nTo: {$call->to}\nSid: {$call->sid}\n\n"; 52 } 53 54 Filtering Calls 55 ====================== 56 57 Let's say you want to find all of the calls that have been sent from 58 a particular number. You can do so by constructing an iterator explicitly: 59 60 .. code-block:: php 61 62 $client = new Services_Twilio('AC123', '123'); 63 foreach ($client->account->calls->getIterator(0, 50, array( 64 'From' => '+14105551234' 65 )) as $call) { 66 echo "From: {$call->from}\nTo: {$call->to}\nSid: {$call->sid}\n\n"; 67 } 68 69 Accessing Resources from a Specific Call 70 ======================================== 71 72 The :class:`Call` resource has some subresources you can access, such as 73 notifications and recordings. If you have already have a :class:`Call` 74 resource, they are easy to get: 75 76 .. code-block:: php 77 78 $client = new Services_Twilio('AC123', '123'); 79 foreach ($client->account->calls as $call) { 80 $notifications = $call->notifications; 81 if (is_array($notifications)) { 82 foreach ($notifications as $notification) { 83 print $notification->sid; 84 } 85 } 86 87 $transcriptions = $call->transcriptions; 88 if (is_array($transcriptions)) { 89 foreach ($transcriptions as $transcription) { 90 print $transcription->sid; 91 } 92 } 93 94 $recordings = $call->recordings; 95 if (is_array($recordings)) { 96 foreach ($recordings as $recording) { 97 print $recording->sid; 98 } 99 } 100 } 101 102 Be careful, as the above code makes quite a few HTTP requests and may display 103 PHP warnings for unintialized variables. 104 105 Retrieve a Call Record 106 ====================== 107 108 If you already have a :class:`Call` sid, you can use the client to retrieve 109 that record.: 110 111 .. code-block:: php 112 113 $client = new Services_Twilio('AC123', '123'); 114 $sid = "CA12341234" 115 $call = $client->account->calls->get($sid) 116 117 Modifying live calls 118 ==================== 119 120 The :class:`Call` resource makes it easy to find current live calls and 121 redirect them as necessary: 122 123 .. code-block:: php 124 125 $client = new Services_Twilio('AC123', '123'); 126 $calls = $client->account->calls->getIterator(0, 50, array('Status' => 'in-progress')); 127 foreach ($calls as $call) { 128 $call->update(array('Url' => 'http://foo.com/new.xml', 'Method' => 'POST')); 129 } 130 131 Ending all live calls is also possible: 132 133 .. code-block:: php 134 135 $client = new Services_Twilio('AC123', '123'); 136 $calls = $client->account->calls->getIterator(0, 50, array('Status' => 'in-progress')); 137 foreach ($calls as $call) { 138 $call->hangup(); 139 } 140 141 Note that :meth:`hangup` will also cancel calls currently queued.
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |