import * as z from "zod" import { defineAction } from "../../../automation/actions" import { getGmailApi } from "@automate.ax/integration-contracts/gmail" import { GMAIL_READ_REQUIREMENT } from "../lib/scopes" /** * Returns the base64url-encoded RFC 5322 source of one Gmail message. * * Most automations should prefer `getMessage`; this action is an escape hatch * for protocols or parsers that require the untouched message source. */ export const getRawGmailMessage = defineAction("Get raw Gmail message") .describe("Gets the untouched base64url-encoded RFC 5322 message.") .account("google", GMAIL_READ_REQUIREMENT) .input( z.object({ /** Immutable Gmail message ID. */ messageId: z.string().min(1), }), ) .output(z.string()) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => { const { data: message } = await getGmailApi( account.secret, ).users.messages.get({ format: "raw", id: input.messageId, userId: "me", }) if (!message.raw) throw new Error("Gmail did not return the raw message.") return message.raw })