d25d482dc2
Publish CLI Package / publish-npm (push) Waiting to run
Publish Python SDK / publish-pypi (push) Waiting to run
Publish TypeScript SDK / publish-npm (push) Waiting to run
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
85 lines
2.6 KiB
TypeScript
85 lines
2.6 KiB
TypeScript
import { db } from '@sim/db'
|
|
import { webhook } from '@sim/db/schema'
|
|
import { createLogger } from '@sim/logger'
|
|
import { eq } from 'drizzle-orm'
|
|
import type {
|
|
FormatInputContext,
|
|
FormatInputResult,
|
|
PollingConfigContext,
|
|
WebhookProviderHandler,
|
|
} from '@/lib/webhooks/providers/types'
|
|
|
|
const logger = createLogger('WebhookProvider:Imap')
|
|
|
|
export const imapHandler: WebhookProviderHandler = {
|
|
async formatInput({ body }: FormatInputContext): Promise<FormatInputResult> {
|
|
const b = body as Record<string, unknown>
|
|
if (b && typeof b === 'object' && 'email' in b) {
|
|
return {
|
|
input: {
|
|
messageId: b.messageId,
|
|
subject: b.subject,
|
|
from: b.from,
|
|
to: b.to,
|
|
cc: b.cc,
|
|
date: b.date,
|
|
bodyText: b.bodyText,
|
|
bodyHtml: b.bodyHtml,
|
|
mailbox: b.mailbox,
|
|
hasAttachments: b.hasAttachments,
|
|
attachments: b.attachments,
|
|
email: b.email,
|
|
timestamp: b.timestamp,
|
|
},
|
|
}
|
|
}
|
|
return { input: b }
|
|
},
|
|
|
|
async configurePolling({ webhook: webhookData, requestId }: PollingConfigContext) {
|
|
logger.info(`[${requestId}] Setting up IMAP polling for webhook ${webhookData.id}`)
|
|
|
|
try {
|
|
const providerConfig = (webhookData.providerConfig as Record<string, unknown>) || {}
|
|
const now = new Date()
|
|
|
|
if (!providerConfig.host || !providerConfig.username || !providerConfig.password) {
|
|
logger.error(
|
|
`[${requestId}] Missing required IMAP connection settings for webhook ${webhookData.id}`
|
|
)
|
|
return false
|
|
}
|
|
|
|
await db
|
|
.update(webhook)
|
|
.set({
|
|
providerConfig: {
|
|
...providerConfig,
|
|
port: providerConfig.port || '993',
|
|
secure: providerConfig.secure !== false,
|
|
mailbox: providerConfig.mailbox || 'INBOX',
|
|
searchCriteria: providerConfig.searchCriteria || 'UNSEEN',
|
|
markAsRead: providerConfig.markAsRead || false,
|
|
includeAttachments: providerConfig.includeAttachments !== false,
|
|
lastCheckedTimestamp: now.toISOString(),
|
|
setupCompleted: true,
|
|
},
|
|
updatedAt: now,
|
|
})
|
|
.where(eq(webhook.id, webhookData.id as string))
|
|
|
|
logger.info(
|
|
`[${requestId}] Successfully configured IMAP polling for webhook ${webhookData.id}`
|
|
)
|
|
return true
|
|
} catch (error: unknown) {
|
|
const err = error as Error
|
|
logger.error(`[${requestId}] Failed to configure IMAP polling`, {
|
|
webhookId: webhookData.id,
|
|
error: err.message,
|
|
})
|
|
return false
|
|
}
|
|
},
|
|
}
|