import * as z from "zod" import { defineAction } from "../../../automation/actions" import { getGmailApi, getGmailMessage as parseGmailMessage, } from "@automate.ax/integration-contracts/gmail" import { GMAIL_READ_REQUIREMENT } from "../lib/scopes" import { MESSAGE_SCHEMA } from "@automate.ax/integration-contracts/gmail" /** * Retrieves and fully parses one Gmail message. * * Attachments are always returned as Files because Gmail's raw-message response * already includes their contents. */ export const getGmailMessage = defineAction("Get Gmail message") .describe("Gets a parsed Gmail message with headers and attachments.") .account("google", GMAIL_READ_REQUIREMENT) .input( z.object({ /** Immutable Gmail message ID. */ messageId: z.string().min(1), }), ) .output(MESSAGE_SCHEMA) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => parseGmailMessage( ( await getGmailApi(account.secret).users.messages.get({ format: "raw", id: input.messageId, userId: "me", }) ).data, ), )