Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/morning-briefing

src/output.ts

34 lines · 766 B · TypeScript
import { kody } from 'kody:runtime'
import { deliveryPreview } from './format.ts'
import type { BriefingReport, BriefingResult, OutputChannel } from './types.ts'

export async function deliverReport(options: {
	report: BriefingReport
	output: OutputChannel
	dryRun: boolean
}): Promise<BriefingResult> {
	const preview = deliveryPreview(options.report, options.output)
	if (options.dryRun) {
		return {
			...options.report,
			dryRun: true,
			output: options.output,
			delivered: false,
			preview,
		}
	}

	await kody.email_send({
		subject: preview.subject,
		text: preview.text,
	})

	return {
		...options.report,
		dryRun: false,
		output: options.output,
		delivered: true,
		delivery: { channel: options.output, subject: preview.subject },
		preview,
	}
}