Erlang exmpp 从数据包中获取主体

发布于 2024-11-08 11:39:33 字数 317 浏览 0 评论 0原文

我需要使用 Erlang/xmpp 从输入 xmpp 数据包中获取 body 属性。

我收到数据包:

 Record = #received_packet{packet_type=message,
                  raw_packet=Packet,
                  from=From,
                  type_attr=Type} when Type =/= "error

如何从数据包中提取正文消息?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗心遗梦遗幸福 2024-11-15 11:39:33

如果您使用的是 exmpp,则可以使用模块 exmpp_message:get_body/1

http ://www.process-one.net/docs/exmpp/devdoc/trunk/exmpp_message.html

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

遗失的美好 2024-11-15 11:39:33

不确定您是否已经浏览过 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).

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).
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文