Recently I need a offline push notification on ejabberd server for iOS and Android remote notification, after a sets of google and try I found the following solution, it works fine on jabberd-15.11, hope it helpful for somebody.
You should save the following code to a file and put it into ejabberd source code folder ejabberd-15.11/src/mod_offline_push.erl
You should save the following code to a file and put it into ejabberd source code folder ejabberd-15.11/src/mod_offline_push.erl
%% name of module must match file name
-module(mod_offline_push).
-author("guangmean").
%% Every ejabberd module implements the gen_mod behavior
%% The gen_mod behavior requires two functions: start/2 and stop/1
-behaviour(gen_mod).
%% public methods for this module
-export([start/2, stop/1, message_push/3]).
%% included for writing to ejabberd log file
-include("ejabberd.hrl").
-include("logger.hrl").
%% ejabberd functions for JID manipulation called jlib.
-include("jlib.hrl").
start(Host, Opts) ->
?INFO_MSG("Loading offline message push mode", []),
ejabberd_hooks:add(offline_message_hook, Host, ?MODULE, message_push, 3).
stop(Host) ->
?INFO_MSG("Stoping offline message push mode", []),
ejabberd_hooks:delete(offline_message_hook, Host, ?MODULE, message_push, 3).
message_push(From, To, Packet) ->
MessageType = xml:get_tag_attr_s(<<"type">>, Packet),
MessageFrom = xml:get_tag_attr_s(<<"from">>, Packet),
MessageTo = xml:get_tag_attr_s(<<"to">>, Packet),
curl_request_push(MessageFrom, MessageTo),
ok.
curl_request_push(From, To) ->
?INFO_MSG("Pushing notify From ~p To ~p~n",[From, To]),
httpc:request(post, {"http://fullstacking.blogspot.com", [], "application/x-www-form-urlencoded", list_to_binary(["from=", From, "&to=", To])}, [], []).
Compile ejabberd:
./configure --prefix=/your/ejabberd/install/path/ejabberd-15.11
make
make install
Compile ejabberd:
./configure --prefix=/your/ejabberd/install/path/ejabberd-15.11
make
make install