import { CLOSEBOT_ID_SCHEMA, CLOSEBOT_SMART_FAQ_SCHEMA, } from "@automate.ax/integration-contracts/closebot" import * as z from "zod" import { defineAction } from "../../../automation/actions" import { CLOSEBOT_ACCOUNT, getCloseBotApi } from "./lib" /** Lists CloseBot Smart FAQs for one or more sources. */ export const listCloseBotSmartFaqs = defineAction("List CloseBot Smart FAQs") .describe("Lists Smart FAQs by source, state, and answer status.") .account(CLOSEBOT_ACCOUNT) .input( z.object({ answered: z.enum(["answered", "unanswered"]).optional(), sourceId: CLOSEBOT_ID_SCHEMA.optional(), state: z.enum(["compressed", "uncompressed"]).optional(), }), ) .output(CLOSEBOT_SMART_FAQ_SCHEMA.array()) .retry({ replaySafety: "safe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request("smart-faq", { query: input, responseSchema: CLOSEBOT_SMART_FAQ_SCHEMA.array(), }), ) /** Creates a CloseBot Smart FAQ for one source. */ export const createCloseBotSmartFaq = defineAction("Create CloseBot Smart FAQ") .describe("Creates a question and answer for one source.") .account(CLOSEBOT_ACCOUNT) .input( z.object({ answer: z.string().trim().min(1), question: z.string().trim().min(1), sourceId: CLOSEBOT_ID_SCHEMA, }), ) .output(z.null()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request("smart-faq", { body: input, method: "POST", responseSchema: z.null(), }), ) /** Answers multiple CloseBot Smart FAQs. */ export const answerCloseBotSmartFaqs = defineAction( "Answer CloseBot Smart FAQs", ) .describe("Saves answers for multiple existing Smart FAQs.") .account(CLOSEBOT_ACCOUNT) .input( z.object({ faqs: z .object({ answer: z.string(), id: CLOSEBOT_ID_SCHEMA }) .array() .min(1), }), ) .output(CLOSEBOT_SMART_FAQ_SCHEMA.array()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request("smart-faq/answer", { body: { faQs: input.faqs }, method: "POST", responseSchema: CLOSEBOT_SMART_FAQ_SCHEMA.array(), }), ) /** Sends a follow-up for one answered CloseBot Smart FAQ. */ export const followUpOnCloseBotSmartFaq = defineAction( "Follow up on CloseBot Smart FAQ", ) .describe("Follows up with selected leads about one answered Smart FAQ.") .account(CLOSEBOT_ACCOUNT) .input( z.object({ faqId: CLOSEBOT_ID_SCHEMA, leadIds: CLOSEBOT_ID_SCHEMA.array().min(1), }), ) .output(z.null()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request("smart-faq/answered-followup", { body: input, method: "POST", responseSchema: z.null(), }), ) /** Deletes one CloseBot Smart FAQ. */ export const deleteCloseBotSmartFaq = defineAction("Delete CloseBot Smart FAQ") .describe("Deletes one Smart FAQ by ID.") .account(CLOSEBOT_ACCOUNT) .input(z.object({ faqId: CLOSEBOT_ID_SCHEMA })) .output(z.null()) .retry({ replaySafety: "unsafe" }) .handler(async ({ account, input }) => getCloseBotApi(account.secret).request( `smart-faq/${encodeURIComponent(input.faqId)}`, { method: "DELETE", responseSchema: z.null() }, ), )