BaileysEx.Auth.Persistence behaviour (baileys_ex v0.1.0-alpha.7)

Copy Markdown View Source

Persistence behaviour for auth credentials and key-store datasets.

Phase 15 supports two built-in file backends:

Custom backends can implement either the context-free callbacks, the context-aware callbacks, or both. BaileysEx.Auth.KeyStore dispatches to the widest arity the backend exports.

Summary

Types

Helper map returned by the built-in auth-state loaders.

Types

auth_state_helper()

@type auth_state_helper() :: %{
  state: BaileysEx.Auth.State.t(),
  connect_opts: keyword(),
  save_creds: (BaileysEx.Auth.State.t() | map() -> :ok | {:error, term()})
}

Helper map returned by the built-in auth-state loaders.

connect_opts is ready to merge into BaileysEx.connect/2, and save_creds persists the latest auth-state snapshot for the selected backend.

Callbacks

delete_keys(type, id)

@callback delete_keys(type :: atom(), id :: term()) :: :ok | {:error, term()}

delete_keys(context, type, id)

(optional)
@callback delete_keys(context :: term(), type :: atom(), id :: term()) ::
  :ok | {:error, term()}

load_credentials()

@callback load_credentials() :: {:ok, BaileysEx.Auth.State.t()} | {:error, term()}

load_credentials(context)

(optional)
@callback load_credentials(context :: term()) ::
  {:ok, BaileysEx.Auth.State.t()} | {:error, term()}

load_keys(type, id)

@callback load_keys(type :: atom(), id :: term()) :: {:ok, term()} | {:error, term()}

load_keys(context, type, id)

(optional)
@callback load_keys(context :: term(), type :: atom(), id :: term()) ::
  {:ok, term()} | {:error, term()}

save_credentials(t)

@callback save_credentials(BaileysEx.Auth.State.t()) :: :ok | {:error, term()}

save_credentials(context, t)

(optional)
@callback save_credentials(context :: term(), BaileysEx.Auth.State.t()) ::
  :ok | {:error, term()}

save_keys(type, id, data)

@callback save_keys(type :: atom(), id :: term(), data :: term()) ::
  :ok | {:error, term()}

save_keys(context, type, id, data)

(optional)
@callback save_keys(context :: term(), type :: atom(), id :: term(), data :: term()) ::
  :ok | {:error, term()}