Behaviour for adapter-specific threading support.
Threading is fundamental to messaging but varies significantly across platforms. This behaviour defines how adapters can implement platform-specific threading logic while providing a normalized output for the messaging pipeline.
Implementation
Adapters that support threading should implement this behaviour:
defmodule MyApp.Channels.Slack do
@behaviour Jido.Chat.Adapter
@behaviour Jido.Chat.Adapters.Threading
@impl Jido.Chat.Adapters.Threading
def supports_threads?, do: true
@impl Jido.Chat.Adapters.Threading
def compute_thread_root(raw) do
# Slack uses thread_ts as the thread identifier
raw["thread_ts"] || raw["ts"]
end
@impl Jido.Chat.Adapters.Threading
def extract_thread_context(raw) do
%{
thread_id: raw["thread_ts"],
is_thread_reply: raw["thread_ts"] != nil,
thread_root_ts: raw["thread_ts"] || raw["ts"]
}
end
endDefault Implementations
All callbacks are optional. The defaults assume no threading support:
supports_threads?/0- Returnsfalsecompute_thread_root/1- Returnsnilextract_thread_context/1- Returns empty map
Summary
Callbacks
Computes the thread root identifier from a raw message payload.
Extracts threading context from a raw message payload.
Returns whether this adapter supports threading.
Functions
Safely computes the thread root for a module.
Safely extracts thread context for a module.
Checks if a module implements the Threading behaviour and supports threads.
Types
Callbacks
Computes the thread root identifier from a raw message payload.
The thread root is the first message in a thread. For messages that are
not part of a thread, this typically returns nil or the message's own ID.
Parameters
raw- The raw platform-specific message payload
Returns
The thread root identifier as a string, or nil if not applicable.
@callback extract_thread_context(raw :: map()) :: thread_context()
Extracts threading context from a raw message payload.
Returns a map with thread-related information that can be used for routing decisions and context building.
Parameters
raw- The raw platform-specific message payload
Returns
A map that may contain:
:thread_id- The thread identifier:is_thread_reply- Whether this message is a reply in a thread:thread_root_ts- The timestamp/ID of the thread root message
@callback supports_threads?() :: boolean()
Returns whether this adapter supports threading.
Used for capability detection and feature gating.
Functions
Safely computes the thread root for a module.
Returns nil if the module doesn't implement the callback.
@spec extract_thread_context(module(), map()) :: thread_context()
Safely extracts thread context for a module.
Returns an empty map if the module doesn't implement the callback.
Checks if a module implements the Threading behaviour and supports threads.
Returns true only if the module implements supports_threads?/0 and it returns true.