ejabberd - custom iq handlers

折月煮酒 提交于 2019-12-12 03:29:23

问题


I have created simple module. here is the code

-module(mod_conversations).
-behaviour(gen_mod).
-export([start/2, stop/1, process_local_iq/3]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("jlib.hrl").
-define(IQ_CUSTOM, <<"jabber:iq:conversations">>).
start(Host, _) ->
    gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?IQ_CUSTOM, ?MODULE, process_local_iq, one_queue),
ok.
stop(Host) ->
    gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?IQ_CUSTOM),
ok.
process_local_iq(From,_ ,IQ) ->
IQ#iq{type = result, sub_el = [{xmlelement, <<"value">>, [], [{xmlcdata, <<"Testing...">>}]}]}.

When i make request with strophe.js var iq = $iq({type: 'get', to: 'some host'}).c('query', {xmlns: 'jabber:iq:conversations'}); connection.sendIQ(iq);

server disconnects me.I have tried to find simillar issues but some of them was more problematic. please help me to solve this issue


回答1:


You must not use xmlelement tuples in recent ejabberd versions, the correct code should look like this:

IQ#iq{type = result,
      sub_el = [#xmlel{name = <<"value">>,
                       children = [{xmlcdata, <<"Testing...">>}]}]}.


来源:https://stackoverflow.com/questions/41506560/ejabberd-custom-iq-handlers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!