A common way of creating a new XMPP service is to develop a plugin that will serve the service as a subdomain. 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 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 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.
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.igniterealtime.openfire.botz.BotzConnection;
import org.igniterealtime.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();
}
}
}
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, it needs to be defined as a dependency of your plugin project. The dependency can be obtained from Ignite's Maven repository, as shown in this snippet of a pom.xml
file:
<dependencies>
<dependency>
<groupId>org.igniterealtime.openfire.botz</groupId>
<artifactId>botz</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>igniterealtime</id>
<name>Ignite Realtime Repository</name>
<url>https://igniterealtime.org/archiva/repository/maven/</url>
</repository>
</repositories>