jabber chatbot + ProgramE = Multiuser AI chat

Sean James
2005-07-05
2013-04-25
  • Sean James
    Sean James
    2005-07-05

    created a shell script that accesses ProgramE's functions and interfaces it neatly with chatbot for Jabber. The result is a AI chatbot that responds to it's name, and tries to reply intelligently to anyone in the room.  I will try to send the Shell script and chatbot plugin. I don't have a public live demo of this working yet, but I plan on implementing it on my chat servers soon.

     
    • Anne Kootstra
      Anne Kootstra
      2005-07-07

      Well, in any case I'd love to see how you were able to do it. One of the drawbacks of PHP is that it is hard to tie into messenger type of systems like MSN, Jabber, IRC etc. At least without the help of third party software that often require special priviledges to be able to run on a server. These rights are generally not available to a person on a regular hosting subscription.

      As soon as you have something you can contact me directly or provide a link here.

      As ever,

      Anne Kootstra
      Founding Member AIML.info, Main developer Program E
      http://www.aiml.info       http://sourceforge.net/projects/programe

      e-mail & msn messenger:
      anne@aiml.info

       
    • Sean James
      Sean James
      2005-07-20

      Here's the nitty gritty details.
      It does require special privledges, unfortuantely.

      I am runng Jive_Messenger, which is a great jabber server. But, any jabber server should do.

      I downloaded the perl based chatbot script originally for jabberd, but seems to work okay with other jabber servers as well.

      The eliza plugin for the chatbot script do all the hard work of connecting to the server and establishing a presense in a room for you.

      http://www.jabberstudio.org/cgi-bin/viewcvs.cgi/chatbot/ provides the sources for that. The changes I made to Eliza.pl are a bit lengthy to go into here. But, with some minor tweaking I changed the eliza.pl file to call CONV.PHP which is a PHP-CLI file that I created in my Program E root folder that looks like this:

      #!/usr/bin/php -q
      <?php
      include "respond.php";
      $numselects=0;
      $botresponse=replybotname(urldecode($_SERVER['argv'][3]),$_SERVER['argv'][2],$_SERVER['argv'][1]);
      echo urlencode(strip_tags(str_replace("\n"," ",$botresponse->response)));
      ?>

      I just made this executable, so when the eliza plugin calls conv.php <bot name> <userid> <usermessage>
      it writes to the stdout the Program E's response.

      The response is picked up by the eliza plugin, and broadcast to the room.

      This works great since, the bot can carry on several conversations at once. I set it up to respond whenever someone referenced it by name. For example: "Hi Sparky, how are you?" or when someone started the sentace with "Sparky:" as is customary is IRC.

      here is the source to Eliza.pl as well for reference:
      You will need to fix the path to your program E installation to suit your setup.
      ##############################################################################
      #
      #  This program is free software; you can redistribute it and/or modify
      #  it under the terms of the GNU General Public License as published by
      #  the Free Software Foundation; either version 2 of the License, or
      #  (at your option) any later version.
      #
      #  This program is distributed in the hope that it will be useful,
      #  but WITHOUT ANY WARRANTY; without even the implied warranty of
      #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      #  GNU General Public License for more details.
      #
      #  You should have received a copy of the GNU General Public License
      #  along with this program; if not, write to the Free Software
      #  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
      #
      #  Jabber
      #  Copyright (C) 1998-2002 The Jabber Team http://jabber.org/
      #
      ##############################################################################

      ##############################################################################
      #
      # ChatBot Eliza PlugIn - handles putting some spunk into ChatBot by wiring
      #                        the Eliza program into place when you address
      #                        ChatBot.
      #
      ##############################################################################

      use strict;
      use Chatbot::Eliza; 

      ##############################################################################
      #
      # Register Events
      #
      ##############################################################################
      &RegisterEvent("groupchat_message",\&amp;plugin_eliza_eliza);
      &RegisterEvent("chat_message",\&amp;plugin_eliza_eliza);

      ##############################################################################
      #
      # Register Flags
      #
      ##############################################################################
      &RegisterFlag("eliza");

      ##############################################################################
      #
      # Instantiate an Eliza
      #
      ##############################################################################
      $plugin_env{eliza}->{eliza} = new Chatbot::Eliza;

      ##############################################################################
      #
      # plugin_eliza_eliza - prints out the current eliza in UTC
      #
      ##############################################################################
      sub plugin_eliza_eliza
      {
          #require "syscall.ph";
          my $message = shift;

          my $fromJID = $message->GetFrom("jid");

          return unless &CheckFlag($fromJID->GetJID(),"eliza");
          my $nick = &ChatBotNick($fromJID->GetJID());
          my $body = $message->GetBody();
          my $fromNick = $fromJID->GetResource();

          return if ($fromNick eq "");
          return if ($fromNick =~ /$nick/);
          return unless ($body =~ /$nick/i);

          if ($body =~ /^\s*$nick\:(.*)$/) {
            $body =  substr($body,length($nick)+2);
          }
          my $input = $1;
          my $s = "/PATH TO YOUR PROGRAM E INSTALLATION/conv.sh ".$nick." ".$fromNick." \&quot;".urlencode($body)."\&quot;";   
              #print $s;
          my $reply = urldecode(readpipe($s));

          return ($message->GetType(),$fromJID->GetResource().": $reply");
      }
      sub urldecode {
          my($string) = $_[0];
          print $string;
              $string =~ s/\+/ /g;   
              $string =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("c",hex($1))/eg;
          #print $string;
          return($string);
      }
      sub urlencode {
           my ($string) = $_[0];
          $string =~ s/([^A-Za-z0-9])/sprintf("%%%2X", ord($1))/eg;
               $string =~ s/%20/+/g;
           return ($string);
      }
      1;