Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/sim/app/api/webhooks/agentmail/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ export const POST = withRouteHandler(async (req: Request) => {
return NextResponse.json({ ok: true })
}

const fromEmail = extractSenderEmail(message.from_) || ''
logger.info('Webhook received', { fromEmail, from_raw: message.from_, workspaceId: result.id })
const fromEmail = extractSenderEmail(message.from) || ''
logger.info('Webhook received', { fromEmail, from_raw: message.from, workspaceId: result.id })

if (result.inboxAddress && fromEmail === result.inboxAddress.toLowerCase()) {
logger.info('Skipping email from inbox itself', { workspaceId: result.id })
Expand Down Expand Up @@ -212,7 +212,7 @@ export const POST = withRouteHandler(async (req: Request) => {

const chatId = parentTaskResult[0]?.chatId ?? null

const fromName = extractDisplayName(message.from_)
const fromName = extractDisplayName(message.from)

const taskId = generateId()
const bodyText = message.text?.substring(0, 50_000) || null
Expand Down Expand Up @@ -334,8 +334,8 @@ async function createRejectedTask(
await db.insert(mothershipInboxTask).values({
id: generateId(),
workspaceId,
fromEmail: extractSenderEmail(message.from_) || 'unknown',
fromName: extractDisplayName(message.from_),
fromEmail: extractSenderEmail(message.from) || 'unknown',
fromName: extractDisplayName(message.from),
subject: message.subject || '(no subject)',
bodyPreview: (message.text || '').substring(0, 200) || null,
emailMessageId: message.message_id,
Expand All @@ -347,7 +347,7 @@ async function createRejectedTask(
}

/**
* Extract the raw email address from AgentMail's from_ field.
* Extract the raw email address from AgentMail's from field.
* Format: "username@domain.com" or "Display Name <username@domain.com>"
*/
function extractSenderEmail(from: string): string {
Expand Down
12 changes: 6 additions & 6 deletions apps/sim/lib/api/contracts/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ export const agentMailMessageSchema = z
thread_id: z.string(),
inbox_id: z.string(),
organization_id: z.string().optional(),
from_: z.string(),
from: z.string(),
to: z.array(z.string()),
cc: z.array(z.string()),
cc: z.array(z.string()).optional(),
bcc: z.array(z.string()).optional(),
reply_to: z.array(z.string()).optional(),
subject: z.string(),
subject: z.string().optional(),
preview: z.string().optional(),
text: z.string().nullable(),
html: z.string().nullable(),
attachments: z.array(agentMailAttachmentSchema),
text: z.string().nullable().optional(),
html: z.string().nullable().optional(),
attachments: z.array(agentMailAttachmentSchema).optional(),
in_reply_to: z.string().optional(),
references: z.array(z.string()).optional(),
labels: z.array(z.string()).optional(),
Expand Down
12 changes: 6 additions & 6 deletions apps/sim/lib/mothership/inbox/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ export interface AgentMailMessage {
thread_id: string
inbox_id: string
organization_id?: string
from_: string
from: string
to: string[]
cc: string[]
cc?: string[]
bcc?: string[]
reply_to?: string[]
subject: string
subject?: string
preview?: string
text: string | null
html: string | null
attachments: AgentMailAttachment[]
text?: string | null
html?: string | null
attachments?: AgentMailAttachment[]
in_reply_to?: string
references?: string[]
labels?: string[]
Expand Down
Loading