Search code examples
erlangejabberdejabberd-module

Reading ejabberd.yml module parameter fails


I have a Ejabberd module for pushing notifications in case the recipient of a message is offline. In principle, it works reasonably well. One problem is that the URL to which I push the notification is hard-coded in the module. Intuitively this should be configurable in the ejabberd.yml conf file.

The relevant snippet in my ejabberd.yml looks like this

modules:
  mod_fcm_fork:
    post_url: "http://xxx.xxx.xxx.xxx/notification/push/"

The problem is that I cannot access that value inside my module, at least not in the way I can find on the Web:

push_notification(From, To, Packet) ->
  URL = gen_mod:get_module_opt(global, ?MODULE, post_url, []),
  %URL = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, post_url, []),
  ?INFO_MSG("mod_fcm_fork -> push_notification: ~p~n",[URL]),
  ...

This command throws the following warning (not even an error):

[warning] <0.5453.0>@ejabberd_config:prepare_opt_val:806 incorrect value '"http://xxx.xxx.xxx.xxx/notification/push/"' of option 'post_url', using 'undefined' as fallback

So it kind of finds / sees the value. Any way the ?INFO_MSG prints and undefined:

2017-01-26 20:16:09.019 [info] <0.5453.0>@mod_fcm_fork:push_notification:52 mod_fcm_fork -> push_notification: undefined

Interestingly, the following works nicely:

start(Host, _Opts) ->
  URL = proplists:get_value(post_url, _Opts),
  ?INFO_MSG("HTTP client started ~p~n", [URL]),

But in push_notification I don't have access to _Opts which in turn is called by a hook. So how can I get the post_url value in the method push_notification?


Solution

  • gen_mod:get_module_opt(global,?MODULE,post_url,fun(X) -> X end, all)