Erlang how to correctly update module syntax
<p>I'm trying to use an Erlang module for my Android chat application but i'm not sure about the correct syntax, because this module was created years ago and something's changed on Erlang. I'don't know Erlang very well so i've made a first adaptation but there is something strange with a Case expression, seems that a string is not correctly matched.</p>

<p>The original module is the <a href="https://github.com/johanvorster/ejabberd_confirm_delivery/blob/master/mod_confirm_delivery.erl" rel="nofollow noreferrer">mod_confirm_delivery</a> , here below</p>

<pre><code>%% name of module must match file name
-module(mod_confirm_delivery).

-author("Johan Vorster").

%% Every ejabberd module implements the gen_mod behavior
%% The gen_mod behavior requires two functions: start/2 and stop/1
-behaviour(gen_mod).

%% public methods for this module
-export([start/2, stop/1, send_packet/3, receive_packet/4, get_session/5, set_offline_message/5]).

%% included for writing to ejabberd log file
-include("ejabberd.hrl").
-include("logger.hrl").

-record(session, {sid, usr, us, priority, info}).
-record(offline_msg, {us, timestamp, expire, from, to, packet}).
-record(confirm_delivery, {messageid, timerref}).

start(_Host, _Opt) -&gt; 

        ?INFO_MSG("mod_confirm_delivery loading", []),
        mnesia:create_table(confirm_delivery, 
            [{attributes, record_info(fields, confirm_delivery)}]),
        mnesia:clear_table(confirm_delivery),
        ?INFO_MSG("created timer ref table", []),

        ?INFO_MSG("start user_send_packet hook", []),
        ejabberd_hooks:add(user_send_packet, _Host, ?MODULE, send_packet, 50),   
        ?INFO_MSG("start user_receive_packet hook", []),
        ejabberd_hooks:add(user_receive_packet, _Host, ?MODULE, receive_packet, 50).   

stop(_Host) -&gt; 
        ?INFO_MSG("stopping mod_confirm_delivery", []),
        ejabberd_hooks:delete(user_send_packet, _Host, ?MODULE, send_packet, 50),
        ejabberd_hooks:delete(user_receive_packet, _Host, ?MODULE, receive_packet, 50). 

