$npx -y skills add gokapso/agent-skills --skill automate-whatsappBuild WhatsApp automations with Kapso workflows: configure WhatsApp triggers, edit workflow graphs, manage executions, deploy functions, search workflow Logs, and debug automation behavior. Use when automating WhatsApp conversations and event handling.
| 1 | # Automate WhatsApp |
| 2 | |
| 3 | ## When to use |
| 4 | |
| 5 | Use this skill to build and run WhatsApp automations: workflow CRUD, graph edits, WhatsApp and Project Event triggers, Project Event emissions, executions, function management, webhook tools, and MCP tools. |
| 6 | |
| 7 | ## Setup |
| 8 | |
| 9 | Preferred path: |
| 10 | - Kapso CLI installed and authenticated (`kapso login`) |
| 11 | - For workflow and function edits, use source-controlled projects with `kapso link`, `kapso pull`, `kapso build`, and `kapso push` |
| 12 | - For workflow code, use `@kapso/workflows` and export a `Workflow` instance from `workflow.js` or `workflow.ts` |
| 13 | |
| 14 | Fallback path: |
| 15 | Env vars: |
| 16 | - `KAPSO_API_BASE_URL` (host only, no `/platform/v1`) |
| 17 | - `KAPSO_API_KEY` |
| 18 | |
| 19 | ## How to |
| 20 | |
| 21 | ### Edit workflows locally |
| 22 | |
| 23 | Use this path first when the user is working in, or can create, a local repo. |
| 24 | |
| 25 | ```bash |
| 26 | npm install -g @kapso/cli |
| 27 | npm install --save-dev @kapso/workflows |
| 28 | kapso login |
| 29 | kapso link --project <project-id> |
| 30 | kapso pull |
| 31 | ``` |
| 32 | |
| 33 | Edit `workflows/<workflow-slug>/workflow.js` or `workflow.ts` with `@kapso/workflows`: |
| 34 | |
| 35 | ```ts |
| 36 | import { START, Workflow } from "@kapso/workflows"; |
| 37 | |
| 38 | const workflow = new Workflow("inbound-support", { |
| 39 | name: "Inbound Support", |
| 40 | status: "draft", |
| 41 | }); |
| 42 | |
| 43 | workflow.addTrigger({ |
| 44 | type: "inbound_message", |
| 45 | phoneNumberId: "<phone-number-id>", |
| 46 | }); |
| 47 | |
| 48 | workflow.addNode(START, { |
| 49 | position: { x: 100, y: 100 }, |
| 50 | }); |
| 51 | |
| 52 | workflow.addNode("reply", { |
| 53 | type: "send_text", |
| 54 | message: "Thanks for reaching out.", |
| 55 | }); |
| 56 | |
| 57 | workflow.addEdge(START, "reply"); |
| 58 | |
| 59 | export default workflow; |
| 60 | ``` |
| 61 | |
| 62 | Build and push: |
| 63 | |
| 64 | ```bash |
| 65 | kapso build |
| 66 | kapso push --dry-run |
| 67 | kapso push workflow <workflow-slug> |
| 68 | ``` |
| 69 | |
| 70 | Use `kapso push` to push every local function and workflow. See `references/local-workflow-source.md` for repo layout, source-file behavior, and JSON-only editing. |
| 71 | |
| 72 | ### Discover phone numbers first |
| 73 | |
| 74 | Preferred path: |
| 75 | 1. Check project state: `kapso status` |
| 76 | 2. List connected numbers: `kapso whatsapp numbers list --output json` |
| 77 | 3. Resolve a display number when needed: `kapso whatsapp numbers resolve --phone-number "<display-number>" --output json` |
| 78 | |
| 79 | Fallback path: |
| 80 | 1. List number configs for triggers: `node scripts/list-whatsapp-phone-numbers.js` |
| 81 | |
| 82 | ### Edit a workflow graph through API scripts |
| 83 | |
| 84 | Prefer local source sync for workflow edits. Use these scripts as a fallback for debugging, direct graph inspection, or API-only environments. |
| 85 | |
| 86 | 1. Fetch graph: `node scripts/get-graph.js <workflow_id>` (note the `lock_version`) |
| 87 | 2. Edit the JSON (see graph rules below) |
| 88 | 3. Validate: `node scripts/validate-graph.js --definition-file <path>` |
| 89 | 4. Update: `node scripts/update-graph.js <workflow_id> --expected-lock-version <n> --definition-file <path>` |
| 90 | 5. Re-fetch to confirm |
| 91 | |
| 92 | For small edits, use `edit-graph.js` with `--old-file` and `--new-file` instead. |
| 93 | |
| 94 | If you get a lock_version conflict: re-fetch, re-apply changes, retry with new lock_version. |
| 95 | |
| 96 | ### Manage triggers |
| 97 | |
| 98 | 1. List: `node scripts/list-triggers.js <workflow_id>` |
| 99 | 2. Create: `node scripts/create-trigger.js <workflow_id> --trigger-type <type> --phone-number-id <id>` |
| 100 | 3. Toggle: `node scripts/update-trigger.js --trigger-id <id> --active true|false` |
| 101 | 4. Delete: `node scripts/delete-trigger.js --trigger-id <id>` |
| 102 | |
| 103 | For inbound_message triggers, prefer `kapso whatsapp numbers resolve --phone-number "<display-number>" --output json` to get the exact `phone_number_id`. Fall back to `node scripts/list-whatsapp-phone-numbers.js` when the CLI is unavailable. |
| 104 | |
| 105 | For project_event triggers, register or update the Project Event definition first when the user is defining an event type/schema: |
| 106 | |
| 107 | ```bash |
| 108 | node scripts/project-event-definitions.js create \ |
| 109 | --name conversation.csat_scored \ |
| 110 | --description "Customer satisfaction score for a conversation" \ |
| 111 | --property-schema '{"score":{"type":"number"},"reason":{"type":"string"}}' |
| 112 | ``` |
| 113 | |
| 114 | Then create the trigger: |
| 115 | |
| 116 | ```bash |
| 117 | node scripts/create-trigger.js <workflow_id> \ |
| 118 | --trigger-type project_event \ |
| 119 | --triggerable-attributes '{"event_name":"conversation.csat_scored","property_key":"score","operator":"gte","property_value":4}' |
| 120 | ``` |
| 121 | |
| 122 | Definitions are metadata only. Do not emit a sample event just to register a name unless the user explicitly accepts that side effect. |
| 123 | |
| 124 | ### Manage Project Event definitions |
| 125 | |
| 126 | Use definitions for event names, descriptions, and flat scalar property schemas. Emitted events are separate records created by `POST /platform/v1/events`, `emit_event` nodes, Function node `project_events`, or Agent node `emit_event`. |
| 127 | |
| 128 | 1. List: `node scripts/project-event-definitions.js list` |
| 129 | 2. Create/update by name: `node scripts/project-event-definitions.js create --name <event.name> [--description <text>] [--property-schema <json>]` |
| 130 | 3. Update by ID: `node scripts/project-event-definitions.js upda |