Currently Being Moderated

Botz: Internal Bot Library for Openfire

VERSION 3  Click to view document history

Created on: Sep 17, 2007 8:40 AM by Aznidin - Last Modified:  Sep 21, 2007 10:06 AM by Aznidin

Overview

A common way of creating a new XMPP service is to develop a plugin that will serve the service as a sub domain. That said, if Openfire's domain is example.com programmers would develop the new service as an internal or external component and deploy it as myservice.example.com.

 

Botz library adds the already rich and extensible Openfire with the ability to create internal user bots. With Botz library, programmers may choose to develop a user bot to run as a service bearing myservice@example.com as its JID. To Openfire, the user bot is just like other (human) users.

 

Botz library is strictly internal for Openfire. The notion of a user connection doesn't involve any TCP/IP or socket; hence virtual. There isn't even a C2S implementation.

 

Botz Classes

Botz library contains BotzConnection class that allows a user bot to login as a registered or anonymous user. The class optionally automates the creation and registration of the user bot if it has not existed in the database. To make the user bot useful, programmers would implement BotzPacketReceiver interface to respond to received packets. BotzPacketReceiver.processIncomingPacket(Packet) will be called for every packet received by the user bot. To send packets to other XMPP entities, programmers in turn call BotzConnection.sendPacket(Packet).

 

Botz classes may be used in situations where an internal user bot is needed. Botz most likely proves itself useful in the development of Openfire extensions through plugins.

 

Key Features

  • Login anonymously

  • Login as an existing Openfire user

  • Optionally create a new user as a registered user (bot) if it does not exist. The newly created user account will be stored in the database. Because user creation is done using SQL statements internal to Openfire, this should work for all Openfire-supported databases.

  • The above features hide programmers from handling the connection establishment and allow programmers to focus on packet exchanges.

  • Change BotPacketReceiver on the fly, thus switch behaviors and create multiple personalities of a bot.

 

Using Botz in A Plugin

The following is the code snippet that shows a way to use Botz classes in a plugin. The sample plugin is a parrot bot service that simply echoes <message/> packets back to the sender.

 

import org.jivesoftware.openfire.botz.BotzConnection;
import org.jivesoftware.openfire.botz.BotzPacketReceiver;
 
public class ParrotBot implements Plugin {
    @Override
    public void destroyPlugin() { }
 
