It is possible to send message from ejabberd server manually?

334 Views Asked by At

I am trying to send a message from ejabberd server to the client manually. I create a module and use offline_message_hook to send the message to FCM and take action on FCM response. If I did not get any error in FCM response I try to send an acknowledgement message to the sender that message is sent to the FCM. I am using erlang to create modules for ejabberd server. When I try to send a message like this:

ejabberd_ctl:send_message("normal", From, To, "ack", "101020").

I got this error:

exception error: undefined function ejabberdctl:send_message/5
   in function  mod_http_offline:create_message/1 (/opt/ejabberd-modules/mod_http_offline.erl, line 36)
   in call from ejabberd_hooks:safe_apply/4 (src/ejabberd_hooks.erl, line 236)
   in call from ejabberd_hooks:run_fold1/4 (src/ejabberd_hooks.erl, line 217)
   in call from ejabberd_sm:route/1 (src/ejabberd_sm.erl, line 146)
   in call from ejabberd_router:do_route/1 (src/ejabberd_router.erl, line 399)
   in call from ejabberd_router:route/1 (src/ejabberd_router.erl, line 92)
   in call from ejabberd_c2s:check_privacy_then_route/2 (src/ejabberd_c2s.erl, line 855)

The error is seems like the function is not accessable for the module but I don't know what file should I need to include to use this function? When I try to send a message like this:

XmlBody = {xmlelement, "message", [{"id", []},{"type", "normal"}, {"from", From}, {"to", To}], [{xmlelement, "body", [], [{xmlcdata, <<"Test Message">>}]}]},
ejabberd_router:route(From, To, XmlBody);

I got this error:

exception error: no function clause matching
                  ejabberd_router:route(<<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>,
                                        <<"67456efc-be57-4cbd-a176-527de2dce19d">>,
                                        {xmlelement,"message",
                                         [{"id",[]},
                                          {"type","normal"},
                                          {"from",
                                           <<"e5d6d83c-ea77-4d10-aaac-4e0e38899ac2">>},
                                          {"to",
                                           <<"67456efc-be57-4cbd-a176-527de2dce19d">>}],
                                         [{xmlelement,"body",[],
                                           [{xmlcdata,<<"Test Message">>}]}]}) (src/ejabberd_router.erl, line 101)
   in function  mod_http_offline:create_message/1 (/opt/ejabberd-modules/mod_http_offline.erl, line 38)
   in call from ejabberd_hooks:safe_apply/4 (src/ejabberd_hooks.erl, line 236)
   in call from ejabberd_hooks:run_fold1/4 (src/ejabberd_hooks.erl, line 217)
   in call from ejabberd_sm:route/1 (src/ejabberd_sm.erl, line 146)
   in call from ejabberd_router:do_route/1 (src/ejabberd_router.erl, line 399)
   in call from ejabberd_router:route/1 (src/ejabberd_router.erl, line 92)
   in call from ejabberd_c2s:check_privacy_then_route/2 (src/ejabberd_c2s.erl, line 855)

I did not understand this error.

0

There are 0 best solutions below