How do you place a phone call using tropo by sending xml to a tropo hosted script? This php script is supposed to use curl to post xml to another php script (hosted @ tropo). The tropo-hosted script is then supposed to use the xml to place a phone call. In the below example, the tropo debugger is receiving the correct information, since messages like this show up in the debugger:
customerName:Kent is added into the context of app instance : ApplicationInstance[http://hosting.tropo.com/107029/www/ExternalPhoneHelper.php , sas_2-14-sm25ogjh4vlab5tropo]
Here's the curl php script that sends the xml data to tropo:
$token = "mytoken";//removed actual token
$url = PhoneHelper::$TROPO_URL;
$xml = "
<session>
<token>" . $token . "</token>
<var name=\"action\" value=\"create\"/>
<var name=\"customerName\" value=\"Kent\" />
<var name=\"numberToDial\" value=\"##########\" />
<var name=\"msg\" value=\"XML Test\" />
</session>";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo curl_error($ch);
echo $output;
curl_close($ch);
The receiving script is empty:
<?php
?>
If the call() and say() methods should be used, how would I reference the posted xml to get numberToDial and msg?
Here is the debugger log:
|-----------------------------------------------------------------------|
|00000|00-1|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=-1 sessionNumber=-1 callID=-1 |
|-----------------------------------------------------------------------|
|00001|00-1|02:18:47 AM|Attempting to determine application type via |
| | | |tropo-engine URL parameter in myURL |
|-----------------------------------------------------------------------|
|00002|00-1|02:18:47 AM|Attempting to determine application type by |
| | | |requesting HEAD from |
| | | |myURL to get Content-Type header |
|-----------------------------------------------------------------------|
|00003|00-1|02:18:47 AM|Opened URLConnection |
|-----------------------------------------------------------------------|
|00004|00-1|02:18:47 AM|Connecting for HEAD |
|-----------------------------------------------------------------------|
|00005|00-1|02:18:47 AM|Got HEAD response |
|-----------------------------------------------------------------------|
|00006|00-1|02:18:47 AM|No Content-Type header provided by HEAD. |
|-----------------------------------------------------------------------|
|00007|00-1|02:18:47 AM|Attempting to determine application type based |
| | | |on file extension for myURL |
|-----------------------------------------------------------------------|
|00008|00-1|02:18:47 AM|Determined type=php from filename suffix |
|-----------------------------------------------------------------------|
|00009|00-1|02:18:47 AM|Trying to create application for URL=myURL |
|-----------------------------------------------------------------------|
|00010|00-1|02:18:47 AM|Tropo app dir is /tropo_app_home |
|-----------------------------------------------------------------------|
|00011|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=0 sessionNumber=0 callID=0 |
|-----------------------------------------------------------------------|
|00012|0000|02:18:47 AM|Application[myURL ver(1.0.56092) has been |
| | | |created. |
|-----------------------------------------------------------------------|
|00013|0000|02:18:47 AM|Found hosted Application[myURL ver(1.0.56092) |
| | | |[token=myToken] |
|-----------------------------------------------------------------------|
|00014|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=0 sessionNumber=0 callID=0 |
|-----------------------------------------------------------------------|
|00015|0000|02:18:47 AM|Application[myURL ver(1.0.56092) has been found.|
|-----------------------------------------------------------------------|
|00016|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=0 |
| | | |sessionNumber=a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |callID=0 |
|-----------------------------------------------------------------------|
|00017|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 acquired engine |
| | | |QuercusScriptEngine[] of type php, |
| | | |activeEngines = 5 |
|-----------------------------------------------------------------------|
|00018|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 got engine to |
| | | |compile script |
|-----------------------------------------------------------------------|
|00019|0000|02:18:47 AM|?><?php // line 1121 |
|-----------------------------------------------------------------------|
|00020|0000|02:18:47 AM|if ($currentCall != null) // line 1122 |
|-----------------------------------------------------------------------|
|00021|0000|02:18:47 AM|{ // line 1123 |
|-----------------------------------------------------------------------|
|00022|0000|02:18:47 AM| say("I'm sorry, but I can not find or |
| | | |compile the Tropo script for this phone number."|
| | | |); // line 1124 |
|-----------------------------------------------------------------------|
|00023|0000|02:18:47 AM| hangup(); // line 1125 |
|-----------------------------------------------------------------------|
|00024|0000|02:18:47 AM|} // line 1126 |
|-----------------------------------------------------------------------|
|00025|0000|02:18:47 AM|?> // line 1127 |
|-----------------------------------------------------------------------|
|00026|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 returning engine |
| | | |after compiling script |
|-----------------------------------------------------------------------|
|00027|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 returned engine |
| | | |QuercusScriptEngine[] of type php, |
| | | |activeEngines = 4 |
|-----------------------------------------------------------------------|
|00028|0000|02:18:47 AM|In SimpleApplication.execute() for token launch,|
| | | |HttpSession |
| | | |hssn-9541A863A42B7294412DF27003FE67BF associated|
| | | |with SipApplicationSession |
| | | |sas_2-14-sm86gosslpnlz6tropo |
|-----------------------------------------------------------------------|
|00029|0000|02:18:47 AM|SipApplicationSession |
| | | |sas_2-14-sm86gosslpnlz6tropo associated with |
| | | |Tropo session a8f0ba032d2a377e8fdcc8b68d82c766 |
|-----------------------------------------------------------------------|
|00030|0000|02:18:47 AM|customerName:Kent is added into the context of |
| | | |app instance : ApplicationInstance[myURL, |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00031|0000|02:18:47 AM|numberToDial:2087401235 is added into the |
| | | |context of app instance : ApplicationInstance[ |
| | | |myURL , sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00032|0000|02:18:47 AM|action:create is added into the context of app |
| | | |instance : ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00033|0000|02:18:47 AM|format:xml is added into the context of app |
| | | |instance : ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00034|0000|02:18:47 AM|msg:XML Test is added into the context of app |
| | | |instance : ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00035|0000|02:18:47 AM|ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] has been created. |
|-----------------------------------------------------------------------|
|00036|0000|02:18:47 AM|com.voxeo.tropo.core.SimpleCallFactory@44d6123f |
| | | |is added into the context of app instance : |
| | | |ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00037|0000|02:18:47 AM|Clearing logging context for |
| | | |http/0.0.0.0/8080-t-31 |
|-----------------------------------------------------------------------|
|00038|0000|02:18:47 AM|Set logging context for |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=0 |
| | | |sessionNumber=a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |callID=-1 |
|-----------------------------------------------------------------------|
|00039|0000|02:18:47 AM|ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] starts execution |
| | | |on Thread |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
|-----------------------------------------------------------------------|
|00040|0000|02:18:47 AM|Thread |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |acquired engine QuercusScriptEngine[] of type |
| | | |php, activeEngines = 5 |
|-----------------------------------------------------------------------|
|00041|0000|02:18:47 AM|ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] replaced script |
| | | |engine [QuercusScriptEngine[]] --> |
| | | |[QuercusScriptEngine[]] in field <_engine> |
|-----------------------------------------------------------------------|
|00042|0000|02:18:47 AM|ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] ends execution on |
| | | |Thread |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
|-----------------------------------------------------------------------|
|00043|0000|02:18:47 AM|Thread |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |returned engine QuercusScriptEngine[] of type |
| | | |php, activeEngines = 4 |
|-----------------------------------------------------------------------|
|00044|0000|02:18:47 AM|sas_2-14-sm86gosslpnlz6tropo invalidated |
|-----------------------------------------------------------------------|
|00045|0000|02:18:47 AM|Instance a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |removed |
|-----------------------------------------------------------------------|
|00046|0000|02:18:47 AM|Clearing logging context for |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
|-----------------------------------------------------------------------|
It looks like there are a few points of confusion/issues here, so I am going to try my best to tackle them all for you. The first thing I wanted to discuss is that the XML post to the session API is totally optional, it is just one way that you can submit your 'token request' to start an outbound call. If you are having issues getting this to work, let's just skip it and try a 'plane jane' HTTP GET straight from the browser until you are most comfortable:
api.tropo.com/1.0/sessions?action=create&token=123456&customerName=Kent&numberToDial=4075551212&msg=XML%20Test
Now on to the script itself, I found your accountID (yep, I work at Voxeo Labs / Tropo :P ), and I noticed a few things. First off you misspelled the application startURL, I am almost certain you meant ExternalPhoneHelper.php, but you typed ExterMalPhoneHelper.php, so you need to fix this first. Now the second thing, your file is actually blank, with the exception of the PHP tags.
So if you want to make a call and say something you can use call(); with a say(); or you can just use the combo/shortcut message(); method within your Tropo script:
<?php
message("Received office voice mail.", array("to" => "+14075550100"));
?>
Now on to the last question, How do you get your posted data in the Tropo application context? Well, the good news is that this is DEAD simple, we actually scope these as globals in your application, so the numberToDial query string parameter becomes $numberToDial, for example:
<?php
message($msg, array("to" => "+".$numberToDial));
?>
I really hope this helps, and if you still find yourself running into trouble hit up our support team, or find us in IRC on freenode (#tropo). My handle is dyer, and I am often in the channel lurking ;)
Take care!
-John