Botz: Internal Bot Library for Openfire

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 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.*

1.0.0

GPL

3.3.2-3.3.*

1.0.0

GPL

Sample Bot Plugin

Plugin Name

Openfire Version

Plugin JAR

Source Code

Version

License

ParrotBot

3.4.*

1.0.0

GPL

ParrotBot

3.3.2-3.3.*

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

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)

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.

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

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!

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

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

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

Sorry, Ignore my last post, got it sorted

Hi Guys,

Anybody get this library working with opefire 3.6.3?

Best

Mark

Scratch that, got it working.

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

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

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.

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.

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:

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.

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.

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…

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.

Hi,

Anyone have success trying the parrotbot with openfire 3.7.0. It seems to install fine but the actual bot session never starts.

Any and all help appreciated.

Best

Mark

I am using openfire 4.0.1 installation has been done But Bot isn’t coming online please help…?

Hi,

Is a IQHandler required to handle incoming IQ packets? I am getting message packets when the incoming packet is an instance of Message but not so in the case of IQ, kindly clarify if am missing anything.