https://github.com/igniterealtime/botz
The Botz library adds to the already rich and extensible Openfire with the ability to create internal user bots. With the 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.
https://github.com/igniterealtime/botz
Last synced: 9 months ago
JSON representation
The Botz library adds to the already rich and extensible Openfire with the ability to create internal user bots. With the 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.
- Host: GitHub
- URL: https://github.com/igniterealtime/botz
- Owner: igniterealtime
- License: apache-2.0
- Created: 2022-10-13T16:50:40.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-28T08:19:08.000Z (over 1 year ago)
- Last Synced: 2025-04-24T05:49:11.228Z (9 months ago)
- Language: Java
- Size: 43 KB
- Stars: 3
- Watchers: 7
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://github.com/igniterealtime/Botz/actions/workflows/continuous-integration-workflow.yml)
About
-----
The Botz library adds to the already rich and extensible [Openfire] with the ability to create internal user bots. With the 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.
[Openfire] is a XMPP server licensed under the Open Source Apache License.
[Botz] - an [Ignite Realtime] community project.
Ignite Realtime
===============
[Ignite Realtime] is an Open Source community composed of end-users and developers around the world who
are interested in applying innovative, open-standards-based Real Time Collaboration to their businesses and organizations.
We're aimed at disrupting proprietary, non-open standards-based systems and invite you to participate in what's already one
of the biggest and most active Open Source communities.
[Botz]: http://www.igniterealtime.org/projects/botz/index.jsp
[Openfire]: http://www.igniterealtime.org/projects/openfire/index.jsp
[Ignite Realtime]: http://www.igniterealtime.org
[XMPP (Jabber)]: http://xmpp.org/
## 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 a working sample that shows how to use Botz classes in a plugin. The sample plugin is a parrot bot service that simply echoes ** packets back to the sender.
`plugin.xml`
```xml
John Doe
org.example.ParrotBot
${project.name}
${project.description}
${project.version}
Apache 2.0
2024-06-27
4.8.0
```
`pom.xml`
```xml
4.0.0
org.example
ParrotBot
1.0-SNAPSHOT
ParrotBot
Echo bot for Openfire
11
11
UTF-8
4.8.0
org.apache.maven.plugins
maven-resources-plugin
3.3.1
UTF-8
org.apache.maven.plugins
maven-assembly-plugin
org.igniterealtime.openfire.plugins
openfire-plugin-assembly-descriptor
${openfire.version}
make-assembly
package
single
false
${project.artifactId}
false
openfire-plugin-assembly
org.apache.felix
maven-bundle-plugin
3.0.0
true
org.apache.maven.plugins
maven-compiler-plugin
11
11
org.igniterealtime.openfire
xmppserver
${openfire.version}
provided
org.igniterealtime.openfire.botz
botz
1.3.0
mvnrepository
Maven Central Repository
https://repo1.maven.org/maven2/
sonatype
Sonatype Repository
https://oss.sonatype.org/content/repositories/releases/
igniterealtime
Ignite Realtime Repository
https://igniterealtime.org/archiva/repository/maven/
igniterealtime
Ignite Realtime Repository
https://igniterealtime.org/archiva/repository/maven/
mvnrepository
Maven Central Repository
https://repo1.maven.org/maven2/
```
`src/main/java/org/example/ParrotBot.java`
```java
package org.example;
import org.igniterealtime.openfire.botz.BotzConnection;
import org.igniterealtime.openfire.botz.BotzPacketReceiver;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
import org.xmpp.packet.Message;
import java.io.File;
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();
}
}
}
```
## 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, 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:
```xml
org.igniterealtime.openfire.botz
botz
1.3.0
igniterealtime
Ignite Realtime Repository
https://igniterealtime.org/archiva/repository/maven/
```