Canonical outbound message target.
MessagingTarget provides a unified representation for outbound message routing, supporting DMs, groups, threads, and various reply modes. It abstracts away platform-specific targeting details while preserving the information needed for accurate message delivery.
Reply Modes
:inline- Reply as a direct response in the same context:thread- Reply in a thread (creates one if needed):platform_default- Use the platform's default reply behavior
Usage
# Create target from incoming context
target = MessagingTarget.from_context(msg_context)
# Create reply target with specific mode
target = MessagingTarget.for_reply(msg_context, :thread)
# Create target for a specific room
target = MessagingTarget.for_room("external_room_123")
Summary
Functions
Creates a MessagingTarget configured for replying to a message.
Creates a MessagingTarget for a specific room/chat.
Creates a MessagingTarget for a specific thread.
Creates a MessagingTarget from a normalized context map.
Returns the Zoi schema for MessagingTarget
Returns options suitable for passing to channel send_message functions.
Types
@type context() :: %{ :external_room_id => String.t() | integer(), optional(:chat_type) => atom(), optional(:external_thread_id) => String.t() | nil, optional(:external_message_id) => String.t() | nil, optional(:bridge_id) => String.t() | nil, optional(:instance_id) => String.t() | nil, optional(:channel_type) => atom() | nil }
@type kind() :: :room | :dm | :thread
@type reply_mode() :: :inline | :thread | :platform_default
Functions
@spec for_reply(context(), reply_mode()) :: t()
Creates a MessagingTarget configured for replying to a message.
Parameters
ctx- The MsgContext of the message being replied toreply_mode- How to reply::inline,:thread, or:platform_default
Examples
# Reply in a thread
target = MessagingTarget.for_reply(ctx, :thread)
# Reply inline
target = MessagingTarget.for_reply(ctx, :inline)
Creates a MessagingTarget for a specific room/chat.
Use this when sending a proactive message (not a reply).
Examples
target = MessagingTarget.for_room("chat_123")
target = MessagingTarget.for_room("chat_123", kind: :dm, channel_type: :telegram)
Creates a MessagingTarget for a specific thread.
Examples
target = MessagingTarget.for_thread("chat_123", "thread_456")
Creates a MessagingTarget from a normalized context map.
The target kind is inferred from the chat type:
:directchat type ->:dmkind:threadchat type ->:threadkind- otherwise ->
:roomkind
Examples
iex> ctx = %{external_room_id: "123", chat_type: :direct}
iex> target = MessagingTarget.from_context(ctx)
iex> target.kind
:dm
Returns the Zoi schema for MessagingTarget
Returns options suitable for passing to channel send_message functions.
Converts the target into keyword options that channels can use.