d25d482dc2
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
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { EmailClient, type EmailMessage } from '@azure/communication-email'
|
|
import { env } from '@/lib/core/config/env'
|
|
import type { MailProvider, ProcessedEmailData, SendEmailResult } from '@/lib/messaging/email/types'
|
|
|
|
function extractBareAddress(addressOrFormatted: string): string {
|
|
if (!addressOrFormatted.includes('<')) return addressOrFormatted
|
|
return addressOrFormatted.match(/<(.+)>/)?.[1] ?? addressOrFormatted
|
|
}
|
|
|
|
export function createAzureProvider(): MailProvider | null {
|
|
const connectionString = env.AZURE_ACS_CONNECTION_STRING
|
|
if (!connectionString || connectionString.trim() === '') return null
|
|
const client = new EmailClient(connectionString)
|
|
|
|
return {
|
|
name: 'azure',
|
|
async send(data: ProcessedEmailData): Promise<SendEmailResult> {
|
|
if (!data.html && !data.text) {
|
|
throw new Error('Azure Communication Services requires either HTML or text content')
|
|
}
|
|
|
|
const message: EmailMessage = {
|
|
senderAddress: extractBareAddress(data.senderEmail),
|
|
content: data.html
|
|
? { subject: data.subject, html: data.html }
|
|
: { subject: data.subject, plainText: data.text as string },
|
|
recipients: {
|
|
to: (Array.isArray(data.to) ? data.to : [data.to]).map((address) => ({ address })),
|
|
},
|
|
headers: data.headers,
|
|
}
|
|
|
|
const poller = await client.beginSend(message)
|
|
const result = await poller.pollUntilDone()
|
|
if (result.status !== 'Succeeded') {
|
|
throw new Error(`Azure Communication Services failed with status: ${result.status}`)
|
|
}
|
|
return {
|
|
success: true,
|
|
message: 'Email sent successfully via Azure Communication Services',
|
|
data: { id: result.id },
|
|
}
|
|
},
|
|
}
|
|
}
|