# `Jido.Messaging.MsgContext`
[🔗](https://github.com/agentjido/jido_messaging/blob/v1.0.0/lib/jido_messaging/msg_context.ex#L1)

Normalized message envelope for routing and transport.

MsgContext provides a unified, typed representation of an inbound/outbound message
that can be used consistently across all pipeline stages. It contains channel
identification, conversation scope, sender identity, message identification,
threading context, and extensible metadata.

## Usage

    # Populated by Ingest pipeline
    {:ok, message, msg_context} = Ingest.ingest_incoming(messaging, channel, bridge_id, incoming)

    # Use for routing decisions
    if msg_context.chat_type == :direct do
      # Handle DM
    end

    # Build reply target
    target = MessagingTarget.from_context(msg_context)

# `t`

```elixir
@type t() :: %Jido.Messaging.MsgContext{
  agent_mentions: [binary()],
  app_meta: map(),
  body: nil | nil | binary(),
  bridge_id: binary(),
  channel_meta: map(),
  channel_module: nil | nil | module(),
  channel_type: atom(),
  chat_type: :direct | :group | :channel | :thread,
  command: nil | nil | map(),
  delivery_external_room_id: nil | nil | binary(),
  external_message_id: nil | nil | binary(),
  external_reply_to_id: nil | nil | binary(),
  external_room_id: binary(),
  external_thread_id: nil | nil | binary(),
  external_user_id: binary(),
  mentions: [map()],
  message_id: nil | nil | binary(),
  participant_id: nil | nil | binary(),
  raw: nil | nil | map(),
  reply_to_id: nil | nil | binary(),
  room_id: nil | nil | binary(),
  sender_name: nil | nil | binary(),
  sender_username: nil | nil | binary(),
  thread_id: nil | nil | binary(),
  timestamp: nil | nil | integer(),
  was_mentioned: boolean()
}
```

# `from_incoming`

```elixir
@spec from_incoming(module(), String.t(), map()) :: t()
```

Creates a new MsgContext from incoming message data.

## Parameters

  * `channel_module` - The channel module that received the message
  * `bridge_id` - The bridge identifier
  * `incoming` - The normalized incoming message map

## Examples

    iex> incoming = %{
    ...>   external_room_id: "chat_123",
    ...>   external_user_id: "user_456",
    ...>   text: "Hello"
    ...> }
    iex> ctx = MsgContext.from_incoming(MyChannel, "bot_1", incoming)
    iex> ctx.external_room_id
    "chat_123"

# `schema`

Returns the Zoi schema for MsgContext

# `with_resolved`

```elixir
@spec with_resolved(t(), map(), map(), map()) :: t()
```

Enriches the MsgContext with resolved internal IDs after room/participant lookup.

## Parameters

  * `ctx` - The MsgContext to enrich
  * `room` - The resolved Room struct
  * `participant` - The resolved Participant struct
  * `message` - The persisted Message struct

---

*Consult [api-reference.md](api-reference.md) for complete listing*
