MCPcopy Index your code
hub / github.com/simstudioai/sim / sendInboxResponse

Function sendInboxResponse

apps/sim/lib/mothership/inbox/response.ts:22–62  ·  view source on GitHub ↗
(
  inboxTask: InboxTask,
  result: { success: boolean; content: string; error?: string },
  ctx: InboxResponseContext
)

Source from the content-addressed store, hash-verified

20 * Returns the AgentMail response message ID for thread stitching, or null on failure.
21 */
22export async function sendInboxResponse(
23 inboxTask: InboxTask,
24 result: { success: boolean; content: string; error?: string },
25 ctx: InboxResponseContext
26): Promise<string | null> {
27 if (!ctx.inboxProviderId || !inboxTask.agentmailMessageId) {
28 logger.warn('Cannot send response: missing inbox provider or message ID', {
29 taskId: inboxTask.id,
30 })
31 return null
32 }
33
34 const chatUrl = inboxTask.chatId
35 ? `${getBaseUrl()}/workspace/${ctx.workspaceId}/chat/${inboxTask.chatId}`
36 : `${getBaseUrl()}/workspace/${ctx.workspaceId}/home`
37
38 const text = result.success
39 ? `${result.content}\n\n[View full conversation](${chatUrl})\n\nBest,\nMothership`
40 : `I wasn't able to complete this task.\n\nError: ${result.error || 'Unknown error'}\n\n[View details](${chatUrl})\n\nBest,\nMothership`
41
42 const html = result.success
43 ? await renderEmailHtml(result.content, chatUrl)
44 : await renderErrorHtml(result.error || 'Unknown error', chatUrl)
45
46 try {
47 const response = await agentmail.replyToMessage(
48 ctx.inboxProviderId,
49 inboxTask.agentmailMessageId,
50 { text, html }
51 )
52
53 logger.info('Inbox response sent', { taskId: inboxTask.id, responseId: response.message_id })
54 return response.message_id
55 } catch (error) {
56 logger.error('Failed to send inbox response email', {
57 taskId: inboxTask.id,
58 error: getErrorMessage(error, 'Unknown error'),
59 })
60 return null
61 }
62}
63
64const FONT_FAMILY = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif"
65const CODE_FONT_FAMILY = "ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace"

Callers 1

executeInboxTaskFunction · 0.90

Calls 7

getBaseUrlFunction · 0.90
getErrorMessageFunction · 0.90
renderEmailHtmlFunction · 0.85
renderErrorHtmlFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected