Chuyển đến nội dung

Workflows

client.workflows hiển thị cả tự động hóa kênh (route v2/backend) và công cụ flow (CRUD flows, runs, folders, connections, pieces, MCP servers, tables, invitations).

Khởi tạo client trước (xem Cài đặt hoặc Quick Start). Để biết hướng dẫn từ đầu đến cuối kết nối workflow với AI agent, xem Hướng dẫn toàn diện §2.


Tự động hóa Kênh — client.workflows

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

Flows

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");

Áp dụng thao tác

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: {},
},
},
});

Kích hoạt flow

// Fire and forget
await client.workflows.triggerFlow("flow_id", {
contactId: "contact_xxx",
event: "lead_qualified",
});
// Chờ kết quả
const result = await client.workflows.triggerFlowSync("flow_id", {
contactId: "contact_xxx",
event: "lead_qualified",
});

Lượt chạy Flow

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

Thư mục

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");

Kết nối Ứng dụng

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");

Pieces

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

Triggers

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

Bảng & Bản ghi

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 Servers

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");

Lời mời Người dùng

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