Commercials / Computing / Java / WebSphere2 Comments
Nov 08

Building an IM Bot with the Smack API. Avoid setting Roster Permissions

So I built what is an instant messaging bot using the Smack API and the Openfire XMPP server. Doing it is pretty simple of you read the documentation and Smack’s developer notes. The bot relies on a queue-like object that Smack gives you called a PacketCollector. All you need to do is log in to the server, and let the packet collector wait for incoming messages. Clearly, you need to respond to the messages and use thread tools to do the waiting and all, but in general, the effort is relatively straightforward.
Continue reading →

Nov 08

Smack API: Destorying persistent Multi-User Chat Rooms

Another one that is not documented.
Suppose you have a persistent Multi-User Chat Room (MUC) and room is empty. Apparently to destroy the room, the owner needs to join it, and then call the destroy() method on that room.
See, short and sweet.

Nov 08

Smack API: No clean way to discover if a multi-user chat room exists

Here’s another one to follow the previous two posts about Smack API and Multi-User Chat issues.
Suppose you want to create a persistent room. Suppose you are not sure if that room already exists. In Smack, and I am not familiar of any other APIs, there is no non-exception-throwing way of doing this.

Fundamentally, a room already exists is the situation where a room is already set up on the server with the same name as the one you wish to create.

The MultiUserChat object has a static getRoomInfo() method which may have been the way to go. If the room does not exist, return null. Instead, if the room does not exist throws an XMPPException. Not sure what the error situation is here – I am just trying to find out if a room exists or not, but that causes an exception.

The flipside is on the creation end. If you try to create a room that already exists, an XMPPException will be thrown. This makes sense and is recoverable. Still, I am a fan of checking first instead of trying to do something only to encounter a bad situation. Not a biggie – just hope this spares someone the exploration and time. Not really documented, etc.