8

I have installed Openfire 3.10.2 on Ubuntu 12.04.

Chat is working fine and for offline message management I have installed the CallbackOnOffline plugin. 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.

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.


Important Part :-


I want to customize CallbackOnOffline plugin of openfire and I want to add one more parameter "message". How can I do that?

You will find the code here: https://github.com/igniterealtime/Openfire/blob/master/src/plugins/callbackOnOffline/src/java/com/fotsum/CallbackOnOffline.java

Now, how to create .jar file, which require to make installable plugin in openfire ?

Er.KT
  • 2,852
  • 1
  • 36
  • 70
  • try these two plugins, https://github.com/xinminlabs/openfire-apns-plugin and https://github.com/meisterfuu/Openfire-GCM – calvinfly Sep 29 '15 at 10:20
  • calvinfly : ok, let me try that, but how openfire will get device tokens of device ? – Er.KT Sep 29 '15 at 10:26
  • create a custom IQHandler like [this](https://github.com/xinminlabs/openfire-apns-plugin/blob/master/src/main/java/com/wecapslabs/openfire/plugin/apns/ApnsIQHandler.java). In client app, send this custom IQ packet to XMPP server to register token. – calvinfly Sep 30 '15 at 00:59
  • @Er.KT i have latest source code for edit existing Plugin and also i had made changes in that plugin. Now how to make a JAR File? – Parthpatel1105 Sep 27 '16 at 06:31
  • @Parthpatel1105 I am on the stage my friend, I have the code and changes but dont know how to build jar file. – Er.KT Sep 27 '16 at 09:09
  • Can you give me that code? – Parthpatel1105 Sep 27 '16 at 11:48

3 Answers3

4

If you want to add more parameters to the link. You need to extend the CallbackOnOffline Plugin. You will find the code here: https://github.com/igniterealtime/Openfire/blob/master/src/plugins/callbackOnOffline/src/java/com/fotsum/CallbackOnOffline.java

If you look into the java class, you will find on line 109 and 110 the "to" and "from" parameter which will be send back (callback). Just add there your parameter with value you need.

Update: After that you need to build the plugin with ANT again. See a how to build a plugin: https://www.igniterealtime.org/builds/openfire/docs/latest/documentation/plugin-dev-guide.html

Roman S.
  • 1,206
  • 15
  • 24
  • Thanks Roman, I have idea about that codes but the problem is how to create .jar file, which require to make installable plugin ? – Er.KT Oct 02 '15 at 04:52
  • 1
    You need to buld the plugin with ANT. Look here for further plugin building: https://www.igniterealtime.org/builds/openfire/docs/latest/documentation/plugin-dev-guide.html – Roman S. Oct 02 '15 at 14:10
3

I also had the same problem and I Solved it by creating a new table "TblPushNotification". A table named 'ofOffline' is used to store the offline messages so I added 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.

Please find my tables' details as 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.

HarshIT
  • 4,583
  • 2
  • 30
  • 60
  • Thanks for your detailed answer. Can you please tell me if we call any URL or web service at the server side at the time of TRIGGER when data is entering into the table 'TblPushNotification'. Actually we can do the TRIGGER operation but to send push notification from the server we need to call customer URL to send push notification to the device from server. – Parthpatel1105 Sep 23 '16 at 07:03
1

Trigger

--
-- Triggers `ofOffline`
--
DELIMITER //
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 push_notification (message_id,from_user_id,to_user_id,message) VALUES (intMessageId,strSenderId,strReceiverId,strMessageText);


END
//
DELIMITER ;

Table :

CREATE TABLE IF NOT EXISTS `push_notification` (
`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 ;
Er.KT
  • 2,852
  • 1
  • 36
  • 70