Categories
Commercials Computing Java WebSphere

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.

Share
Categories
General

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.

Share
Categories
General

Openfire/XMPP Multi-User Chat name is registered as all lower-case

Another observation regarding XMPP multi-user chat (aka chat-rooms) to follow on my previous entry. This one is also an odd one.
It appears that Openfire uses all-lowercase names for multi-user chat rooms. So if your room’s name is “myRoom”, it will be saved as “myroom”.

Could not find anything to require this in the XMPP specifications for multi-user chat.

Oddness.

UPDATE:
This is apparently the way it is supposed to be according to the XMPP protocol or as explained to me on the Openfire dev boards.

Share
Share