0
votes

I'm having problems while trying to create custom modules for ejabberd.

Using:
ejabberd 19.05.81 (from source)
ubuntu server 18.04

I created the hello_world module following the tutorial from https://docs.ejabberd.im/developer/extending-ejabberd/modules/

I tried putting the source file mod_hello_world.erl inside the src folder and then compiled using make install. Everything goes smoothly, but if I add the module on ejabberd.yml then start the node, I get a crash:

19:59:43.683 [critical] Failed to start ejabberd application: Invalid value of option modules: 'mod_hello_world' is not a ejabberd module

I tried using the folder $HOME/.ejabberd-modules/sources and the command ejabberdctl module_install mod_hello_world, and when checking if it was installed using modules_installed, it is there.

Still, I get the same error, described above.

Does anyone knows what I'm doing wrong?

1

1 Answers

1
votes

I tried putting the source file mod_hello_world.erl inside the src folder and then compiled using make install. Everything goes smoothly, but if I add the module on ejabberd.yml then start the node, I get a crash:

Problem confirmed. Since a recent commit, gen_mod requires the ejabberd modules to export four functions. The documentation page you found with the mod_hello_world source code isn't yet updated, so ejabberd complains that it doesn't recognize the erlang module as an ejabberd module. Thanks for mentioning it!

I've updated the documentation source code, but I guess will not be updated online since the next release. This updated source code works correctly, please try it:

-module(mod_hello_world).

-behaviour(gen_mod).

%% Required by ?INFO_MSG macros
-include("logger.hrl").

%% gen_mod API callbacks
-export([start/2, stop/1, mod_options/1, depends/2]).

start(_Host, _Opts) ->
    ?INFO_MSG("Hello, ejabberd world!", []),
    ok.

stop(_Host) ->
    ?INFO_MSG("Bye bye, ejabberd world!", []),
    ok.

depends(_Host, _Opts) ->
    [].

mod_options(_Host) ->
    [].