send_packet(From, To, Packet) -&gt;    
    ?INFO_MSG("send_packet FromJID ~p ToJID ~p Packet ~p~n",[From, To, Packet]),

    Type = xml:get_tag_attr_s("type", Packet),
    ?INFO_MSG("Message Type ~p~n",[Type]),

    Body = xml:get_path_s(Packet, [{elem, "body"}, cdata]), 
    ?INFO_MSG("Message Body ~p~n",[Body]),

    MessageId = xml:get_tag_attr_s("id", Packet),
    ?INFO_MSG("send_packet MessageId ~p~n",[MessageId]), 

    LUser = element(2, To),
    ?INFO_MSG("send_packet LUser ~p~n",[LUser]), 

    LServer = element(3, To), 
    ?INFO_MSG("send_packet LServer ~p~n",[LServer]), 

    Sessions = mnesia:dirty_index_read(session, {LUser, LServer}, #session.us),
    ?INFO_MSG("Session: ~p~n",[Sessions]),

    case Type =:= "chat" andalso Body =/= [] andalso Sessions =/= [] of
        true -&gt;                

        {ok, Ref} = timer:apply_after(10000, mod_confirm_delivery, get_session, [LUser, LServer, From, To, Packet]),

        ?INFO_MSG("Saving To ~p Ref ~p~n",[MessageId, Ref]),

        F = fun() -&gt;
            mnesia:write(#confirm_delivery{messageid=MessageId, timerref=Ref})
        end,

        mnesia:transaction(F);

    _ -&gt;
        ok
    end.   

receive_packet(_JID, From, To, Packet) -&gt;
    ?INFO_MSG("receive_packet JID: ~p From: ~p To: ~p Packet: ~p~n",[_JID, From, To, Packet]), 

    Received = xml:get_subtag(Packet, "received"), 
    ?INFO_MSG("receive_packet Received Tag ~p~n",[Received]),    

    if Received =/= false andalso Received =/= [] -&gt;
        MessageId = xml:get_tag_attr_s("id", Received),
        ?INFO_MSG("receive_packet MessageId ~p~n",[MessageId]);       
    true -&gt;
        MessageId = []
    end, 

    if MessageId =/= [] -&gt;
        Record = mnesia:dirty_read(confirm_delivery, MessageId),
        ?INFO_MSG("receive_packet Record: ~p~n",[Record]);       
    true -&gt;
        Record = []
    end, 

    if Record =/= [] -&gt;
        [R] = Record,
        ?INFO_MSG("receive_packet Record Elements ~p~n",[R]), 

        Ref = element(3, R),

        ?INFO_MSG("receive_packet Cancel Timer ~p~n",[Ref]), 
        timer:cancel(Ref),

        mnesia:dirty_delete(confirm_delivery, MessageId),
        ?INFO_MSG("confirm_delivery clean up",[]);     
    true -&gt;
        ok
    end.


get_session(User, Server, From, To, Packet) -&gt;   
    ?INFO_MSG("get_session User: ~p Server: ~p From: ~p To ~p Packet ~p~n",[User, Server, From, To, Packet]),   

    ejabberd_router:route(From, To, Packet),
    ?INFO_MSG("Resend message",[]),

    set_offline_message(User, Server, From, To, Packet),
    ?INFO_MSG("Set offline message",[]),

    MessageId = xml:get_tag_attr_s("id", Packet), 
    ?INFO_MSG("get_session MessageId ~p~n",[MessageId]),    

    case MessageId =/= [] of
        true -&gt;        

        mnesia:dirty_delete(confirm_delivery, MessageId),
        ?INFO_MSG("confirm_delivery clean up",[]);

     _ -&gt;
        ok
    end.

set_offline_message(User, Server, From, To, Packet) -&gt;
    ?INFO_MSG("set_offline_message User: ~p Server: ~p From: ~p To ~p Packet ~p~n",[User, Server, From, To, Packet]),    

    F = fun() -&gt;
        mnesia:write(#offline_msg{us = {User, Server}, timestamp = now(), expire = "never", from = From, to = To, packet = Packet})
    end,

mnesia:transaction(F). 
</code></pre>

<p>And here there is the module with my changes, the Case is the one in the send_packet method. </p>

<pre><code>Type = xml:get_tag_attr_s("type", Packet),
</code></pre>

<p>The line above return &lt;&lt;"chat">> as Type but i don't think is matched with case Type =:= "chat", also the other tag_attr are included inside &lt;&lt;"">>  </p>

<pre><code>%% name of module must match file name
-module(mod_confirm_delivery).

-author("Johan Vorster").

%% Every ejabberd module implements the gen_mod behavior
%% The gen_mod behavior requires two functions: start/2 and stop/1
-behaviour(gen_mod).

%% public methods for this module
-export([start/2, stop/1, send_packet/4, receive_packet/5, get_session/5, set_offline_message/5]).

%% included for writing to ejabberd log file
-include("ejabberd.hrl").
-include("logger.hrl").

-record(session, {sid, usr, us, priority, info}).
-record(offline_msg, {us, timestamp, expire, from, to, packet}).
-record(confirm_delivery, {messageid, timerref}).

start(_Host, _Opt) -&gt; 

        ?DEBUG("mod_confirm_delivery loading", []),
        mnesia:create_table(confirm_delivery, 
            [{attributes, record_info(fields, confirm_delivery)}]),
        mnesia:clear_table(confirm_delivery),
        ?DEBUG("created timer ref table", []),

        ?DEBUG("start user_send_packet hook", []),
        ejabberd_hooks:add(user_send_packet, _Host, ?MODULE, send_packet, 50),   
        ?DEBUG("start user_receive_packet hook", []),
        ejabberd_hooks:add(user_receive_packet, _Host, ?MODULE, receive_packet, 50).   

stop(_Host) -&gt; 
        ?DEBUG("stopping mod_confirm_delivery", []),
        ejabberd_hooks:delete(user_send_packet, _Host, ?MODULE, send_packet, 50),
        ejabberd_hooks:delete(user_receive_packet, _Host, ?MODULE, receive_packet, 50). 

%%send_packet(From, To, Packet) -&gt;
send_packet(Packet, C2SState, From, To) -&gt;  
   %% ?INFO_MSG("send_packet FromJID ~p ToJID ~p Packet ~p~n",[From, To, Packet]),
    ?DEBUG("send_packet Packet ~p C2SState ~p FromJID ~p ToJID ~p~n",[Packet, C2SState, From, To]),   

    Type = fxml:get_tag_attr_s(&lt;&lt;"type"&gt;&gt;, Packet),
    ?DEBUG("Message Type ~p~n",[Type]),

    Body = fxml:get_path_s(Packet, [{elem, &lt;&lt;"body"&gt;&gt;}, cdata]), 
    ?DEBUG("Message Body ~p~n",[Body]),

    MessageId = fxml:get_tag_attr_s(&lt;&lt;"id"&gt;&gt;, Packet),
    ?DEBUG("send_packet MessageId ~p~n",[MessageId]), 

    LUser = element(2, To),
    ?DEBUG("send_packet LUser ~p~n",[LUser]), 

    LServer = element(3, To), 
    ?DEBUG("send_packet LServer ~p~n",[LServer]), 

    Sessions = mnesia:dirty_index_read(session, {LUser, LServer}, #session.us),
    ?DEBUG("Session: ~p~n",[Sessions]),

    case Type =:= "chat" andalso Body =/= [] andalso Sessions =/= [] of
        true -&gt;                

        {ok, Ref} = timer:apply_after(10000, mod_confirm_delivery, get_session, [LUser, LServer, From, To, Packet]),

        ?DEBUG("Saving To ~p Ref ~p~n",[MessageId, Ref]),

        F = fun() -&gt;
            mnesia:write(#confirm_delivery{messageid=MessageId, timerref=Ref})
        end,

        mnesia:transaction(F);

    _ -&gt;
        Packet
    end.   

receive_packet(Packet, C2SState, _JID, From, To) -&gt;
    ?DEBUG("receive_packet JID: ~p From: ~p To: ~p Packet: ~p~n",[_JID, From, To, Packet]), 

    Received = fxml:get_subtag(Packet, &lt;&lt;"received"&gt;&gt;), 
    ?DEBUG("receive_packet Received Tag ~p~n",[Received]),    

    if Received =/= false andalso Received =/= [] -&gt;
        MessageId = fxml:get_tag_attr_s(&lt;&lt;"id"&gt;&gt;, Received),
        ?DEBUG("receive_packet MessageId ~p~n",[MessageId]);       
    true -&gt;
        MessageId = []
    end, 

    if MessageId =/= [] -&gt;
        Record = mnesia:dirty_read(confirm_delivery, MessageId),
        ?DEBUG("receive_packet Record: ~p~n",[Record]);       
    true -&gt;
        Record = []
    end, 

    if Record =/= [] -&gt;
        [R] = Record,
        ?DEBUG("receive_packet Record Elements ~p~n",[R]), 

        Ref = element(3, R),

        ?DEBUG("receive_packet Cancel Timer ~p~n",[Ref]), 
        timer:cancel(Ref),

        mnesia:dirty_delete(confirm_delivery, MessageId),
        ?DEBUG("confirm_delivery clean up",[]);     
    true -&gt;
        Packet
    end.


get_session(User, Server, From, To, Packet) -&gt;   
    ?DEBUG("get_session User: ~p Server: ~p From: ~p To ~p Packet ~p~n",[User, Server, From, To, Packet]),   

    ejabberd_router:route(From, To, Packet),
    ?DEBUG("Resend message",[]),

    set_offline_message(User, Server, From, To, Packet),
    ?DEBUG("Set offline message",[]),

    MessageId = fxml:get_tag_attr_s(&lt;&lt;"id"&gt;&gt;, Packet), 
    ?DEBUG("get_session MessageId ~p~n",[MessageId]),    

    case MessageId =/= [] of
        true -&gt;        

        mnesia:dirty_delete(confirm_delivery, MessageId),
        ?DEBUG("confirm_delivery clean up",[]);

     _ -&gt;
        ok
    end.

set_offline_message(User, Server, From, To, Packet) -&gt;
    ?DEBUG("set_offline_message User: ~p Server: ~p From: ~p To ~p Packet ~p~n",[User, Server, From, To, Packet]),    

    F = fun() -&gt;
        mnesia:write(#offline_msg{us = {User, Server}, timestamp = now(), expire = "never", from = From, to = To, packet = Packet})
    end,

    mnesia:transaction(F).   
</code></pre>

<p>The module compilation is ok and also the start. </p>