import * as z from "zod" import { defineAction } from "../../../automation/actions" import { findLabelIds, getGmailApi, } from "@automate.ax/integration-contracts/gmail" import { GMAIL_MODIFY_REQUIREMENT } from "../lib/scopes" import { LABELS_SCHEMA, MESSAGE_IDS_SCHEMA, } from "@automate.ax/integration-contracts/gmail" /** * Removes Gmail labels from one or many messages. * * Accepts label display names or immutable IDs and returns the modified message * IDs for action chaining. */ export const removeGmailLabel = defineAction("Remove Gmail label") .describe("Removes Gmail labels from one or many messages.") .account("google", GMAIL_MODIFY_REQUIREMENT) .input( z.object({ /** Gmail label display names or immutable IDs. */ labels: LABELS_SCHEMA, /** One ID or up to 1,000 immutable Gmail message IDs. */ messageIds: MESSAGE_IDS_SCHEMA, }), ) .output(z.string().array()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => { const gmailApi = getGmailApi(account.secret) const { messageIds } = input await gmailApi.users.messages.batchModify({ requestBody: { ids: messageIds, removeLabelIds: await findLabelIds(gmailApi, input.labels), }, userId: "me", }) return messageIds })