Pandora Bot Problem
Well I saw an article that says you can make a bot using this site and PHP and had some example code that parses XML, so I changed it a bit so that it could work with Pandora Bots and it works, but when a user uses an illegal character such as "?" or types in certain phrases I get a "Bot connection failed" error. I tried using the "str_replace" function but that caused an error every time even though the code was valid.
Also is there a way to save the CustID in a variable over PHP? So far I'm just using a CustID it gave to me in the code.
<?php
$u = "http://www.pandorabots.com/pandora/talk-xml?botid=c32ff0376e3459c2";
$u = $u . "&input=" . $_REQUEST['msg'];
$u = $u . "&custid=b6bcd069ae74b98c";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $u);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = simplexml_load_string(curl_exec($ch));
curl_close($ch);
$result = $xml->xpath('//that');
while (list($key, $value) = each($result)) {
echo $value ."<br>";
}
?>
Comments are currently closed for this discussion. You can start a new one.
Support Staff 2 Posted by Adam Kalsey on 23 Jan, 2010 04:10 AM
Try URL encoding your msg before you pass it to Pandora.
<?php
$u = "http://www.pandorabots.com/pandora/talk-xml?botid=c32ff0376e3459c2";
$u = $u . "&input=" . urlencode($_REQUEST['msg']);
$u = $u . "&custid=b6bcd069ae74b98c";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $u);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$xml = simplexml_load_string(curl_exec($ch));
curl_close($ch);
$result = $xml->xpath('//that');
while (list($key, $value) = each($result)) {
echo $value ."<br>";
}
?>
3 Posted by Terry Swanson on 23 Jan, 2010 04:24 AM
Thanks for the help! It seems to have worked.
Now I was wondering if there was a way to change the message "Bot connection failed" to something else when it fails to load (since the Pandora Bots servers sometimes stop working).
Also is there anyway I can store a CustID for a specific user in a variable or is there no way of doing that?
Support Staff 4 Posted by Adam Kalsey on 23 Jan, 2010 04:49 AM
You can't store anything on our side. But you could run a database
server on your side, or perhaps even just store it in a text file.
The error message cannot be changed at this time. However, to solve
the problem with Pandora not working, you can check the return status
of the curl call and if it is an error, print your own error message.
Our API sample code has an example of checking an error message from
curl.
--
Adam Kalsey
This mobile device has tiny keys. Please excuse any typos.
5 Posted by Terry Swanson on 23 Jan, 2010 05:06 AM
I'll have to try that out sometime. Thanks for your help.
Support Staff 6 Posted by Adam Kalsey on 23 Jan, 2010 05:30 AM
Glad I could help. Let us know if we can do anything else.
--
Adam Kalsey
This mobile device has tiny keys. Please excuse any typos.