Class: Silas::AgentMailbox

Inherits:
ActionMailbox::Base
  • Object
show all
Defined in:
app/mailboxes/silas/agent_mailbox.rb

Overview

Action Mailbox reference inbound: maps an email thread to a Silas session. A new thread starts a session; a reply (same References/In-Reply-To root) continues it. Route inbound mail here from the host's ApplicationMailbox:

routing all: "Silas::AgentMailbox"

Requires app/agent/channels/email.rb (Agent::Channels::Email) to exist.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.thread_key(mail) ⇒ Object

The thread root: References head, else In-Reply-To, else this Message-ID.



23
24
25
# File 'app/mailboxes/silas/agent_mailbox.rb', line 23

def self.thread_key(mail)
  (Array(mail.references).first || mail.in_reply_to || mail.message_id).to_s
end

Instance Method Details

#processObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/mailboxes/silas/agent_mailbox.rb', line 8

def process
  channel_class.dispatch(
    thread_key: self.class.thread_key(mail),
    input: body_text,
    # Which staff member was written to (nil -> the root agent). Every
    # recipient is a candidate — To, Cc, and the forwarding headers Action
    # Mailbox's own routing matches on — first route wins.
    agent: Silas::Channel.route_for("email", mail.recipients),
    metadata: { "email" => { "from" => mail.from&.first, "subject" => mail.subject } }
  )
rescue Silas::TurnInProgressError
  # A reply arriving while a turn is active is dropped (v1 single-active-turn).
end