powered by Jive Software

Smack Attention/Buzz feature

I have written a small tool using the API that monitors DBs for excessive transaction time. Is there a way that I can utilize the “buzz” (Clicking the bell on the Spark IM window) feature using this API? If not, would it be possible to conisder adding this in a future version of the API?

Thanks,

Eric K.

Hi Eric,

The buzz feature in Spark is pretty basic so I’m not sure if it really needs to be added as an API to Smack. It would probably make more sense to implement XEP-0224 if/when it moves beyone experimental status.

However, to buzz someone who is using Spark you can send them the following message:

<message id="4YP96-26" to="you@example.com">
  <buzz xmlns="http://www.jivesoftware.com/spark"></buzz>
</message>

Hope that helps,

Ryan

Hi Ryan

Thanks for your help. I think I am pretty close to getting this (I dont work in Java very much). I have created a specific Message object and gave it the parameters specified in your message:

/* Build the Buzz Message */

Message buzz = new Message();

buzz.setPacketID(“4YP96-26”);

buzz.setTo(“kobelsem@openfire_srv”);

    buzz.setDefaultXmlns("http://www.jivesoftware.com/spark");

After I log into the openfire server, I create a chat object:

Chat chat = connection.getChatManager().createChat(

“kobelsem@openfire_srv”, new MessageListener() { public void processMessage(Chat chat, Message message) {}}

);

And then attempt to send the message:

try

{

chat.sendMessage(“blah”);

chat.sendMessage(buzz);

}

catch (Exception ex)

{

System.out.println(ex.getMessage());

}

I am able to recieve the “blah” without any difficulties, however the buzz does not come through. If I cast the buzz message to XML and view it it appears as:

to the message?

Thanks,

Eric K.

Hi Eric,

You’re got the right idea but there are a couple of things that you’ll need to change.

First, you don’t want to set the packet id. The packet id is a randomly generated id that you’ll want to have smack do for you in this case (which happens by default). And second, you’ll need to to implement your own buzz PacketExtension, which isn’t too difficult as you can see from the down and dirty sample code below:

private void sendBuzz() {
      Message buzz = new Message();
      buzz.setTo("kobelsem@openfire_srv");
      buzz.addExtension(new PacketExtension() {
         public String getElementName() {
            return "buzz";
         }          public String getNamespace() {
            return "http://www.jivesoftware.com/spark";
         }          public String toXML() {
            return "<" + getElementName() + " xmlns=\"" + getNamespace() + "\"/>" ;
         }
      });
            connection.sendPacket(buzz);
   }

Hope this helps,

Ryan

Hmm… something strange happened with the code when I formatted it. I’ve attached a sample file that includes the sendBuzz() method.

Grr… and now the file attachment doesn’t see to be working. Here is the method with the tags:

private void sendBuzz() {

Message buzz = new Message();

buzz.setTo(“kobelsem@openfire_srv”);

buzz.addExtension(new PacketExtension() {

public String getElementName() {

return “buzz”;

}

public String getNamespace() {

return “http://www.jivesoftware.com/spark”;

}

public String toXML() {

return “<” xmlns="" + getNamespace() + “”/>" ;

}

});

connection.sendPacket(buzz);

}

Message was edited by: ryang
Login.java (1200 Bytes)

Still no luck. Here is just the toXML() method:

public String toXML() {
   return "<buzz xmlns=\"http://www.jivesoftware.com/spark\"/>";
}

Thanks for your help Ryan!!! The buzz feature is working correctly. Now I just have to modify the app to make the Spark conversation window immediately restore from the windows taskbar a message is sent.