Ask Frogans

“Ask ALICE” is a new site-let on frogans*lab (you know, the celebrated companion Frogans site for this illustrious blog). “ALICE” is in reference to the Artificial Linguistic Internet Computer Entity which was created by Richard Wallace in the 90’s.

And why “Ask,” you ask? It’s because on this site-let you can ask ALICE questions (which ALICE will try to answer, sometimes successfully). And there is, of course, that famous line, “Go ask Alice,” in Jefferson Airplane’s 1967 chart-topper “White Rabbit,” a song that makes psychedelia-flavored references to Alice in Wonderland.

I wanted to make a Frogans site that was a front end for a chatbot, i.e., a software that simulates human conversation. This would be possible provided I could find a chatbot platform with an API that would work well with Frogans. I went to RapidAPI.com, which provides code for accessing a vast array of APIs, and found a number chatbot APIs to choose from.

I found that most of these APIs would either require client-side JavaScript, have a prohibitively steep learning curve and/or work through monthly subscriptions. “The BOTlibre” API stood out from the crowd as it is relatively easy to use, it can work using only PHP (making it Frogans-friendly) and it’s completely free to use.

That’s where I hooked up with ALICE.

The BOTlibre site provides innumerable chatbots that you can chat with, either directly on the site or via their API. You can also create your own chatbot on the site, either from scratch (meaning that you would have to teach it how to respond to all question it might be asked) or by creating a clone from a preexisting model, such as ALICE. For this site-let, I took a basic ALICE clone and made it truly useful by teaching it about Frogans.

A Frogans-based chatbot

To create a Frogans-based chatbot through BOTlibre, you must first go to BOTlibre.com, sign up with a password and create an application. You will be given an application ID which, with your user name and password, all of which you will need for connecting to the API at RapidAPI.com.

RapidAPI provides you with numerous means for connecting with the API.

I chose PHP -> Unirest/Request. This method does require a unirest.php library, which you can download here, but other than that, it’s out-of-the-box PHP:

 require_once '../../unirest-php/src/Unirest.php';
    $response = Unirest\Request::get("https://paphus-botlibre.p.rapidapi.com/form-chat?application=[YOUR BOTLIBLRE APPLICATION NUMBER]&password=[YOUR BOTLIBRE PASSWORD]&user=[YOUR BOTLIBRE USER NAME]&message=".$question."[<- THIS IS THE QUESTION YOU ASK TO THE CHATBOT]&instance=31533212[<- THIS IS THE INSTANCE NUMBER FOR THE ALICE FROGANS CHATBOT]",
      array(
        "X-RapidAPI-Host" => "paphus-botlibre.p.rapidapi.com",
        "X-RapidAPI-Key" => "[YOUR RAPIDAPI KEY]"
      )
    );
    $response = json_decode(json_encode($response),true);  //this is a trick for converting a StdClass object to an array.
    $answer_xml=$response['body'];
    $answer_array = new SimpleXMLElement($answer_xml);
    $answer=$answer_array->message;

Essentially, when the PHP code for the slide is processed on the server, a $question is sent to the chatbot via the API. The API returns a $response from which is derived an $answer. The $question and the $answer are displayed on the slide.

For Ask Alice I made it so that the first time you open the slide, the $question is always “What does ALICE stand for?” The response depends on ALICE. Sometimes the answer is “ALICE = Artificial Linguistic Internet Computer Entity,” but often it is “Are you asking about my politics or religion?”

To ask a question of your own, you click on the button “Ask a question” which opens up a text input field where you can type and send your question. Now the same PHP code is processed on the server for a new slide, only this time, it is your question that is asked to ALICE.

All you need to is to install Frogans Player for Developers alpha from get.frogans. Then open up the frogans*lab Frogans site, go to “Gallery” and click on “Ask ALICZ.” Enjoy!

Be the first to comment

Leave a Reply

Your email address will not be published.


*