Amarula.Protocol.Messages.MessageContent (amarula v0.1.0)

View Source

Classify a decrypted %Proto.Message{} into a tagged tuple so consumers don't have to pattern-match the (large) proto. The inverse of the builders in MessageEncoder.

classify/1 returns one of:

  • {:text, body}
  • {:reaction, target_key, emoji} — emoji "" means the reaction was removed
  • {:edit, target_key, new_text}
  • {:revoke, target_key}
  • {:media, type, message_struct} — type in :image/:video/:audio/:document/:sticker
  • {:protocol, type, protocol_message} — other protocolMessages (history sync, keys, …)
  • {:sender_key, skdm} — Signal group-session-key plumbing (filtered before emit)
  • {:other, message} — anything not yet classified

WhatsApp may wrap the real content in deviceSentMessage (our own other devices) or ephemeralMessage; those are unwrapped first.

Summary

Functions

Classify a decrypted message into a tagged tuple.

Extract the %Proto.ContextInfo{} from a message, or nil. It lives on whichever content sub-message is present (extendedText/image/video/…); we unwrap envelopes first and return the first sub-message's contextInfo. Carries the reply reference (stanzaId/participant/quotedMessage) and mentionedJid.

Functions

classify(message)

@spec classify(Amarula.Protocol.Proto.Message.t()) :: tuple()

Classify a decrypted message into a tagged tuple.

Examples

iex> alias Amarula.Protocol.Proto
iex> Amarula.Protocol.Messages.MessageContent.classify(%Proto.Message{conversation: "hi"})
{:text, "hi"}

iex> alias Amarula.Protocol.Proto
iex> key = %Proto.MessageKey{remoteJid: "x@s.whatsapp.net", id: "ABC"}
iex> msg = %Proto.Message{reactionMessage: %Proto.Message.ReactionMessage{key: key, text: "👍"}}
iex> Amarula.Protocol.Messages.MessageContent.classify(msg)
{:reaction, key, "👍"}

context_info(message)

@spec context_info(Amarula.Protocol.Proto.Message.t()) ::
  Amarula.Protocol.Proto.ContextInfo.t() | nil

Extract the %Proto.ContextInfo{} from a message, or nil. It lives on whichever content sub-message is present (extendedText/image/video/…); we unwrap envelopes first and return the first sub-message's contextInfo. Carries the reply reference (stanzaId/participant/quotedMessage) and mentionedJid.