Jido.Chat.ChannelRef (Jido Chat v1.0.0)

Copy Markdown View Source

Channel handle for adapter-routed posting, state, and metadata access.

Summary

Functions

Builds a channel ref from serialized map data.

Renders adapter-specific mention format for a user id.

Fetches a page of channel-level messages when supported.

Returns a lazy stream over channel messages using cursor pagination.

Returns cached channel name from metadata when present.

Creates a channel reference.

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

Opens a native platform thread from an existing channel message when supported.

Posts string/postable/stream content to channel via adapter.

Posts an ephemeral message via adapter when supported.

Returns the Zoi schema for ChannelRef.

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

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

Starts typing indicator on channel when supported.

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

Lists thread summaries in this channel when supported.

Returns a lazy stream over channel thread summaries using cursor pagination.

Serializes channel ref into a plain map with type marker.

Types

t()

@type t() :: %Jido.Chat.ChannelRef{
  adapter: any(),
  adapter_name: atom(),
  external_id: any(),
  id: binary(),
  metadata: map()
}

Functions

fetch_metadata(channel, opts \\ [])

@spec fetch_metadata(
  t(),
  keyword()
) :: {:ok, Jido.Chat.ChannelInfo.t()} | {:error, term()}

Fetches channel metadata as Jido.Chat.ChannelInfo.

from_map(map)

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

Builds a channel ref from serialized map data.

mention_user(channel_ref, user_id)

@spec mention_user(t(), String.t() | integer()) :: String.t()

Renders adapter-specific mention format for a user id.

messages(channel, opts \\ [])

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

Fetches a page of channel-level messages when supported.

messages_stream(channel, opts \\ [])

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

Returns a lazy stream over channel messages using cursor pagination.

name(channel)

@spec name(t()) :: String.t() | nil

Returns cached channel name from metadata when present.

new(attrs)

Creates a channel reference.

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

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

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

open_thread(channel, message_id, opts \\ [])

@spec open_thread(t(), String.t() | integer(), keyword()) ::
  {:ok, Jido.Chat.Thread.t()} | {:error, term()}

Opens a native platform thread from an existing channel message when supported.

post(channel, 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 to channel via adapter.

post_ephemeral(channel, user_id, input, opts \\ [])

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

Posts an ephemeral message via adapter when supported.

schema()

Returns the Zoi schema for ChannelRef.

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

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

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

set_state(chat, channel, key, value)

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

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

start_typing(channel, status \\ nil)

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

Starts typing indicator on channel when supported.

state(chat, channel, key \\ nil)

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

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

threads(channel, opts \\ [])

@spec threads(
  t(),
  keyword()
) :: {:ok, Jido.Chat.ThreadPage.t()} | {:error, term()}

Lists thread summaries in this channel when supported.

threads_stream(channel, opts \\ [])

@spec threads_stream(
  t(),
  keyword()
) :: Enumerable.t()

Returns a lazy stream over channel thread summaries using cursor pagination.

to_map(channel)

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

Serializes channel ref into a plain map with type marker.