3
votes

I'm building an ejabberd module to send carbon copies of messages to an external RESTful API. Everything works okay, and requests to that API are sending POST params with Sender, Recipient and the message Body.

I'm triggering the user_send_packet and user_receive_packet hooks for this, and I can extract the params (Sender, Recipient, Body) from the packet:

Sender = xml:get_tag_attr_s("from", Packet),
Recipient = xml:get_tag_attr_s("to", Packet),
Body = xml:get_path_s(Packet, [{elem, "body"}, cdata])

For group chats (MUC) I'd also like to send the MUC roster (participants) in a parameter, but I don't know how to access them.

Is there an event for this? Can anyone point me to some documentation?

Thanks in advance!

1

1 Answers

0
votes

It seems that you want to get MUC participants of specific room.

You need to look at mod_muc.erl and mod_muc_room.erl. I'm not sure which version of ejabberd you use, so I will explain based on latest ejabberd.

After getting pid of room by calling

mnesia:dirty_read(muc_online_room, {Room, Host})

you can call

gen_fsm:sync_send_all_state_event(Pid, {get_disco_item, From, Lang}, 100)

or use similar code. User list is in the reply.

If you don't like reply format, you may want to add custom handle_sync_event to mod_muc_room.erl .