import { native, object, validateDraft } from "./core.ts"; import type { MessageDraft } from "./core.ts"; import type { SendReceipt } from "./types.ts"; /** * Preview a reviewed draft by default, or explicitly send it through this Mac's Messages app. * @param input - draft from /draft, and confirmSend (default false). Set true only after the user explicitly approves this exact target and text. Never use true in smoke tests. * @returns Dry-run preview without any host command, or a local send receipt. recorded is not a delivery receipt. Never retry an uncertain result automatically. * @example * import prepare from 'kody:@tannerlinsley/imessage/draft'; * import send from 'kody:@tannerlinsley/imessage/send'; * const draft = await prepare({target:{recipient:'test@example.invalid'},text:'Synthetic preview, do not send.'}); * const preview = await send({draft,confirmSend:false}); */ export default async function send(input: { draft: MessageDraft; confirmSend?: boolean; }): Promise { const p = object(input, ["draft", "confirmSend"]); if (p.confirmSend !== undefined && typeof p.confirmSend !== "boolean") throw new Error("confirmSend must be a boolean."); const reviewed = await validateDraft(p.draft); if (p.confirmSend !== true) return { sent: false, dryRun: true, draft: reviewed }; return native({ action: "send", ...reviewed.target, text: reviewed.text, service: reviewed.service, }); }