在ejabberd 20.07版本中安装和配置mod_offline_post



我在20.07版本中安装并使用了mod_offline_http_post模块,能够为单个用户获取推送通知。但是这个模块不支持MUC房间。我想为订阅了MUC房间并且目前处于离线状态的用户获得推送通知。我发现mod_offline_post模块可以做到这一点。但我无法配置[mod_offline_post]与ejabberd 20.07版本。对于编译和安装,我遵循了以下说明https://docs.ejabberd.im/developer/extending-ejabberd/modules/.

完成此操作后,当我尝试在ejabberd.yml中配置mod_offline_post时,它会给我一个错误mod_offline_post不是ejabberd模块。

好吧,该模块已有两年的历史,并且不符合ejabberd模块API的最新要求,所以它不是ejabber模块。

我已经更新了它的源代码,以便使用最新的ejabberd进行正确编译。我还没有检查它是否真的有效。

这些步骤允许下载、修复和安装模块:

mkdir -p $HOME/.ejabberd-modules/sources/
cd $HOME/.ejabberd-modules/sources/
git clone https://github.com/k9428/mod_offline_post.git
cd mod_offline_post

然后在这里放一个名为update.patch的文件,其中包含以下内容:

From bb7355f5abf558365e68b91e996b303beeb7576e Mon Sep 17 00:00:00 2001
From: Badlop <badlop@process-one.net>
Date: Mon, 5 Oct 2020 18:07:29 +0200
Subject: [PATCH] Update to compile with recent ejabberd
---
src/mod_offline_post.erl | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/src/mod_offline_post.erl b/src/mod_offline_post.erl
index a5e6af8..dccf419 100644
--- a/src/mod_offline_post.erl
+++ b/src/mod_offline_post.erl
@@ -8,11 +8,34 @@
send_notice/1,
getbody/1]).

+-export([mod_options/1, depends/2, mod_opt_type/1, mod_doc/0]).
+
-define(PROCNAME, ?MODULE).

-include("xmpp.hrl").
+-include("translate.hrl").
-include("logger.hrl").

+depends(_Host, _Opts) ->
+    [].
+
+mod_opt_type(post_url) ->
+    econf:binary();
+mod_opt_type(app_id) ->
+    econf:binary();
+mod_opt_type(api_key) ->
+    econf:binary().
+
+mod_options(_Host) ->
+    [{post_url, <<"">>},
+     {app_id, <<"">>},
+     {api_key, <<"">>}
+    ].
+
+mod_doc() ->
+    #{desc =>
+          ?T("This module is for offline post.")}.
+
start(Host, Opts) ->
?INFO_MSG("Starting mod_offline_post", [] ),
register(?PROCNAME,spawn(?MODULE, init, [Host, Opts])),  
@@ -50,11 +73,11 @@ send_notice({Action,Packet}) ->
% ToId = binary_to_list(fxml:get_tag_attr_s(list_to_binary("toId"), CustomData)),
% IsPhoto = binary_to_list(fxml:get_tag_attr_s(list_to_binary("isPhoto"), CustomData)),

-   PostUrl = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, post_url,fun(S) -> iolist_to_binary(S) end, list_to_binary("")),
+   PostUrl = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, post_url),

%% Configure your own options passed to module
-   AppId = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, app_id, fun(S) -> iolist_to_binary(S) end, list_to_binary("")),
-   ApiKey = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, api_key, fun(S) -> iolist_to_binary(S) end, list_to_binary("")),
+   AppId = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, app_id),
+   ApiKey = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, api_key),

Data = string:join(["to=", ToUsername, "&from=", FromUsername, "&type=", Type, "&body=", FinalBody], ""),
Request = {binary_to_list(PostUrl), [{"X-Parse-Application-Id", binary_to_list(AppId)}, {"X-Parse-REST-API-Key", binary_to_list(ApiKey)}], "application/x-www-form-urlencoded", Data},
-- 
2.20.1

最后,应用补丁,安装模块:

git am -3 update.patch
S'està aplicant: Update to compile with recent ejabberd
ejabberdctl modules_available
mod_offline_post        Forwards messages that are sent to offline users through a post request to a configurable url
ejabberdctl module_install mod_offline_post
/home/badlop/.ejabberd-modules/sources/mod_offline_post/src/mod_offline_post.erl:33: Warning: variable 'Action' is unused
/home/badlop/.ejabberd-modules/sources/mod_offline_post/src/mod_offline_post.erl:45: Warning: variable 'El' is unused

相关内容

  • 没有找到相关文章

最新更新