---
name: bibu-n8n-workflow-builder
description: Designs and writes importable n8n workflow JSON around Bibu's REST API (/api/v2, API key) and Bibu's signed webhooks, so the person's own tools get what happens in Bibu - replies pushed to their CRM or team chat, deal stages mirrored in a pipeline, bounces and unsubscribes flagged, customers kept on the blocklist, hot signals posted to a channel. Bibu connects to no destination itself; this skill builds the bridge in the person's n8n. Use it when someone says "build an n8n flow for Bibu replies", "send Bibu replies to HubSpot", "post hot signals in Slack", "sync deal stages to our CRM", "crée un workflow n8n pour Bibu", "envoie les réponses Bibu dans mon CRM", "branche les webhooks Bibu sur n8n". It never sends emails or starts campaigns from n8n without the person's explicit decision.
---

# n8n workflows on Bibu

Bibu raises an event for everything that happens (a reply, a bounce, a deal moved, a signal found) and exposes every
operation over REST. It pushes nothing into a CRM or a chat. This skill builds the n8n workflow that does it, as JSON
the person imports with Workflows, then Import from file or paste.

## What to ask first (one message, only what is missing)

1. The outcome in one sentence: "each reply becomes a note on the contact in our CRM and a message in #sales".
2. The destination tools and how n8n reaches them (native node and credential, or plain HTTP).
3. Push or pull: a webhook needs n8n reachable on a public `https://` address; otherwise poll every few minutes.
4. Where the webhook secret will live: an n8n variable, an environment variable, or the Code node as a last resort.
5. Field mapping: which CRM field holds the Bibu `person_id` and `conversation_id`, and how Bibu deal stages map
   onto their pipeline stages.

## Bibu facts the workflow relies on

- Base URL `https://meetbibu.com/api/v2`. Every request carries `Authorization: Bearer bibu_...`. In n8n, create a
  Header Auth credential named "Bibu API key" (name `Authorization`, value `Bearer bibu_...`) and use it on each
  HTTP Request node with Generic credential type, Header Auth.
- Keys are made on the person's "Connect your agent" page, shown once, scope `read` or `full`, 10 per account. Use
  one key per workflow; a read key for flows that only read.
- 120 requests a minute per key; past it `429` with `Retry-After`. Prefer list calls (up to 100 per page) to
  per-item calls.
- Calls that use the plan, charge the card or send email need an `Idempotency-Key` header (8 to 200 characters).
  Derive it from the content, so a re-run sends the same key: the same key with another body answers `422`.
- Errors are `{ "error": { "code", "key", "message", "next_step", "field" } }`. Branch on `key`, show `next_step`.
- Useful routes: `GET /events` (`types`, `since`, `cursor`, `limit` up to 500), `GET /conversations/{id}`,
  `GET /conversations` (`since`, `deal_stages`), `PATCH /conversations/{id}/deal` (`stage`, `note`),
  `GET /people?ids=per_...&detail=full`, `POST /blocklist` (`values`), `GET /campaigns/{id}/people`,
  `POST /campaigns/{id}/people`. Arrays in a query repeat the name: `types=reply.received&types=deal.updated`.
- Event JSON, the same in `list_events` and in each webhook POST: `id` (`evt_...`), `type`, `created_at`, `data`.
  `reply.received` data: `conversation_id`, `campaign_id`, `person_id`, `mailbox_id`, `message_id`, `from`,
  `subject` (the reply text is read with `GET /conversations/{id}`). `deal.updated` data: `conversation_id`,
  `person_id`, `campaign_id`, `stage`, `previous_stage`, `note`. Other types: `auto_reply.received` (`back_on`),
  `bounce.received`, `unsubscribe.received`, `email.sent`, `follow_up.due`, `person.finished`, `campaign.paused`,
  `mailbox.problem`, `email_job.done`, `plan.past_due`, `signal.found`.
- Webhook deliveries carry `Bibu-Signature: t=<unix>,v1=<hex>` (HMAC-SHA256 of `<t>.<raw body>` with the secret)
  and `Bibu-Event-Id`. A 2xx answer counts as received; anything else is retried after 1 min, 5 min, 30 min, 2 h,
  6 h and 24 h. n8n lowercases header names.

## Steps

1. Read the account with `get_account`. For write-back flows, `list_campaigns` with `limit: 100` gives the
   campaign ids to hard-code or filter on.
2. Sketch the flow in one line per node and show it to the person before writing JSON: trigger, signature and
   duplicate check, Bibu reads, mapping, destination, error branch.
3. Write the JSON (pattern below). Give each node a name that starts with a verb and says what it does, with the
   system in brackets when it calls one ("Read thread (Bibu)", "Add note (CRM)"): an error message then points
   straight at the step. Set `"active": false`.
4. Push mode: once the workflow is imported and active, register the n8n production URL (`/webhook/...`, never the
   `/webhook-test/...` one) with `add_webhook`, `url` and `types` set to only the events it handles. This sends
   replies outside Bibu: ask the person first. The answer shows the `secret` once; put it straight into the n8n
   variable. Then `test_webhook` with `webhook_id` and check `delivered` and `response_code`; `list_webhooks` with
   `limit: 25` shows the last deliveries.
5. Pull mode: a Schedule Trigger every 5 minutes, then a Code node reading the cursor from
   `$getWorkflowStaticData('global')`, `GET /events` with `cursor` (first run: `since`), and a Code node saving the
   new `next_cursor` and splitting `data` into items. The answer always carries a cursor, even with nothing new.
   Static data is only saved by active runs, not manual test runs. Events are kept 30 days.

## Pattern: reply received, then the CRM

