import { CLOSEBOT_BOT_VARIABLE_SCHEMA, CLOSEBOT_ID_SCHEMA, } from "@automate.ax/integration-contracts/closebot" import * as z from "zod" import { defineAction } from "../../../automation/actions" import { CLOSEBOT_ACCOUNT, getCloseBotApi } from "./lib" /** Lists a bot's variables for one CloseBot source. */ export const listCloseBotSourceVariables = defineAction( "List CloseBot source variables", ) .describe("Lists one bot's variable values for a source.") .account(CLOSEBOT_ACCOUNT) .input(z.object({ botId: CLOSEBOT_ID_SCHEMA, sourceId: CLOSEBOT_ID_SCHEMA })) .output(CLOSEBOT_BOT_VARIABLE_SCHEMA.array()) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request( `botVariables/${encodeURIComponent(input.botId)}/${encodeURIComponent(input.sourceId)}`, { responseSchema: CLOSEBOT_BOT_VARIABLE_SCHEMA.array() }, ), ) /** Updates one bot variable for a CloseBot source. */ export const updateCloseBotSourceVariable = defineAction( "Update CloseBot source variable", ) .describe("Updates one bot variable value for a source.") .account(CLOSEBOT_ACCOUNT) .input( z.object({ botId: CLOSEBOT_ID_SCHEMA, sourceId: CLOSEBOT_ID_SCHEMA, variableId: CLOSEBOT_ID_SCHEMA, value: z.string(), }), ) .output(z.null()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request( `botVariables/${encodeURIComponent(input.botId)}/${encodeURIComponent(input.sourceId)}`, { body: [{ id: input.variableId, value: input.value }], method: "POST", responseSchema: z.null(), }, ), )