跳到內容

工作流程

client.workflows 同時公開頻道自動化(v2/backend 路由)和流程引擎(CRUD 流程、執行、資料夾、連線、元件、MCP 伺服器、表格、邀請)。

請先初始化客戶端(請參閱安裝快速入門)。如需將工作流程連接至 AI agent 的端到端逐步說明,請參閱完整流程指南 §2


頻道自動化 — client.workflows

const { data: automations } = await client.workflows.listChannelAutomation();
const { data: whatsappFlows } = await client.workflows.listChannelAutomation({ channelType: "whatsapp" });

流程

CRUD

const { data: flows } = await client.workflows.listFlows();
const flow = await client.workflows.getFlow("flow_id");
const newFlow = await client.workflows.createFlow({
displayName: "New Lead Notification",
projectId: "project_id",
});
await client.workflows.deleteFlow("flow_id");

套用操作

await client.workflows.applyFlowOperation("flow_id", {
type: "UPDATE_TRIGGER",
request: {
name: "trigger",
type: "PIECE_TRIGGER",
valid: true,
displayName: "Webhook",
settings: {
pieceName: "@activepieces/piece-webhook",
pieceVersion: "0.1.24",
triggerName: "catch_webhook",
input: {},
propertySettings: {},
},
},
});

觸發流程

// 觸發後即忘
await client.workflows.triggerFlow("flow_id", {
contactId: "contact_xxx",
event: "lead_qualified",
});
// 等待結果
const result = await client.workflows.triggerFlowSync("flow_id", {
contactId: "contact_xxx",
event: "lead_qualified",
});

流程執行

const { data: runs } = await client.workflows.listRuns({ flowId: "flow_id", limit: 20 });
const run = await client.workflows.getRun("run_id");

資料夾

const { data: folders } = await client.workflows.listFolders();
const folder = await client.workflows.getFolder("folder_id");
const newFolder = await client.workflows.createFolder({ displayName: "CRM Automations", projectId: "project_id" });
const updated = await client.workflows.updateFolder("folder_id", { displayName: "Updated Name" });
await client.workflows.deleteFolder("folder_id");

應用程式連線

const { data: connections } = await client.workflows.listConnections();
const connection = await client.workflows.getConnection("connection_id");
await client.workflows.upsertConnection({
name: "slack-integration",
type: "OAUTH2",
value: { access_token: "xoxb-xxx" },
});
await client.workflows.deleteConnection("connection_id");

元件

const pieces = await client.workflows.listPieces({ limit: 20 });

觸發條件

const status = await client.workflows.getTriggerRunStatus();
await client.workflows.testTrigger({ pieceName: "@activepieces/piece-webhook", flowId: "flow_id" });

表格與記錄

const { data: tables } = await client.workflows.listTables();
const table = await client.workflows.getTable("table_id");
const { data: records } = await client.workflows.listRecords({ tableId: "table_id" });

MCP 伺服器

const { data: servers } = await client.workflows.listMcpServers("project_id");
const server = await client.workflows.getMcpServer("mcp_server_id");
const newServer = await client.workflows.createMcpServer({ projectId: "project_id", name: "My MCP" });
await client.workflows.deleteMcpServer("mcp_server_id");
await client.workflows.rotateMcpToken("mcp_server_id");

使用者邀請

const { data: invitations } = await client.workflows.listInvitations({ type: "PROJECT" });
await client.workflows.deleteInvitation("invitation_id");