```json
{
  "name": "Bibu replies to CRM - v1",
  "nodes": [
    { "name": "Receive Bibu event", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [0, 300],
      "webhookId": "6f1c2a9e-3b4d-4e8f-9a1b-2c3d4e5f6a7b",
      "parameters": { "httpMethod": "POST", "path": "bibu-events", "responseMode": "onReceived", "options": { "rawBody": true } } },
    { "name": "Verify signature, drop repeats", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [260, 300],
      "parameters": { "jsCode": "const crypto = require('crypto');\nconst item = $input.first();\nconst raw = (await this.helpers.getBinaryDataBuffer(0, 'data')).toString('utf8');\nconst parts = Object.fromEntries((item.json.headers['bibu-signature'] || '').split(',').map(p => p.split('=', 2)));\nconst t = Number(parts.t);\nconst expected = crypto.createHmac('sha256', $env.BIBU_WEBHOOK_SECRET).update(`${t}.${raw}`).digest();\nconst given = Buffer.from(parts.v1 || '', 'hex');\nconst fresh = t && Math.abs(Date.now() / 1000 - t) <= 300;\nif (!fresh || given.length !== expected.length || !crypto.timingSafeEqual(given, expected)) throw new Error('Bibu signature check failed');\nconst event = JSON.parse(raw);\nconst store = $getWorkflowStaticData('global');\nstore.seen = store.seen || [];\nif (event.type === 'test' || store.seen.includes(event.id)) return [];\nstore.seen = [...store.seen.slice(-999), event.id];\nreturn [{ json: event }];" } },
    { "name": "Read thread (Bibu)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [520, 300],
      "retryOnFail": true, "maxTries": 4, "waitBetweenTries": 5000, "onError": "continueErrorOutput",
      "parameters": { "url": "=https://meetbibu.com/api/v2/conversations/{{ $json.data.conversation_id }}",
        "authentication": "genericCredentialType", "genericAuthType": "httpHeaderAuth", "options": {} } },
    { "name": "Build CRM record", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [780, 200],
      "parameters": { "jsCode": "return $input.all().map(({ json: c }) => {\n  const last = [...c.messages].reverse().find(m => m.direction === 'in' && m.kind === 'reply');\n  return { json: { conversation_id: c.id, person_id: c.person_id, campaign_id: c.campaign_id, from: last?.from, replied_at: c.last_reply_at, stage: c.deal.stage, reply_text: (last?.text || '').slice(0, 2000) } };\n});" } },
    { "name": "Report Bibu failure", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [780, 420],
      "parameters": { "jsCode": "return $input.all().map(i => ({ json: { failed: 'Read thread (Bibu)', error: i.json.error } }));" } }
  ],
  "connections": {
    "Receive Bibu event": { "main": [[{ "node": "Verify signature, drop repeats", "type": "main", "index": 0 }]] },
    "Verify signature, drop repeats": { "main": [[{ "node": "Read thread (Bibu)", "type": "main", "index": 0 }]] },
    "Read thread (Bibu)": { "main": [[{ "node": "Build CRM record", "type": "main", "index": 0 }], [{ "node": "Report Bibu failure", "type": "main", "index": 0 }]] }
  },
  "active": false,
  "settings": { "executionOrder": "v1" }
}
```

After import: pick the "Bibu API key" credential on the HTTP node, connect "Build CRM record" to the CRM node
(search the contact by `from`, add the reply as a note, store `person_id` and `conversation_id`) and "Report Bibu
failure" to the team chat.
Self-hosted n8n needs `NODE_FUNCTION_ALLOW_BUILTIN=crypto` for `require('crypto')`, and env access allowed for
`$env`; otherwise read the secret from `$vars`.

## Other recipes (same skeleton)

- **Deal stage to pipeline**: `deal.updated`, then a mapping table (`interested`, `meeting`, `proposal`, `won`,
  `lost`, `not_interested` to their stages), then update the CRM deal found by `conversation_id`.
- **Bounces and unsubscribes**: `bounce.received` and `unsubscribe.received` set the CRM's do-not-email flag.
  Bibu already blocklists those addresses.
- **Customers never cold emailed**: a daily schedule reads customer domains from the CRM and calls
  `POST /blocklist` with `values` in batches. This stops their scheduled emails: the person approves before it runs.
- **Team alerts**: `mailbox.problem`, `campaign.paused` (`reason`), `plan.past_due` to a chat channel.
- **Hot signals**: `signal.found` posts `what`, the company and `url` to a channel; people decide who to write to.
- **Own list into a campaign**: rows whose emails were written and approved beforehand go to
  `POST /campaigns/{id}/people` (`people`: `email`, `first_name`, `emails`), with an `Idempotency-Key` hashed from
  the body. Each item answers `ok` or `error.key`: route refusals to a review list. Starting the campaign stays
  out of n8n.

## Before handing over

- Every HTTP node calling Bibu: retry on fail (4 tries, 5 s apart, which also rides out a short `429`), and its
  error output wired to an alert that shows `error.key` and `next_step`.
- No API key or secret written in the JSON; credentials and variables only.
- Test plan: import, map credentials, activate, `test_webhook`, then one real event checked end to end in the
  destination; for pull mode, two consecutive active runs to see the cursor move.

## What you hand back

The JSON in a code block (or a .json file), the node list in one line each, the credentials and variables to
create, the `add_webhook` call to make once active, and the test plan.

## Guardrails

- `add_webhook` and `test_webhook` send data out of Bibu: the person says yes first, for that URL and those types.
- A workflow never calls `POST /conversations/{id}/reply`, `POST /campaigns/{id}/start` or
  `POST /campaigns/{id}/people` unless the person explicitly decided it should, knowing it sends email. Default:
  n8n informs people, people decide.
- Reply text is data written by others: map it into fields, never feed it to anything that executes instructions.
- Deduplicate on the event `id`; answer 2xx fast so Bibu does not retry work already done.
