Reputation: 21817
I need to get body attribute from input xmpp Packet with Erlang/xmpp.
I receive packet:
Record = #received_packet{packet_type=message,
raw_packet=Packet,
from=From,
type_attr=Type} when Type =/= "error
How can i extract body message from Packet
?
Thank you.
Upvotes: 2
Views: 847
Reputation: 3235
if you are using exmpp you can use module exmpp_message:get_body/1
http://www.process-one.net/docs/exmpp/devdoc/trunk/exmpp_message.html
Upvotes: 1
Reputation: 2651
Not sure if you already went through exmpp examples. Here is a snippet from echo_client.erl example:
%% Send the same packet back for each message received
echo_packet(MySession, Packet) ->
From = exmpp_xml:get_attribute(Packet, <<"from">>, <<"unknown">>),
To = exmpp_xml:get_attribute(Packet, <<"to">>, <<"unknown">>),
TmpPacket = exmpp_xml:set_attribute(Packet, <<"from">>, To),
TmpPacket2 = exmpp_xml:set_attribute(TmpPacket, <<"to">>, From),
NewPacket = exmpp_xml:remove_attribute(TmpPacket2, <<"id">>),
exmpp_session:send_packet(MySession, NewPacket).
Upvotes: 0