Hi,
I’m trying to implement the XEP-0297 to forward a message.
Smack implements it, but unfortunately I am not able to find any usages example.
Can anyone provide a code snippet on how use it?
Thanks
Hi,
I’m trying to implement the XEP-0297 to forward a message.
Smack implements it, but unfortunately I am not able to find any usages example.
Can anyone provide a code snippet on how use it?
Thanks
After few tries I found how to implement it.
To send a forwarded message:
val fwd = xmppConnection.stanzaFactory
.buildMessageStanza()
.ofType(Message.Type.chat)
.setBody(text) // text to forward
.build()
val ext = Forwarded(fwd)
stanza.addExtension(ext) // stanza is the message to send
To receive it, in your IncomingChatMessageListener
add:
val isForwarded = message.hasExtension(Forwarded::class.java) &&
message.getExtension(Forwarded::class.java).isForwarded(Message::class.java)
val received = if (isForwarded) message.getExtension(Forwarded::class.java).forwardedStanza as Message else message
// do stuff with received
Make sure to trust/authenticate the sender of the message containing a forwarded message, and/or ensure that the forwarded message has the expected from/to attributes. Otherwise you have created an security issue. See also XEP-0280: Message Carbons § 11. Security Considerations.
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.