Program E的Flash前端
Program E的Flash前端
Program E是一个php的aiml解析器. (http://sourceforge.net/projects/programe/)
如果你对机器人聊天很感兴趣, 你肯定知道aiml, alicebox. 反正我是在03年就把这个东西用在了msn上(貌似是第一个).
无废话, 上代码:
php:
- /**
- * Include the guts of the program.
- */
- include "respond.php";
- $numselects=0;
- // Start the session or get the existing session.
- session_start();
- $myuniqueid=session_id();
- //echo 'botresponse='. $_POST['input'];
- //exit;
- // Here is where we get the reply. Make sure you fill in testbot with your bot's name
- if(isset($_POST['input'])){
- //echo 'botresponse='. $_POST['input'];
- $uid = isset($_POST['uid']) ? $_POST['uid'] : $myuniqueid;
- $botresponse=replybotname($_POST['input'], $uid, "ChinaBabel Bot No. 1");
- echo 'botresponse=' . $botresponse->response;
- echo '&myuniqueid=' . $uid;
- }
- // Print the results.
- //print "&bot_name=Test Agent/n";
- //print $botresponse->response;
- //print "&textLoaded=1";
Flash as2:
- var username;
- var keyListener:Object = new Object();
- keyListener.onKeyDown = function() {
- // compare return value of getCode() to constant
- if (Key.getCode() == Key.ENTER) {
- _root.askBot(_root.ask.text);
- _root.ask.text = "";
- }
- else if(Key.getCode()==Key.ESCAPE){
- //clear
- _root.ask.text = "";
- }
- };
- Key.addListener(keyListener);
- var myuniqueid:String = "";
- function askBot(ques:String):Void{
- if(ques == ''){
- return;
- }
- _root.answer.htmlText = "......";
- var botResponse:LoadVars = new LoadVars();
- var result_lv:LoadVars = new LoadVars();
- result_lv.onLoad = function(success:Boolean) {
- if (success) {
- _root.append("机器人", result_lv.botresponse);
- //_root.answer.text = result_lv.botresponse;
- _root.myuniqueid = result_lv.myuniqueid;
- } else {
- _root.answer.text = "Error connecting to server.";
- }
- };
- if(_root.myuniqueid != ""){
- botResponse.uid = _root.myuniqueid;
- }
- botResponse.input = ques;
- botResponse.sendAndLoad("http://www.xxx.com/bot/src/flash.php", result_lv, "POST");
- }
- function append(user, txt){
- var tt = user + ' says: <span>' + txt + "</span>";
- _root.answer.htmlText = tt;
- }
- askBot("I am "+username);