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 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 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 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">>}]}]}]}