hey guys im totally new with jabber/xmpp but i'm currently developing an chat iPhone app and so far so good for regular configuration... 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 apples servers(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 offer you an idea, but I
I offer you an idea, but I don't have more minutes or hours to help you. If you read this idea, you agree to not ask me any more details.
It's possible to write an ejabberd module that adds a hook to the event offline_message_hook. When the hook is executed, the associated function can do whatever you want: send a message stanza to another user, make an HTTP query to a remote machine...
Hey thanks for the answer
In fact i started to code somehow the module but this is my first time and take a look if you can because i keep on having the same error
//////////.erl
-module(mod_offline_push).
-export([start/2,
init/2,
stop/1,
send_notice/3]).
-include("ejabberd.hrl").
-include("jlib.hrl").
start(Host, Opts) ->
?INFO_MSG("Starting mod_offline_push manuel", [] ),
ok.
init(Host, _Opts) ->
inets:start(),
ssl:start(),
ejabberd_hooks:run(offline_message_hook, Host, ?MODULE, send_notice, 10),
ok.
stop(Host) ->,
ejabberd_hooks:delete(offline_message_hook, Host,?MODULE, send_notice, 10),
ok.
send_notice(_From, To, Packet) ->
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=ejabberd", Sep,
"event=", string:sub_word(FromS,1,$/), Sep,
"description=xmpp://", string:sub_word(FromS,1,$/), "%0A", Body, Sep,
"priority=-1" ],
httpc:request(post, {"http://webserver/pushNotification", [], "application/x-www-form-urlencoded", list_to_binary(Post)},[],[]),
ok;
true ->
ok
end.
/////ERROR//////
=ERROR REPORT==== 2010-08-23 18:55:03 ===
E(<0.376.0>:ejabberd_sm:88) : {{badarg,ok},
[{ejabberd_sm,route_message,3},
{ejabberd_sm,route,3},
{ejabberd_local,route,3},
{ejabberd_router,route,3},
{ejabberd_c2s,session_established2,2},
{p1_fsm,handle_msg,10},
{proc_lib,init_p,5}]}
when processing: {{jid,"benoit","192.168.1.1","9357537161282604097774274",
"benoit","192.168.1.1","9357537161282604097774274"},
{jid,"iphone","192.168.1.1",[],"iphone","192.168.1.1",[]},
{xmlelement,"message",
[{"type","chat"},{"to","iphone@192.168.1.1"}],
[{xmlelement,"body",[],
[{xmlcdata,<<"testingggggg offline messages">>}]}]}}
my http request is never called because i create a log each time a do this request and the log is not created....
any ideas??
thanks again
going crazy!
Please help can't figure this error out
-module(mod_offline_push).
-include("ejabberd.hrl").
-include("jlib.hrl").
-include("web/ejabberd_http.hrl").
-define(PROCNAME, mod_offline_push).
-behaviour(gen_mod).
-export([start/2,
stop/1,
init/2,
send_notice/1]).
start(VHost,Opts) ->
?INFO_MSG("Starting mod_offline_push Host: ~p", [VHost]),
register(?PROCNAME,spawn(?MODULE, init, [VHost, Opts])),
ok.
init(VHost, _Opts) ->
inets:start(),
ssl:start(),
ejabberd_hooks:add(offline_message_hook, VHost, ?MODULE,send_notice, 10),
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]),
Sep = "&",
Post = [
"application=",ToS, Sep,
"event=", FromS,Type, Sep,
"description=", Body, Sep,
"priority=-1" ],
httpc:request(post, {"http://pushNotification/chatXpush", [], "application/x-www-form-urlencoded", list_to_binary(Post)},[],[]).
ERRROR REPORT
=ERROR REPORT==== 2010-08-26 16:53:19 ===
E(<0.370.0>:ejabberd_hooks:190) : {undef,
[{mod_offline_push,send_notice,
[{jid,"userA","188.165.211.1",
"2121731711282852044419503",
"userA","188.165.211.206",
"2121731711282852044419503"},
{jid,"userB","188.165.211.1",
[],"userB","188.165.211.1",[]},
{xmlelement,"message",
[{"type","chat"},
{"to","userb@188.165.211.1"}],
[{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","188.165.211.1",
"2121731711282852044419503","userA",
"userA","2121731711282852044419503"},
{jid,"userB","188.165.211.1",[],"userB",
"188.165.211.1",[]},
{xmlelement,"message",
[{"type","chat"},{"to","userB@188.165.211.1"}],
[{xmlelement,"body",[],[{xmlcdata,<<"Hello">>}]}]}]}
sorry i cant help but...
i know these post are now about 4 month old
so i would love to know if you managed to create a push_module for ejabberd ?
i am very new to ejabberd / erlang but i am thinking of making a chat client for the iphone too
if i am right you are trying to send apple the push notification each time a offline msg is received,
as far as i know apple dosent like those many requests or did you implement some kind of buffer in php ?
and wouldnt it be possible to send the request to apple directly through the push_module ?
if you didnt manage or didnt have time i would use your attempt as a starting point for me
lad1337