//---REQUIRED HEADER - DO NOT MODIFY---
import { pf } from "./pf-bootstrap.mjs";
//---END REQUIRED HEADER---
const WORKFLOW_RESOURCES = {
zendesk: {
type: "connection",
application: "zendesk",
description: "Zendesk support account",
},
apiEndpoint: {
type: "trigger",
triggerType: "api",
description: "API endpoint — bind via workflow_trigger_api tool",
},
ticketAnalyst: {
type: "agent",
description:
"Agent that analyzes support tickets for patterns and insights",
},
};
const WORKFLOW_NODES = [
{
id: "trigger_1",
name: "API Webhook",
type: "trigger",
triggerType: "api",
inputSchema: {
ticketLimit: {
type: "number",
description: "Number of tickets to fetch",
},
},
},
{
id: "node_fetch_tickets",
name: "Fetch Zendesk Tickets",
type: "mcp-tool",
serverName: "zendesk",
toolName: "zendesk_list_tickets",
parameters: {
PCID: "{{resource.zendesk}}",
per_page: "@trigger_1.ticketLimit",
},
inputSchema: {
PCID: { type: "string", source: "resource" },
per_page: { type: "number", source: "input" },
},
},
{
id: "node_format_tickets",
name: "Format Tickets",
type: "code-block",
parameters: {
tickets: "@node_fetch_tickets.tickets",
},
inputSchema: {
tickets: { type: "array", source: "node" },
},
},
{
id: "node_analyze_tickets",
name: "Analyze Tickets",
type: "code-block",
parameters: {
agentId: "{{resource.ticketAnalyst}}",
message:
"Analyze these support tickets and identify top issues, urgent count, and trends.",
formattedTickets: "@node_format_tickets.formattedTickets",
},
inputSchema: {
agentId: { type: "string", source: "resource" },
message: { type: "string", source: "literal" },
formattedTickets: { type: "string", source: "node" },
},
},
];
const WORKFLOW_EDGES = [
{ source: "trigger_1", target: "node_fetch_tickets" },
{ source: "node_fetch_tickets", target: "node_format_tickets" },
{ source: "node_format_tickets", target: "node_analyze_tickets" },
];
async function node_fetch_tickets(params) {
pf.log.info("Fetching Zendesk tickets...");
const result = await pf.mcp.callTool("zendesk", "zendesk_list_tickets", {
...params,
version: "1",
});
await pf.files.writeFile("node_fetch_tickets_output.json", result);
pf.log.success("Fetched " + (result.tickets?.length || 0) + " tickets");
return result;
}
async function node_format_tickets(params) {
const { tickets } = params;
pf.log.info("Formatting " + tickets.length + " tickets...");
const formattedTickets = tickets
.map(
(t) =>
`[${t.id}] ${t.subject} - Status: ${t.status}, Priority: ${t.priority}`,
)
.join("\n");
const output = { formattedTickets, ticketCount: tickets.length };
await pf.files.writeFile("node_format_tickets_output.json", output);
pf.log.success("Formatted " + tickets.length + " tickets");
return output;
}
async function node_analyze_tickets(params) {
const { agentId, message, formattedTickets } = params;
pf.log.info("Analyzing tickets with AI agent...");
const result = await pf.mcp.callTool("pinkfish-sidekick", "workflow_agents", {
action: "invoke",
agentId,
message: `${message}\n${formattedTickets}`,
});
const parsed = JSON.parse(result.response);
await pf.files.writeFile("node_analyze_tickets_output.json", parsed);
pf.log.success("Analysis complete");
return parsed;
}
global.node_fetch_tickets = node_fetch_tickets;
global.node_format_tickets = node_format_tickets;
global.node_analyze_tickets = node_analyze_tickets;
//---REQUIRED FOOTER - DO NOT MODIFY---
await pf.run(WORKFLOW_NODES, WORKFLOW_EDGES);
//---END REQUIRED FOOTER---