Develop Custom Actions
Create reusable workflow steps with Zod schemas, metadata, and an execute function.
Last updated
Was this helpful?
Was this helpful?
import { ConversationalWorkflowContext, createAction } from '@hexabot-ai/api';
import { z } from 'zod';
const createTicketInputSchema = z.object({
email: z.string().email().meta({
title: 'Email',
description: 'Customer email address.',
}),
subject: z.string().min(1).meta({
title: 'Subject',
description: 'Ticket subject.',
}),
message: z.string().min(1).meta({
title: 'Message',
description: 'Ticket message.',
}),
});
const createTicketOutputSchema = z.object({
ticketId: z.string().meta({
title: 'Ticket ID',
description: 'Identifier of the created ticket.',
}),
status: z.string().meta({
title: 'Status',
description: 'Ticket creation status.',
}),
});
const createTicketSettingsSchema = z.object({
priority: z.enum(['low', 'normal', 'high']).default('normal').meta({
title: 'Priority',
description: 'Default priority for created tickets.',
}),
});
type CreateTicketInput = z.infer<typeof createTicketInputSchema>;
type CreateTicketOutput = z.infer<typeof createTicketOutputSchema>;
type CreateTicketSettings = z.infer<typeof createTicketSettingsSchema>;
const CreateTicketAction = createAction<
CreateTicketInput,
CreateTicketOutput,
ConversationalWorkflowContext,
CreateTicketSettings
>({
name: 'create_ticket',
description: 'Creates a support ticket from workflow data.',
inputSchema: createTicketInputSchema,
outputSchema: createTicketOutputSchema,
settingsSchema: createTicketSettingsSchema,
icon: 'Ticket',
color: '#2563EB',
group: 'support',
async execute({ input, settings }) {
return {
ticketId: `ticket_${Date.now()}`,
status: settings.priority,
};
},
});
export default CreateTicketAction;const inputSchema = z.object({
orderId: z.string().min(1),
});const settingsSchema = z.object({
notifyCustomer: z.boolean().default(true),
});const outputSchema = z.object({
sent: z.boolean(),
reference: z.string(),
});async execute({ input, settings, context }) {
// ...
}import { ConversationalWorkflowContext } from '@hexabot-ai/api';src/extensions/actions/i18n/en.translations.json
src/extensions/actions/i18n/fr.translations.json{
"create_ticket": {
"Creates a support ticket from workflow data.": "Creates a support ticket from workflow data.",
"Email": "Email",
"Customer email address.": "Customer email address.",
"Subject": "Subject",
"Ticket subject.": "Ticket subject."
}
}<lang>.translations.json