编译.erl文件以构建自定义ejabberd模块

时间:2018-10-24 13:24:10

标签: erlang ejabberd erl ejabberd-module ejabberd-hooks

我已将 ejabbered-18.09 安装在 mac (MacintoshHD⁩▸eApplicationsber)上的Applications目录下,并且运行良好。我创建了新的 mod_http_offline.erl ,这是一个定制ejabberd模块,用于调用外部api。

我了解的是,我需要编译以上文件才能生成.beam文件,以便与ejabberd一起运行。

如何编译该文件并生成.beam文件?

我尝试了一些以erlc开头的命令,但没有用,我看不到任何错误,也没有输出。 erlc的确切命令是什么?每个参数是什么意思?

我使用brew install安装了erlang。 这是.erl文件

    %% name of module must match file name
-module(mod_http_offline).

-behaviour(gen_mod).

-export([start/2, stop/1, create_message/3]).

-include("ejabberd.hrl").
-include("jlib.hrl").
-include("logger.hrl").

start(_Host, _Opt) ->
    ?INFO_MSG("mod_http_offline loading", []),
    inets:start(),
    ?INFO_MSG("HTTP client started", []),
    ejabberd_hooks:add(offline_message_hook, _Host, ?MODULE, create_message, 50).  

stop (_Host) ->
    ?INFO_MSG("stopping mod_http_offline", []),
    ejabberd_hooks:delete(offline_message_hook, _Host, ?MODULE, create_message, 50).

create_message(_From, _To, Packet) ->

    %% read config options
    MessageId = xml:get_tag_attr_s(list_to_binary("id"), Packet),
    Type = xml:get_tag_attr_s(list_to_binary("type"), Packet),
    FromS = _From#jid.luser,
    ToS = _To#jid.luser,
    Body = xml: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 /= <<"">>) ->
        post_offline_message(FromS, ToS, Body, SubType, MessageId,Token,PostUrl)
    end.

post_offline_message(From, To, Body, SubType, MessageId,Token,PostUrl) ->
    ?INFO_MSG("Posting From ~p To ~p Body ~p SubType ~p ID ~p~n",[From, To, Body, SubType, MessageId]),
    Sep = "&",
    Post = [
        "from=", From, Sep,
        "to=", To, Sep,
        "body=", binary_to_list(Body), Sep,
        "message_id=", binary_to_list(MessageId), Sep,
        "access_token=",Token
    ],
    httpc:request(post, {binary_to_list(PostUrl), [], "application/x-www-form-urlencoded", list_to_binary(Post)},[],[]),
    ?INFO_MSG("post request sent", []).

0 个答案:

没有答案