Jido.Chat.Thread (Jido Chat v1.0.0)

Copy Markdown View Source

Thread handle with posting, lifecycle, state, and discovery helpers.

Summary

Functions

Fetches all available messages by following pagination cursors when supported.

Alias for messages_stream/2 to mirror full-history stream naming.

Returns a channel reference tied to this thread's room.

Returns the logical channel id for this thread.

Edits a previously-sent message via adapter edit_message/4 when supported.

Builds a thread from serialized map data.

Renders a user mention string for this thread's adapter.

Fetches a page of normalized messages for the thread when supported.

Returns a lazy stream over thread messages using cursor pagination.

Creates a thread handle.

Opens a modal in the thread when supported by the adapter.

Posts string/postable/stream content and returns a sent-message handle.

Posts an ephemeral message to a user with optional DM fallback policy.

Fetches a recent message list with default limit 20.

Refreshes thread metadata when adapter supports fetch_thread callback.

Returns the Zoi schema for Thread.

Uploads a file to the thread when supported by the adapter.

Sets thread state in chat struct using :replace, :merge, or key/value modes.

Starts a typing indicator in the thread when supported.

Gets thread state map or a single key from chat struct state.

Subscribes this thread in a pure Jido.Chat state struct.

Returns true when the thread is subscribed in a pure Jido.Chat state struct.

Serializes thread into a plain map with type marker.

Unsubscribes this thread in a pure Jido.Chat state struct.

Types

t()

@type t() :: %Jido.Chat.Thread{
  adapter: any(),
  adapter_name: atom(),
  channel_id: nil | nil | binary(),
  external_room_id: any(),
  external_thread_id: nil | nil | binary(),
  id: binary(),
  is_dm: boolean(),
  metadata: map()
}

Functions

all_messages(thread, opts \\ [])

@spec all_messages(t(), keyword() | map() | Jido.Chat.FetchOptions.t()) ::
  {:ok, [Jido.Chat.Message.t()]} | {:error, term()}

Fetches all available messages by following pagination cursors when supported.

all_messages_stream(thread, opts \\ [])

@spec all_messages_stream(t(), keyword() | map() | Jido.Chat.FetchOptions.t()) ::
  Enumerable.t()

Alias for messages_stream/2 to mirror full-history stream naming.

channel(chat, thread)

@spec channel(Jido.Chat.t(), t()) :: Jido.Chat.ChannelRef.t()

Returns a channel reference tied to this thread's room.

channel_id(thread)

@spec channel_id(t()) :: String.t()

Returns the logical channel id for this thread.

edit(thread, message_id, text, opts \\ [])

Edits a previously-sent message via adapter edit_message/4 when supported.

from_map(map)

@spec from_map(map()) :: t()

Builds a thread from serialized map data.

mention_user(thread, user)

@spec mention_user(t(), String.t() | integer() | Jido.Chat.Author.t() | map()) ::
  String.t()

Renders a user mention string for this thread's adapter.

messages(thread, opts \\ [])

@spec messages(t(), keyword() | map() | Jido.Chat.FetchOptions.t()) ::
  {:ok, Jido.Chat.MessagePage.t()} | {:error, term()}

Fetches a page of normalized messages for the thread when supported.

messages_stream(thread, opts \\ [])

@spec messages_stream(t(), keyword() | map() | Jido.Chat.FetchOptions.t()) ::
  Enumerable.t()

Returns a lazy stream over thread messages using cursor pagination.

new(attrs)

Creates a thread handle.

open_modal(thread, payload, opts \\ [])

@spec open_modal(t(), Jido.Chat.Modal.t() | map(), keyword()) ::
  {:ok, Jido.Chat.ModalResult.t()} | {:error, term()}

Opens a modal in the thread when supported by the adapter.

post(thread, input, opts \\ [])

@spec post(
  t(),
  String.t() | Jido.Chat.Postable.t() | map() | Enumerable.t(),
  keyword()
) ::
  {:ok, Jido.Chat.SentMessage.t()} | {:error, term()}

Posts string/postable/stream content and returns a sent-message handle.

post_ephemeral(thread, user, input, opts \\ [])

@spec post_ephemeral(
  t(),
  String.t() | integer() | Jido.Chat.Author.t() | map(),
  String.t() | Jido.Chat.Postable.t() | map(),
  keyword()
) :: {:ok, Jido.Chat.EphemeralMessage.t()} | {:error, term()}

Posts an ephemeral message to a user with optional DM fallback policy.

recent_messages(thread, opts \\ [])

@spec recent_messages(
  t(),
  keyword()
) :: {:ok, [Jido.Chat.Message.t()]} | {:error, term()}

Fetches a recent message list with default limit 20.

refresh(thread, opts \\ [])

@spec refresh(
  t(),
  keyword()
) :: {:ok, t()} | {:error, term()}

Refreshes thread metadata when adapter supports fetch_thread callback.

schema()

Returns the Zoi schema for Thread.

send_file(thread, file, opts \\ [])

@spec send_file(t(), Jido.Chat.FileUpload.input(), keyword()) ::
  {:ok, Jido.Chat.SentMessage.t()} | {:error, term()}

Uploads a file to the thread when supported by the adapter.

set_state(chat, thread, key, value)

@spec set_state(Jido.Chat.t(), t(), atom() | term(), map() | term()) :: Jido.Chat.t()

Sets thread state in chat struct using :replace, :merge, or key/value modes.

start_typing(thread, status \\ nil)

@spec start_typing(t(), String.t() | nil) :: :ok | {:error, term()}

Starts a typing indicator in the thread when supported.

state(chat, thread, key \\ nil)

@spec state(Jido.Chat.t(), t(), term() | nil) :: map() | term()

Gets thread state map or a single key from chat struct state.

subscribe(chat, thread)

@spec subscribe(Jido.Chat.t(), t()) :: Jido.Chat.t()

Subscribes this thread in a pure Jido.Chat state struct.

subscribed?(chat, thread)

@spec subscribed?(Jido.Chat.t(), t()) :: boolean()

Returns true when the thread is subscribed in a pure Jido.Chat state struct.

to_map(thread)

@spec to_map(t()) :: map()

Serializes thread into a plain map with type marker.

unsubscribe(chat, thread)

@spec unsubscribe(Jido.Chat.t(), t()) :: Jido.Chat.t()

Unsubscribes this thread in a pure Jido.Chat state struct.