Pandora Bot Problem

Terry Swanson's Avatar

Terry Swanson

23 Jan, 2010 03:17 AM via web

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>";
  }
?>
  1. Support Staff 2 Posted by Adam Kalsey on 23 Jan, 2010 04:10 AM

    Adam Kalsey's Avatar

    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>";
         }
        ?>

  2. 3 Posted by Terry Swanson on 23 Jan, 2010 04:24 AM

    Terry Swanson's Avatar

    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?

  3. Support Staff 4 Posted by Adam Kalsey on 23 Jan, 2010 04:49 AM

    Adam Kalsey's Avatar

    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.

  4. 5 Posted by Terry Swanson on 23 Jan, 2010 05:06 AM

    Terry Swanson's Avatar

    I'll have to try that out sometime. Thanks for your help.

  5. Support Staff 6 Posted by Adam Kalsey on 23 Jan, 2010 05:30 AM

    Adam Kalsey's Avatar

    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.

Comments are currently closed for this discussion. You can start a new one.