powered by Jive Software

Can I send messages on behalf of a user?

I have a ruby on rails application that I would like to send Jabber messages. I’m able to get a ruby client connecting and sending messages as one of the Openfire users.

I’m also creating a new user with the User Service plugin every time a new user is created.

I need this application to be able to handle 1000s of users, but I know that keeping connections open in my rails application will prevent that from happening.

I’m wondering if there is a way to use Openfire to send messages without having to create a connection every time. Openfire would be both server and client. The best situation would be for my rails application to issue a HTTP request to Openfire with:

  • the from Jabber ID

  • the to Jabber ID

  • a message

If anyone has any suggestions on how to best approach this problem, I’d be very grateful.

You could write a Openfire plugin that does the job. Take Presence Service or Registration Plugin as example to create such an HTTP interface. Once you have the data inside your plugin, sending the message is simple:

XMPPServer xmppServer = XMPPServer.getInstance();
PacketRouter packetRouter = xmppServer.getPacketRouter();
String serverName = xmppServer.getServerInfo().getXMPPDomain();
public void sendMessage(JID to, JID from, String message) {     
     Message packet = new Message();
     packet.setType(Message.Type.chat);      packet.setFrom(from);
     
     if (to.getResource() != null
        && sessionManager.isActiveRoute(to.getNode(), to.getResource())) {
          packet.setTo(to);
     }
     else {
          // resource is offline => send to bare JID
          packet.setTo(new JID(to.getNode(), serverName, null, true));
     }      packet.setBody(message);
     packetRouter.route(packet);
}

You will have to ensure, that only your application can use this interface, otherwise it would be a security risk!

You, sir, are a wonderful and magmanomous person. And, I dare I say, sexy?

I have two other related questions.

First, where do new messages get created? I’d like Openfire to create a record, or send a request back to my rails application every time a new message is received.

Second, where could I find someone to pay to do this for me? If I can avoid it, I’d rather not make these changes that someone familiar with the system could probably make in a day. If interested, please email me at justin AT jupiterit DOT com.

First, where do new messages get created? I’d like Openfire to create a record, or send a request back to my rails application every time a new message is received.

There are several ways to intercept incoming and outgoing packets. See PluginDevGuide, section “Implementing Your Plugin”.