import * as z from "zod" import { defineAction } from "../../../automation/actions" import { EMAIL_ORIGIN_TOKEN } from "../../../lib/email-origin" import { getGmailApi, getMessageMetadata, sendReply, } from "@automate.ax/integration-contracts/gmail" import { GMAIL_SEND_AND_METADATA_REQUIREMENT } from "../lib/scopes" import { MESSAGE_METADATA_SCHEMA, REPLY_OPTIONS_SCHEMA, } from "@automate.ax/integration-contracts/gmail" /** * Replies to one Gmail message. * * Gmail derives the conversation headers and primary recipient. Optional To, * Cc, and Bcc values add recipients to the outgoing reply. */ export const replyToGmailMessage = defineAction("Reply to Gmail message") .describe("Replies to a Gmail message with optional additional recipients.") .account("google", GMAIL_SEND_AND_METADATA_REQUIREMENT) .input( REPLY_OPTIONS_SCHEMA.extend({ /** Immutable Gmail message ID receiving the reply. */ messageId: z.string().min(1), }), ) .output(MESSAGE_METADATA_SCHEMA) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input, runtime }) => { const gmailApi = getGmailApi(account.secret) return await sendReply( gmailApi, await getMessageMetadata(gmailApi, input.messageId), input, runtime[EMAIL_ORIGIN_TOKEN], ) })