Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ejabberd mod_offline iphone pushed notifications

I'm currently developing a chat iPhone app and so far so good for regular configuration for the ejabberd server. I want to implement Push notification when the user is "offline" and to do this I just need to run a PHP script which gets a Token device and the text message to deliver via SSL to Apple's servers (the Apple part is done), my problem begins is that i have no clue how to implement this action to my ejabberd server? basically I just need to create an action on a received offline message i this possible. Can someone point me in the right direction. I have manage to begin writing some code for a new module but I get same error all the time when this module is called by the offline messages here's the code and the error.

module.erl

-module(mod_offline_push).
-behaviour(gen_mod).
-include("ejabberd.hrl").

-export([start/2, stop/1, send_notice/1]).

start(VHost,_Opts) ->
 ?INFO_MSG("Starting mod_offline_push Host: ~p", [VHost]),
 inets:start(),
    ssl:start(),
 ejabberd_hooks:add(offline_message_hook, VHost, ?MODULE,send_notice, 50), 
 ok.


stop(VHost) ->
    ?INFO_MSG("mod_offline_push stopping Host: ~p", [VHost]),
    ejabberd_hooks:delete(offline_message_hook, VHost, ?MODULE, send_notice, 50),
    ok.

send_notice(Packet) ->
 ?INFO_MSG("after http:",[]),
 Type = xml:get_tag_attr_s("type", Packet),
 FromS = xml:get_tag_attr_s("from", Packet),
 ToS   = xml:get_tag_attr_s("to", Packet),
 Body = xml:get_path_s(Packet, [{elem, "body"}, cdata]),
 if
 (Type == "chat") and (Body /= "") ->
 Sep = "&",
 Post = [
 "application=",ToS, Sep,
 "event=", FromS,Type, Sep,
 "description=", Body, Sep,
 "priority=-1" ],
 httpc:request(post, {"http://pushNotification/push", [], "application/x-www-form-urlencoded", list_to_binary(Post)},[],[]),
  ok;
 true ->
   ok
    end.

ERROR

=ERROR REPORT==== 2010-08-26 16:53:19 ===
E(<0.370.0>:ejabberd_hooks:190) : {undef,
                                   [{mod_offline_push,send_notice,
                                     [{jid,"userA","198.165.211.1",
                                       "2121731711282852044419503",
                                       "userA","198.165.211.206",
                                       "2121731711282852044419503"},
                                      {jid,"userB","198.165.211.1",
                                       [],"userB","198.165.211.1",[]},
                                      {xmlelement,"message",
                                       [{"type","chat"},
                                        {"to","[email protected]"}],
                                       [{xmlelement,"body",[],
                                         [{xmlcdata,<<"Hello">>}]}]}]},
                                    {ejabberd_hooks,run1,3},
                                    {ejabberd_sm,route,3},
                                    {ejabberd_local,route,3},
                                    {ejabberd_router,route,3},
                                    {ejabberd_c2s,session_established,2},
                                    {p1_fsm,handle_msg,10},
                                    {proc_lib,init_p,5}]}
running hook: {offline_message_hook,
                  [{jid,"userA","198.165.211.1",
                       "2121731711282852044419503","userA",
                       "userA","2121731711282852044419503"},
                   {jid,"userB","198.165.211.1",[],"userB",
                       "198.165.211.1",[]},
                   {xmlelement,"message",
                       [{"type","chat"},{"to","[email protected]"}],
                       [{xmlelement,"body",[],[{xmlcdata,<<"Hello">>}]}]}]}
like image 609
Boxtel Avatar asked Aug 30 '10 15:08

Boxtel


3 Answers

what the stacktrace says, is that there is no send_notice function in the mod_offline_push that accepts three parameters (the two JIDs ones and the packet itself). The signature of your function doesn't match, as it expect only 1 argument.

The hook is expecting three-argument callbacks, so try with

send_notice(_From, _To, Packet).
like image 186
ppolv Avatar answered Oct 02 '22 07:10

ppolv


Please use the below blog , very informative.Their code works fine for me.

http://symmetricinfinity.com/2013/01/23/ios-push-notifications-from-ejabberd.html

like image 30
vks Avatar answered Oct 02 '22 09:10

vks


Make sure you remove the INFO_MSG lines in the source files.After that recompile and replace the beam files in the ejabberd folder.Don't forget to restart ejabberd.

like image 42
sureshprasanna70 Avatar answered Oct 02 '22 07:10

sureshprasanna70