| 84 | * 4. Delete mothershipInboxWebhook row |
| 85 | */ |
| 86 | export async function disableInbox(workspaceId: string): Promise<void> { |
| 87 | const [[ws], [webhookRow]] = await Promise.all([ |
| 88 | db |
| 89 | .select({ inboxProviderId: workspace.inboxProviderId }) |
| 90 | .from(workspace) |
| 91 | .where(eq(workspace.id, workspaceId)) |
| 92 | .limit(1), |
| 93 | db |
| 94 | .select({ webhookId: mothershipInboxWebhook.webhookId }) |
| 95 | .from(mothershipInboxWebhook) |
| 96 | .where(eq(mothershipInboxWebhook.workspaceId, workspaceId)) |
| 97 | .limit(1), |
| 98 | ]) |
| 99 | |
| 100 | const deletePromises: Promise<void>[] = [] |
| 101 | if (webhookRow) { |
| 102 | deletePromises.push( |
| 103 | agentmail.deleteWebhook(webhookRow.webhookId).catch((error) => { |
| 104 | logger.warn('Failed to delete AgentMail webhook', { error }) |
| 105 | }) |
| 106 | ) |
| 107 | } |
| 108 | if (ws?.inboxProviderId) { |
| 109 | deletePromises.push( |
| 110 | agentmail.deleteInbox(ws.inboxProviderId).catch((error) => { |
| 111 | logger.warn('Failed to delete AgentMail inbox', { error }) |
| 112 | }) |
| 113 | ) |
| 114 | } |
| 115 | await Promise.all(deletePromises) |
| 116 | |
| 117 | await Promise.all([ |
| 118 | db.delete(mothershipInboxWebhook).where(eq(mothershipInboxWebhook.workspaceId, workspaceId)), |
| 119 | db |
| 120 | .update(workspace) |
| 121 | .set({ |
| 122 | inboxEnabled: false, |
| 123 | inboxAddress: null, |
| 124 | inboxProviderId: null, |
| 125 | updatedAt: new Date(), |
| 126 | }) |
| 127 | .where(eq(workspace.id, workspaceId)), |
| 128 | ]) |
| 129 | |
| 130 | logger.info('Inbox disabled', { workspaceId }) |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Update inbox address (regenerate): |