    @Override
    public void initializePlugin(PluginManager manager, File pluginDirectory) {
        BotzPacketReceiver packetReceiver = new BotzPacketReceiver() {
            BotzConnection bot;
 
            public void initialize(BotzConnection bot) {
                this.bot = bot;
            }
 
            public void processIncoming(Packet packet) {
                if (packet instanceof Message) {
                    // Echo back to sender
                    packet.setTo(packet.getFrom());
                    bot.sendPacket(packet);
                }
            }
 
            public void processIncomingRaw(String rawText) { };
            public void terminate() { };
        };
 
        BotzConnection bot = new BotzConnection(packetReceiver);
        try {
            // Create user and login
            bot.login("parrot");
            Presence presence = new Presence();
            presence.setStatus("Online");
            bot.sendPacket(presence);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

 

 

 

License

This software is published under the terms of the GNU General Public License (GPL).

 

Downloads

Botz Library

Openfire Version

Botz Library

Source Code

Version

License

3.4.*

botz-openfire-3.4.jar

botz-openfire-3-4.src.zip

1.0.0

GPL

3.3.2-3.3.*

botz-openfire-3-3.jar

botz-openfire-3-3.src.zip

1.0.0

GPL

 

Sample Bot Plugin

Plugin Name

Openfire Version

Plugin JAR

Source Code

Version

License

ParrotBot

3.4.*

parrotbot-openfire-3-4.jar

parrotbot-openfire-3-4.src.zip

1.0.0

GPL

ParrotBot

3.3.2-3.3.*

parrotbot-openfire-3-3.jar

parrotbot-openfire-3-3.src.zip

1.0.0

GPL

 

Installation

The Botz library is not a plugin in itself, and does not contain any plugin-related class. It is meant for use in an application development. To use the library in an Openfire plugin development, copy botz-openfire-version.jar file into the lib directory of the plugin directory structure. If there are more than one plugins that will use Botz library, the JAR file can be copied to a global class path like openfire/build/lib/dist or {$OPENFIRE_HOME}/lib.

 

To install the sample ParrotBot plugin, rename parrotbot-openfire-version.jar to parrotbot.jar and copy it into {$OPENFIRE_HOME}/plugins directory. To see the ParrotBot in action, send messages to it using your favorite Jabber client.

 

The parrot user bot appears as a real user in Openfire admin console:

 

Figure 1: Parrot Bot As A Registered User

 

When logged in, the bot has a client session:

 

Figure 2: Parrot Bot Logged In

 

 

User-Contributed Bot Plugins

Plugin Name

Plugin JAR

Source Code

Version

Author

License

 

Bot Plugins Wish List

Plugin Name

Description

CAPService

An implementation of XEP-0127:Common Alerting Protocol(CAP) Over XMPP

NameService

MUC Name Service

RoomService

MUC Room Service

 

8,913 Views Tags: plugin, bot, botz
Average User Rating
(5 ratings)
Benny Kusman  says:

Hi ALl,

I have this errors. Could Somebody please assist me? I have put the parrotbot.jar in the plugins and also the      botz-openfire-3-3.jar in the build/lib. Im using openfire 3.3. Please help, thanks

 

Error loading plugin: E:\Project\EMO\Server\openfire\netbeansProject\plugins\parrotbot

java.lang.NoSuchMethodError: org.jivesoftware.openfire.user.UserManager.createUser(Ljava/lang/String;Ljava/l ang/String;Ljava/lang/String;Ljava/lang/String;)Lorg/jivesoftware/openfire/user/ User;

        at org.jivesoftware.openfire.botz.BotzConnection.login(BotzConnection.java:318)

        at org.jivesoftware.openfire.botz.BotzConnection.login(BotzConnection.java:241)

        at org.jivesoftware.openfire.plugin.ParrotBot.initializePlugin(ParrotBot.java:75)

        at org.jivesoftware.openfire.container.PluginManager.loadPlugin(PluginManager.java :404)

        at org.jivesoftware.openfire.container.PluginManager.access$200(PluginManager.java :46)

        at org.jivesoftware.openfire.container.PluginManager$PluginMonitor.run(PluginManag er.java:916)

        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)

        at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)

        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)

        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101 (ScheduledThreadPoolExecutor.java:98)

        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodi c(ScheduledThreadPoolExecutor.java:181)

        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Schedu ledThreadPoolExecutor.java:205)

        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java: 885)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)

        at java.lang.Thread.run(Thread.java:619)

Benny Kusman  says:

Hi, how to chat with parrotBot ? What is the password for parrotBot? I tried to change the password, and seems i can log in but cant add user.

Benny Kusman  says:

again.. i cant see the parrotBot in the 'Session'. the parrotbot appear only as normal user, and not online.

adev  says in response to Benny Kusman:

sosys, your path might be the issue.. why did you place it in openfire\netbeansProject? i'm assuming you're using a source build. if that's the case, parrotbot-openfire-3-3.jar should be in openfire/target/openfire/plugins/

also, if you're only testing the parrotbot, you don't need to have a copy of the botz library in lib/ since it already has the jar file in its local lib/ path

in regards to your second post, the parrotbot does not need a password since it authenticates itself, and the account is automatically created if it already doesn't exist. once you have this figured out, send a message to parrot@/Botz

 

as for my question, i'd like to know if it would be possible to authenticate the bot without having to create an account since the authentication on my server takes place on ldap, which is read-only. if not, how can i assign a name of my own choice to the bot using the anonymous login? the bot gets a random name when using anonymous login.

adev  says in response to adev:

i solved my problem on my own.

as a reference for anyone else that's interested..

in order to set a username with anonymous login, you must first comment out lines 345 to 359 (for the source version of 3.4), this is where it checks if the user is registered or not.

you should then be able to login using bot.login("bot_name", "resource");

 

thank you for this library.

adev  says in response to adev:

i apologize, i forgot to mention the above changes need to be made to BotzConnection.java

Zemian Deng  says:

I tried with openfire 3.5 and got this to work after few fixes. I thought I might give you feedback and let you updates your dist.

 

1)The ParrotBot.java is not compilable because you have @Override on methods that's from interface. So you remove it will compile.

 

2)The document from http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/plugin-d ev-guide.html didn't tell where to get the build script! So I can't compile your parrot plugin sample.

 

After looking arround, I downloaded the openfire source distribution, copied your parrot plugin into src/plugins directory, and cd into root src project and ran:

 

$ ant -f build/build.xml openfire plugin -Dplugin=parrotbot

 

Now I got a generated plugin jar under arget/openfire/plugins

 

Now I can update and play with codes to get further playing with botz library. Great work Aznidin Zainuddin!

taha bekir eren  says:

Hi,

I'm using the botz library. I perform a login with a username which already exists in the registered users. An msn transport is registered for the user.

Sometime (2-3 minutes) after I create the connection and perform the login, the user becomes offline automatically.

 

How can I solve the problem?

 

Thanks

drh drh  says in response to zhang wei:

Hi I'm having a bit of trouble getting this to work. I have a source build in eclipse and I have put the btz jar into a lib directory in my plugin and in eclipse it is showing with no errors but when I run the ant build it gives me the following message:

 

package org.jivesoftware.openfire.botz does not exist

    javac import org.jivesoftware.openfire.botz.BotzConnection;

Do I need to modify the build file in some way? Sorry not much knowledge of

ant

 

Any help would be greatly appreciated

drh drh  says in response to drh:

Sorry, Ignore my last post, got it sorted

mark16 mark16  says:

Hi Guys,

 

Anybody get this library working with opefire 3.6.3?

 

Best

Mark

 

Scratch that, got it working.

edalessio edalessio  says in response to mark16:

Does anyone have this working successfully in 3.6.3?  What's the trick?

mark16 mark16  says in response to edalessio:

Dont think there was a trick in the end, i just followed the above procedure and made sure the bots library was dropped into the openfire installation lib dir as far as i can remember

edalessio edalessio  says in response to mark16:

Thanks, Mark.  I was having trouble building the parrotbot plugin from eclipse.  Turns-out I had two issues:

  1. I had to comment-out the two references to @Override -- I think this is because we're implementing an Interface rather than subclassing another class -- I don't think @override annotations apply to Interfaces (but I'm not certain)?
  2. I was both including the botz-openfire.jar as part of the plugin project and as part of the openfire server...  I think it was causing problems, so when I just used the botz-openfire.jar as part of the plugin jar, everything behaved.
mark16 mark16  says in response to edalessio:

Hi edalessio, glad you got it working. I have found it to be quite a handy library, pity it has not been updated in a while, but im happy once it still works.

dyat dyat  says:

Hi.. can anybody tell me if parrotBot 3.4 works with current version of openfire 3.6.4, earlier I used this bot with Openfire 3.2 everything went smooth But rite now I am trying to attach the bot version 3.4 to openfire recent version and it seems problem with presence subscription, I am getting this packet inside parrot bot class:

<presence id="fE1f0-30" to="bot1@localhost" type="subscribe" from="test1@localhost"/>

 

and bot is not coming online in contact list of user test1

 

Pls tell me if anyone has come across this issue, currently I am debugging it.

rks rks  says in response to dyat:

Dyat, I got it working in Openfire 3.6.4 without problems. I do login with an existing bot-user though, and it is important that the bot-user itself is subscribing to other peoples presence.

 

However, this plugin does not end gracefully. Even if removed from the Plugins-list (during development for instance) the bot remains in memory and responds.

GradStad255 GradStad255  says:

Hi,

Sorry im a newb but,

Im trying to get the parrotbot to work in netbeans and I am having import issue with the followig:

import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;  

 

It says package does not exist.

 

What can I do to fix this, is there another plugin I need to download, Ive already loaded the parrot

botz-openfire-3.4 jar into the projects library?

 

If anybody Could please Help...

moe1 moe1  says:

Hey

I have got the parrotbot to work 100%. I am new to openfire and using plugins and bots. I am trying to modify the parrot bot source code but nothing happens. Instead of the repeating whatever I say I want the parrot bot to tell me the time. Any ideas? Like I said I am new to plugins and bots.

 

Any help will be highly appreciated.

Bookmarked By (1)

More Like This

  • Retrieving data ...