0

我有一个 Ejabberd 模块,用于在消息收件人离线时推送通知。原则上,它工作得相当好。一个问题是我将通知推送到的 URL 在模块中是硬编码的。直观地说,这应该可以在ejabberd.ymlconf 文件中进行配置。

我的相关片段ejabberd.yml看起来像这样

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

问题是我无法在我的模块中访问该值,至少不能以我在网上找到的方式:

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]),
  ...

此命令引发以下警告(甚至不是错误):

[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

所以它有点发现/看到了价值。无论如何?INFO_MSG打印和undefined

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

有趣的是,以下效果很好:

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

但是在push_notification我无权访问_Optswhich 反过来又被钩子调用。那么我怎样才能得到post_url方法中的值push_notification呢?

4

1 回答 1

1
gen_mod:get_module_opt(global,?MODULE,post_url,fun(X) -> X end, all)
于 2017-01-27T09:01:02.750 回答