我需要从输入xmpp包中使用Erlang / xmpp获取 body 属性。
我收到数据包:
Record = #received_packet{packet_type=message,
raw_packet=Packet,
from=From,
type_attr=Type} when Type =/= "error
如何从Packet
中提取正文消息?
谢谢。
答案 0 :(得分:1)
如果您使用exmpp,可以使用模块exmpp_message:get_body / 1
http://www.process-one.net/docs/exmpp/devdoc/trunk/exmpp_message.html
答案 1 :(得分:0)
不确定您是否已经通过了exmpp示例。以下是echo_client.erl示例的片段:
%% 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).