Ejabberd-使用mod_offline_push推送通知APNS和GCM [英] Ejabberd- Push notifications APNS and GCM with mod_offline_push

查看:84
本文介绍了Ejabberd-使用mod_offline_push推送通知APNS和GCM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取与ejabberd一起使用的推送通知,我在这里找到此链接: https:// github .com / diamondbybold / ejabberd_mod_offline_post ,它应该在URL上发出POST请求以获取脱机消息。我编辑了ejabberd.yml文件以包含URL和令牌,但是,尝试在Ejabberd 16.12上运行该文件时遇到了一些问题。
运行,但是我向离线用户发送消息,我在/var/log/ejabberd/error.log中看到以下错误

I'm trying to get push notifications working with ejabberd and I found this link here: https://github.com/diamondbybold/ejabberd_mod_offline_post where it should make a POST request at a URL for offline messages. I edited my ejabberd.yml file to include the URL and token, however, I'm running into some issues when trying to run it on Ejabberd 16.12. It runs, but I send a message to someone offline, I'm seeing the following error in /var/log/ejabberd/error.log

2017-02-07 09:12:19.359 [error] <0.1045.0>@ejabberd_hooks:run1:332 
{function_clause,[{fxml,get_tag_attr_s,[<<"type">>,{message,
<<"purple130d74a2">>,chat,<<>>,undefined,{jid,<<"test2">>,<<"localhost">>,
<<"Smack">>,<<"test2">>,<<"localhost">>,<<"Smack">>},[],[{text,<<>>,
<<"abc">>}],undefined,[{xmlel,<<"active">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/chatstates">>}],[]}],#{}}],[{file,"src/fxml.erl"},
{line,166}]},{mod_offline_post,offline_message,3,
[{file,"src/mod_offline_post.erl"},{line,86}]},{ejabberd_hooks,safe_apply,3,
[{file,"src/ejabberd_hooks.erl"},{line,382}]},{ejabberd_hooks,run1,3,
[{file,"src/ejabberd_hooks.erl"},{line,329}]},{ejabberd_sm,route,3,
[{file,"src/ejabberd_sm.erl"},{line,126}]},{ejabberd_local,route,3,
[{file,"src/ejabberd_local.erl"},{line,110}]},{ejabberd_router,route,3,
[{file,"src/ejabberd_router.erl"},{line,78}]},{ejabberd_c2s,check_privacy_route,5,
[{file,"src/ejabberd_c2s.erl"},{line,1886}]}]}

在mod_offline_post.erl内部,我具有以下功能:

Inside of mod_offline_post.erl, I have this function:

offline_message(From, To, Packet) ->
Type = fxml:get_tag_attr_s(<<"type">>, Packet),
Body = fxml:get_path_s(Packet, [{elem, list_to_binary("body")}, cdata]),
Token = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, auth_token, fun(S) -> iolist_to_binary(S) end, list_to_binary("")),
PostUrl = gen_mod:get_module_opt(To#jid.lserver, ?MODULE, post_url, fun(S) -> iolist_to_binary(S) end, list_to_binary("")),

if
    (Type == <<"chat">>) and (Body /= <<"">>) ->
        Sep = "&",
        Post = [
            "type=chat", Sep,
            "to=", To#jid.luser, Sep,
            "from=", From#jid.luser, Sep,
            "body=", binary_to_list(Body), Sep,
            "access_token=", Token
        ],
        ?INFO_MSG("Sending post request to ~s with body \"~s\"", [PostUrl, Post]),
        httpc:request(post, {binary_to_list(PostUrl), [], "application/x-www-form-urlencoded", list_to_binary(Post)},[],[]),
        ok;
    true ->
        ok
end.

似乎人们可以通过在更高版本中将xml更改为fxml来解决他们的问题,但是

It seemed like people were able to solve their issues by changing xml to fxml in later version, but it didn't look like it made a difference in my case.

如果有人对如何解决此问题有任何想法,或者对实现推送通知的其他方式有任何建议, 请告诉我。谢谢

If anyone has an idea on how I can solve this or any suggestions for a different way of achieving push notifications, please let me know. Thanks

推荐答案

从16.12开始,数据包现在是 #message {} 记录,因此您应该使用xmpp库来处理它。

Since 16.12, Packet is now a #message{} record, so you should use xmpp library to work with it.

这是重写代码的方法:

Here is how you should rewrite your code:

...
-include("xmpp.hrl").
...
offline_message(From, To, #message{type = Type, body = Body}) ->
    BodyTxt = xmpp:get_text(Body),
    ...
    if (Type == chat) and (BodyTxt /= <<"">>) ->
    ...

咨询 xmpp.erl xmpp_codec.hrl 了解详情。

这篇关于Ejabberd-使用mod_offline_push推送通知APNS和GCM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