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

Copy Markdown View Source

Retry-state helpers modeled after Baileys' message retry manager.

Summary

Functions

Caches recently sent plaintext messages allowing retry requests to resend them.

Cancels a previously scheduled fallback request.

Clears an expired placeholder timeout.

Looks up a placeholder that actively blocking resolution of a message.

Retrieves a cached sent message for a remote peer and message ID.

Yields the current retry iteration count.

Parses an incoming retry receipt and retrieves cached messages for re-encryption.

Checks if a message retry sequence has violated the configured limit loop.

Bumps the volatile retry tally for a specific message tracking iteration count.

Indicates whether the parsed retry code suggests a fatal MAC/Signature error.

Parses stringified error codes from WhatsApp XML nodes.

Records an active placeholder awaiting server response.

Idempotently queues a placeholder resend command, stalling slightly to await in-flight messages.

Clears a resolved placeholder from state.

Executes a scheduled fallback phone request, immediately invoking the callback.

Schedules an asynchronous fallback request for a retry sequence.

Constructs and formats a protocol retry receipt to request a sender re-encrypt a failed message.

Determines if a recipient's Signal session must be recreated based on an error code.

Types

proto_message()

@type proto_message() :: struct()

recent_message_entry()

@type recent_message_entry() :: %{message: proto_message(), timestamp: integer()}

Functions

add_recent_message(store_ref, to, id, message, opts \\ [])

@spec add_recent_message(
  BaileysEx.Connection.Store.Ref.t(),
  String.t(),
  String.t(),
  proto_message(),
  keyword()
) :: :ok

Caches recently sent plaintext messages allowing retry requests to resend them.

cancel_phone_request(store_ref, message_id)

@spec cancel_phone_request(BaileysEx.Connection.Store.Ref.t(), String.t()) :: :ok

Cancels a previously scheduled fallback request.

expire_placeholder_resend(store_ref, message_id)

@spec expire_placeholder_resend(BaileysEx.Connection.Store.Ref.t(), String.t()) :: :ok

Clears an expired placeholder timeout.

get_placeholder_resend(store_ref, message_id)

@spec get_placeholder_resend(BaileysEx.Connection.Store.Ref.t(), String.t()) ::
  map() | boolean() | nil

Looks up a placeholder that actively blocking resolution of a message.

get_recent_message(store_ref, to, id, opts \\ [])

@spec get_recent_message(
  BaileysEx.Connection.Store.Ref.t(),
  String.t(),
  String.t(),
  keyword()
) ::
  recent_message_entry() | nil

Retrieves a cached sent message for a remote peer and message ID.

get_retry_count(store_ref, message_id)

@spec get_retry_count(BaileysEx.Connection.Store.Ref.t(), String.t()) ::
  non_neg_integer()

Yields the current retry iteration count.

handle_retry_receipt(store_ref, node, opts \\ [])

@spec handle_retry_receipt(
  BaileysEx.Connection.Store.Ref.t(),
  BaileysEx.BinaryNode.t(),
  keyword()
) ::
  {:ok, [map()]} | {:error, term()}

Parses an incoming retry receipt and retrieves cached messages for re-encryption.

has_exceeded_max_retries?(store_ref, message_id, max_retry_count \\ 5)

@spec has_exceeded_max_retries?(
  BaileysEx.Connection.Store.Ref.t(),
  String.t(),
  pos_integer()
) ::
  boolean()

Checks if a message retry sequence has violated the configured limit loop.

increment_retry_count(store_ref, message_id)

@spec increment_retry_count(BaileysEx.Connection.Store.Ref.t(), String.t()) ::
  pos_integer()

Bumps the volatile retry tally for a specific message tracking iteration count.

mac_error?(reason)

@spec mac_error?(atom() | integer() | nil) :: boolean()

Indicates whether the parsed retry code suggests a fatal MAC/Signature error.

parse_retry_error_code(value)

@spec parse_retry_error_code(String.t() | nil) :: atom() | nil

Parses stringified error codes from WhatsApp XML nodes.

put_placeholder_resend(store_ref, message_id, data, opts \\ [])

@spec put_placeholder_resend(
  BaileysEx.Connection.Store.Ref.t(),
  String.t(),
  map() | boolean(),
  keyword()
) :: :ok

Records an active placeholder awaiting server response.

request_placeholder_resend(store_ref, message_key, msg_data \\ nil, opts \\ [])

@spec request_placeholder_resend(
  BaileysEx.Connection.Store.Ref.t(),
  map(),
  map() | boolean() | nil,
  keyword()
) :: {:ok, String.t() | nil} | {:error, term()}

Idempotently queues a placeholder resend command, stalling slightly to await in-flight messages.

resolve_placeholder_resend(store_ref, message_id)

@spec resolve_placeholder_resend(BaileysEx.Connection.Store.Ref.t(), String.t()) ::
  :ok

Clears a resolved placeholder from state.

run_phone_request(store_ref, message_id, callback)

@spec run_phone_request(BaileysEx.Connection.Store.Ref.t(), String.t(), (-> term())) ::
  :ok

Executes a scheduled fallback phone request, immediately invoking the callback.

schedule_phone_request(store_ref, message_id, callback, opts \\ [])

@spec schedule_phone_request(
  BaileysEx.Connection.Store.Ref.t(),
  String.t(),
  (-> term()),
  keyword()
) ::
  :ok

Schedules an asynchronous fallback request for a retry sequence.

send_retry_request(store_ref, node, opts \\ [])

@spec send_retry_request(
  BaileysEx.Connection.Store.Ref.t(),
  BaileysEx.BinaryNode.t(),
  keyword()
) ::
  {:ok, BaileysEx.BinaryNode.t()} | {:error, term()}

Constructs and formats a protocol retry receipt to request a sender re-encrypt a failed message.

should_recreate_session(store_ref, jid, has_session, error_code \\ nil, opts \\ [])

@spec should_recreate_session(
  BaileysEx.Connection.Store.Ref.t(),
  String.t(),
  boolean(),
  atom() | integer() | nil,
  keyword()
) :: %{reason: String.t(), recreate: boolean()}

Determines if a recipient's Signal session must be recreated based on an error code.