ExWapp.Media.Retry (ExWapp v0.1.2)

Copy Markdown View Source

Implements WhatsApp's media re-upload protocol.

When a CDN object is no longer available, a companion sends a <receipt type="server-error"> containing an authenticated ServerErrorReceipt. The phone answers with a mediaretry notification carrying a fresh direct path encrypted with the same key.

Summary

Functions

Builds a media re-upload request addressed to the local primary identity.

Decrypts a mediaretry notification.

Derives the AES-256-GCM key used by media-retry payloads.

Types

result()

@type result() ::
  :general_error | :success | :not_found | :decryption_error | non_neg_integer()

Functions

build_receipt(msg_id, own_jid, chat_jid, from_me, participant_jid, media_key)

@spec build_receipt(
  String.t(),
  String.t(),
  String.t(),
  boolean(),
  String.t() | nil,
  binary()
) :: ExWapp.Binary.Node.t()

Builds a media re-upload request addressed to the local primary identity.

participant_jid is required only when the original message belongs to a group. The encrypted protobuf is authenticated with the message ID as AAD.

decode_notification(node, media_key)

@spec decode_notification(ExWapp.Binary.Node.t(), binary()) ::
  {:ok, String.t()} | {:error, term()}

Decrypts a mediaretry notification.

A successful result returns the refreshed direct path. Error code 2 is the wire-level indication that the phone no longer has the media.

retry_key(media_key)

@spec retry_key(binary()) :: binary()

Derives the AES-256-GCM key used by media-retry payloads.