Question 
We have installed Openfire 3.10.2 on Ubuntu 12.04.

Chat is working fine and for offline message management I have installed the CallbackOnOfflineplugin. When the recipient is offline, a url is called.

The plugin loads the url from the plugin.callback_on_offline.url property, adds ‘to’ and ‘from’ parameters and executes an asynchronous GET request.

sample link:-
http://localhost:8080/user/offline/callback/url?from=1%40fotsum.com&to=2%40fotsum.com

I checked what information I get from that and I got a “to” and “from”, but I also need those along with the message for the push notifications.

Solution:- 

By creating a new table “TblPushNotification”. A table named ‘ofOffline’ is used to store the offline messages so by adding trigger to “ofOffline” table of the database. The trigger will extract the XML and add all attributes to the “TblPushNotification” so you may directly check that table for sending push notification.

Table structure will be below.

CREATE TABLE IF NOT EXISTS `TblPushNotification` (
`id` int(11) NOT NULL,
  `message_id` int(11) NOT NULL,
  `from_user_id` text NOT NULL,
  `to_user_id` text NOT NULL,
  `message` text NOT NULL
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 ;

ALTER TABLE `TblPushNotification`
 ADD PRIMARY KEY (`id`), ADD KEY `message_id` (`message_id`);
ALTER TABLE `TblPushNotification`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

For Trigger use following query.

CREATE TRIGGER `PushNotification` AFTER INSERT ON `ofOffline`
 FOR EACH ROW BEGIN

    DECLARE strMessageText VARCHAR(500) DEFAULT '';
    DECLARE strSenderId VARCHAR(500) DEFAULT '';    
    DECLARE strReceiverId VARCHAR(500) DEFAULT '';        
    DECLARE intMessageId INT DEFAULT 1;

    SET strMessageText = ExtractValue(NEW.stanza, 'message/body[1]');
    SET strSenderId = ExtractValue(NEW.stanza, 'message/@from[1]');
    SET strReceiverId = ExtractValue(NEW.stanza, 'message/@to[1]');
    SET intMessageId = NEW.messageID;    
    INSERT INTO TblPushNotification (message_id,from_user_id,to_user_id,message) VALUES (intMessageId,strSenderId,strReceiverId,strMessageText);

Now it will always extract the XML of ofOffline tablet to TblPushNotification and you can fire query before sending push notification.

You may also like

Leave a Reply