BaileysEx.Media.Retry (baileys_ex v0.1.0-alpha.8)

Copy Markdown View Source

Media re-upload request helpers modeled after Baileys' media retry flow.

Summary

Types

Opaque WAProto WebMessageInfo struct used by media retry helpers.

Functions

Apply a media-update event to a media message after decrypting the retry data.

Extract the media-bearing content from a Message, mirroring Baileys' assertMediaContent.

Build the Baileys-style server-error receipt requesting media re-upload.

Decode a mediaretry notification node into a parity-shaped event payload.

Decrypt the encrypted media-update payload returned by the paired device.

Send a media re-upload request for the given message key.

Map a media retry result to the HTTP-style status Baileys uses.

Composed helper that performs the full media re-upload round trip.

Types

media_update_event()

@type media_update_event() :: %{
  :key => %{
    id: String.t() | nil,
    remote_jid: String.t() | nil,
    from_me: boolean(),
    participant: String.t() | nil
  },
  optional(:media) => %{ciphertext: binary(), iv: binary()},
  optional(:error) => map()
}

message_key()

@type message_key() :: %{
  :id => String.t(),
  :remote_jid => String.t(),
  optional(:from_me) => boolean(),
  optional(:participant) => String.t() | nil
}

web_message_info()

@type web_message_info() :: struct()

Opaque WAProto WebMessageInfo struct used by media retry helpers.

Functions

apply_media_update(message, media_key, arg3)

@spec apply_media_update(wa_message(), binary(), media_update_event()) ::
  {:ok, wa_message()} | {:error, term()}

Apply a media-update event to a media message after decrypting the retry data.

assert_media_content(msg)

@spec assert_media_content(wa_message() | nil) ::
  {:ok, struct()} | {:error, :not_a_media_message}

Extract the media-bearing content from a Message, mirroring Baileys' assertMediaContent.

Returns {:ok, media_content} or {:error, :not_a_media_message}.

build_retry_request(key, media_key, me_id, opts \\ [])

@spec build_retry_request(message_key(), binary(), String.t(), keyword()) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Build the Baileys-style server-error receipt requesting media re-upload.

decode_notification_event(node)

@spec decode_notification_event(BaileysEx.BinaryNode.t()) :: media_update_event()

Decode a mediaretry notification node into a parity-shaped event payload.

decrypt_media_update(map, media_key, msg_id)

@spec decrypt_media_update(
  %{ciphertext: binary(), iv: binary()},
  binary(),
  String.t()
) ::
  {:ok, decrypted_media_update()} | {:error, term()}

Decrypt the encrypted media-update payload returned by the paired device.

request_reupload(socket, key, media_key, opts \\ [])

@spec request_reupload(
  GenServer.server() | term(),
  message_key(),
  binary(),
  keyword()
) ::
  :ok | {:error, term()}

Send a media re-upload request for the given message key.

status_code_for_result(result)

@spec status_code_for_result(atom() | integer()) :: pos_integer() | nil

Map a media retry result to the HTTP-style status Baileys uses.

update_media_message(socket, event_emitter, wa_message, opts \\ [])

@spec update_media_message(
  GenServer.server() | term(),
  GenServer.server(),
  web_message_info(),
  keyword()
) :: {:ok, web_message_info()} | {:error, term()}

Composed helper that performs the full media re-upload round trip.

Mirrors Baileys' updateMediaMessage: sends the retry request, subscribes to :messages_media_update events, waits for the matching message ID, decrypts the retry payload, and applies the refreshed directPath/url to the message.

Returns {:ok, updated_web_message_info} or {:error, reason}.

Options

  • :timeout — milliseconds to wait for the media update event (default 10000)
  • :me_id — the caller's JID (required)
  • :send_fun — override the node send function (default Socket.send_node/2)
  • :iv — deterministic IV for testing