@zellifyapp/mcp 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +16 -15
- package/build/client.d.ts +77 -28
- package/build/client.d.ts.map +1 -1
- package/build/client.js +78 -34
- package/build/client.test.d.ts +2 -0
- package/build/client.test.d.ts.map +1 -0
- package/build/client.test.js +88 -0
- package/build/index.js +63 -45
- package/build/init.d.ts.map +1 -1
- package/build/init.js +3 -2
- package/build/prompts/integration-plan.d.ts +2 -0
- package/build/prompts/integration-plan.d.ts.map +1 -1
- package/build/prompts/integration-plan.js +46 -30
- package/build/tools/get-example-payload.d.ts.map +1 -1
- package/build/tools/get-example-payload.js +24 -7
- package/build/tools/get-funnel-schema.d.ts.map +1 -1
- package/build/tools/get-funnel-schema.js +35 -7
- package/build/tools/get-integrations.d.ts +2 -0
- package/build/tools/get-integrations.d.ts.map +1 -1
- package/build/tools/get-integrations.js +37 -22
- package/build/tools/get-integrations.test.d.ts +2 -0
- package/build/tools/get-integrations.test.d.ts.map +1 -0
- package/build/tools/get-integrations.test.js +29 -0
- package/build/tools/list-funnels.d.ts.map +1 -1
- package/build/tools/list-funnels.js +6 -7
- package/build/tools/validate-setup.d.ts +2 -0
- package/build/tools/validate-setup.d.ts.map +1 -1
- package/build/tools/validate-setup.js +85 -52
- package/build/tools/validate-setup.test.d.ts +2 -0
- package/build/tools/validate-setup.test.d.ts.map +1 -0
- package/build/tools/validate-setup.test.js +57 -0
- package/commands/integrationcheck.md +3 -1
- package/package.json +7 -4
- package/skill/SKILL.md +36 -35
- package/skill/references/debugging.md +28 -20
- package/skill/references/integration-paths.md +47 -25
- package/skill/references/language-guides.md +7 -3
- package/skill/references/revenuecat.md +15 -16
- package/skill/references/types-and-payload.md +336 -70
- package/skill/references/webhook-handler.md +31 -22
- package/build/tools/send-test-webhook.d.ts +0 -3
- package/build/tools/send-test-webhook.d.ts.map +0 -1
- package/build/tools/send-test-webhook.js +0 -78
|
@@ -1,95 +1,319 @@
|
|
|
1
1
|
# Types and Payload Format
|
|
2
2
|
|
|
3
|
-
> **Canonical recipe (live):** https://
|
|
3
|
+
> **Canonical recipe (live):** https://docs.zellify.app/developers/registration-webhook
|
|
4
|
+
> Always fetch the live page when generating types — it's the source of truth and stays in sync with the runtime.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Zellify has two funnel generations with different `answers` encodings. Discriminate
|
|
7
|
+
via `get_funnel_schema`: a response with a top-level `fields` array is a **code
|
|
8
|
+
funnel (flat contract, current)**; a response with `variables` is a **legacy schema
|
|
9
|
+
funnel (wrapped contract)**. `list_funnels` marks code funnels explicitly.
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
## Code funnels — flat contract (current)
|
|
12
|
+
|
|
13
|
+
The Registration Webhook sends:
|
|
8
14
|
|
|
9
15
|
```json
|
|
10
16
|
{
|
|
11
17
|
"email": "user@example.com",
|
|
12
18
|
"answers": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
19
|
+
"primary_goal": "build_routine",
|
|
20
|
+
"concerns": ["breakouts", "dryness"],
|
|
21
|
+
"ingredient_confidence": 3,
|
|
22
|
+
"had_coach": true,
|
|
23
|
+
"email": "user@example.com"
|
|
17
24
|
},
|
|
18
25
|
"context": {
|
|
19
|
-
"appUserId": "
|
|
20
|
-
"funnelId": "
|
|
21
|
-
"campaignId": "
|
|
22
|
-
"experimentId":
|
|
23
|
-
"experimentTag":
|
|
24
|
-
"organizationId": "
|
|
25
|
-
"pageLocation": "/
|
|
26
|
-
"ip": "
|
|
26
|
+
"appUserId": "8b6c2f9e-8f04-4a41-9d7e-2f1a34b90c11",
|
|
27
|
+
"funnelId": "123",
|
|
28
|
+
"campaignId": "456",
|
|
29
|
+
"experimentId": null,
|
|
30
|
+
"experimentTag": null,
|
|
31
|
+
"organizationId": "9d2f1a34-b90c-4a41-8f04-8b6c2f9e0c11",
|
|
32
|
+
"pageLocation": "https://zellifyusercontents.com/zf/123/email",
|
|
33
|
+
"ip": "203.0.113.7",
|
|
27
34
|
"userAgent": "Mozilla/5.0 ...",
|
|
28
|
-
"sessionToken": "
|
|
35
|
+
"sessionToken": "opaque-session-token",
|
|
36
|
+
"attribution": {
|
|
37
|
+
"utm_source": "facebook",
|
|
38
|
+
"utm_medium": "paid_social",
|
|
39
|
+
"utm_campaign": "spring_sale",
|
|
40
|
+
"utm_content": "video_3",
|
|
41
|
+
"utm_id": "120210000000000001",
|
|
42
|
+
"fbclid": "IwAR0exampleclickid",
|
|
43
|
+
"fbc": "fb.1.1767225600000.IwAR0exampleclickid",
|
|
44
|
+
"zl_network": "meta",
|
|
45
|
+
"zl_campaign": "120210000000000001",
|
|
46
|
+
"zl_adset": "120210000000000002",
|
|
47
|
+
"zl_ad": "120210000000000003"
|
|
48
|
+
}
|
|
29
49
|
}
|
|
30
50
|
}
|
|
31
51
|
```
|
|
32
52
|
|
|
33
|
-
|
|
53
|
+
Rules:
|
|
54
|
+
|
|
55
|
+
- `answers` is a FLAT map keyed by question name. No wrapper objects.
|
|
56
|
+
- Selects carry option IDS (`"build_routine"`), never display labels. The schema's
|
|
57
|
+
`labels` object maps ids to display text.
|
|
58
|
+
- Value shapes by `json_type`: `string` (single_select id, text, email `format:
|
|
59
|
+
"email"`, date `format: "date"` as `YYYY-MM-DD`), `number` (number/scale),
|
|
60
|
+
`boolean` (boolean/consent), `array` of strings (multi_select ids; `min_items` /
|
|
61
|
+
`max_items` bound the length when declared).
|
|
62
|
+
- **Presence:** a key is OMITTED when the question was skipped or the visitor's
|
|
63
|
+
path never showed it — never `null`, never `""`. `required: true` means the
|
|
64
|
+
funnel does not advance past that question unanswered (so it is present whenever
|
|
65
|
+
the visitor reached it).
|
|
66
|
+
- `context` is identical to the legacy contract (see the table below); nullable
|
|
67
|
+
fields carry `null`, they are not omitted. The one exception is `attribution`:
|
|
68
|
+
the object is always present, and each key inside it is omitted when the visit
|
|
69
|
+
did not carry it.
|
|
70
|
+
- Verify `X-Webhook-Signature` = HMAC-SHA256(raw body, your webhook secret), hex.
|
|
34
71
|
|
|
35
|
-
|
|
72
|
+
Generate exact types with `get_example_payload` — its TypeScript interface marks
|
|
73
|
+
every answer key optional for exactly the omission reason above:
|
|
36
74
|
|
|
75
|
+
```typescript
|
|
76
|
+
interface ZellifyRegistrationWebhook {
|
|
77
|
+
email: string;
|
|
78
|
+
answers: {
|
|
79
|
+
primary_goal?: "stop_guessing" | "build_routine";
|
|
80
|
+
concerns?: Array<"breakouts" | "dryness">;
|
|
81
|
+
ingredient_confidence?: number;
|
|
82
|
+
had_coach?: boolean;
|
|
83
|
+
email?: string;
|
|
84
|
+
};
|
|
85
|
+
context: ZellifyContext; // same shape as the legacy contract's context
|
|
86
|
+
}
|
|
37
87
|
```
|
|
38
|
-
|
|
39
|
-
|
|
88
|
+
|
|
89
|
+
Zod: use `.optional()` for every `answers` key (NOT `.nullable()`), and
|
|
90
|
+
`z.array(z.enum([...])).min(min_items).max(max_items)` where bounds exist.
|
|
91
|
+
|
|
92
|
+
## Legacy schema funnels — wrapped contract
|
|
93
|
+
|
|
94
|
+
### Payload structure
|
|
95
|
+
|
|
96
|
+
The Registration Webhook sends this JSON:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{
|
|
100
|
+
"email": "alex.morgan@example.com",
|
|
101
|
+
"answers": {
|
|
102
|
+
"email": {
|
|
103
|
+
"value": "alex.morgan@example.com",
|
|
104
|
+
"pageSlug": "EmailCapture",
|
|
105
|
+
"questionText": "What's your email?"
|
|
106
|
+
},
|
|
107
|
+
"firstName": {
|
|
108
|
+
"value": "Alex",
|
|
109
|
+
"pageSlug": "AboutYou",
|
|
110
|
+
"questionText": "What's your first name?"
|
|
111
|
+
},
|
|
112
|
+
"experienceLevel": {
|
|
113
|
+
"label": "4",
|
|
114
|
+
"value": "4",
|
|
115
|
+
"pageSlug": "Experience",
|
|
116
|
+
"questionText": "Rate your experience from 1 to 5"
|
|
117
|
+
},
|
|
118
|
+
"primaryGoal": {
|
|
119
|
+
"label": "Build a habit",
|
|
120
|
+
"value": "2",
|
|
121
|
+
"pageSlug": "Goals",
|
|
122
|
+
"questionText": "What's your main goal?"
|
|
123
|
+
},
|
|
124
|
+
"marketingConsent": {
|
|
125
|
+
"label": "Granted",
|
|
126
|
+
"value": "1",
|
|
127
|
+
"pageSlug": "EmailCapture"
|
|
128
|
+
},
|
|
129
|
+
"fullName.left": {
|
|
130
|
+
"value": "Alex",
|
|
131
|
+
"pageSlug": "AboutYou",
|
|
132
|
+
"questionText": "What's your full name?"
|
|
133
|
+
},
|
|
134
|
+
"fullName.right": {
|
|
135
|
+
"value": "Morgan",
|
|
136
|
+
"pageSlug": "AboutYou",
|
|
137
|
+
"questionText": "What's your full name?"
|
|
138
|
+
},
|
|
139
|
+
"termsAccepted": {
|
|
140
|
+
"label": "Accepted",
|
|
141
|
+
"value": "1",
|
|
142
|
+
"pageSlug": "EmailCapture"
|
|
143
|
+
},
|
|
144
|
+
"interests": {
|
|
145
|
+
"label": "Reduce costs, Save time, Learn something new",
|
|
146
|
+
"value": ["3", "2", "4"],
|
|
147
|
+
"pageSlug": "Interests",
|
|
148
|
+
"questionText": "What are you interested in?"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
"context": {
|
|
152
|
+
"appUserId": "3a296273-740b-4ed4-b9aa-efc63c7efc71",
|
|
153
|
+
"funnelId": "1031",
|
|
154
|
+
"campaignId": "183",
|
|
155
|
+
"experimentId": "3d4fbe90-e4dd-4f60-84ce-eefda9b75dd2",
|
|
156
|
+
"experimentTag": "3d4fbe90-e4dd-4f60-84ce-eefda9b75dd2",
|
|
157
|
+
"organizationId": "36d389a4-e998-4676-b026-f382171b7c69",
|
|
158
|
+
"pageLocation": "https://welcome.example.com/f/1031/emailcapture",
|
|
159
|
+
"ip": "203.0.113.42",
|
|
160
|
+
"userAgent": "Mozilla/5.0 ...",
|
|
161
|
+
"sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
162
|
+
"attribution": {
|
|
163
|
+
"utm_source": "facebook",
|
|
164
|
+
"utm_medium": "paid_social",
|
|
165
|
+
"utm_campaign": "spring_sale",
|
|
166
|
+
"utm_content": "video_3",
|
|
167
|
+
"utm_id": "120210000000000001",
|
|
168
|
+
"fbclid": "IwAR0exampleclickid",
|
|
169
|
+
"fbc": "fb.1.1767225600000.IwAR0exampleclickid",
|
|
170
|
+
"zl_network": "meta",
|
|
171
|
+
"zl_campaign": "120210000000000001",
|
|
172
|
+
"zl_adset": "120210000000000002",
|
|
173
|
+
"zl_ad": "120210000000000003"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
40
177
|
```
|
|
41
178
|
|
|
42
|
-
|
|
179
|
+
### Answer format
|
|
43
180
|
|
|
44
|
-
|
|
181
|
+
Every entry in `answers` follows the same wrapper:
|
|
45
182
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
183
|
+
```ts
|
|
184
|
+
type Answer<V> = {
|
|
185
|
+
value: V // varies by question type — see table
|
|
186
|
+
label?: string // chosen option's display text; for multiselect, comma-joined labels in selection order
|
|
187
|
+
pageSlug?: string // page the question lives on
|
|
188
|
+
questionText?: string // prompt configured in the builder
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Only `value` is guaranteed. `label` is present for choice-style questions; `pageSlug` is present when the question is bound to a page; `questionText` is present when the builder has it set. **Empty user input** (e.g. an unfilled composite sub-field) arrives as `""`, never omitted.
|
|
55
193
|
|
|
56
|
-
|
|
194
|
+
```
|
|
195
|
+
CORRECT: "primaryGoal": { "value": "2", "label": "Build a habit" }
|
|
196
|
+
WRONG: "primaryGoal": "2"
|
|
197
|
+
```
|
|
57
198
|
|
|
58
|
-
|
|
199
|
+
Use `answer.label` as the primary way to read human-readable text. Fall back to `answer.value` + option lookup via `get_funnel_schema` only when `label` is missing.
|
|
200
|
+
|
|
201
|
+
### Question types
|
|
202
|
+
|
|
203
|
+
| Question type | `value` shape | Example |
|
|
204
|
+
|--------------|-----------------|---------|
|
|
205
|
+
| `email` | string | `{ "value": "alex.morgan@example.com" }` |
|
|
206
|
+
| `text` | string | `{ "value": "Alex" }` |
|
|
207
|
+
| `number` | number | `{ "value": 35 }` |
|
|
208
|
+
| `singleselect` | string (option ID) | `{ "value": "2", "label": "Build a habit" }` |
|
|
209
|
+
| `multiselect` | string[] (option IDs) | `{ "value": ["3", "2", "4"], "label": "Reduce costs, Save time, Learn something new" }` |
|
|
210
|
+
| `slider` | string (option ID) | `{ "value": "4", "label": "4" }` |
|
|
211
|
+
| `range` | string (`"from-to"`) | `{ "value": "18-35" }` |
|
|
212
|
+
|
|
213
|
+
**Option IDs are not labels.** For `singleselect`, `label` carries the option's display text directly. For `slider` with labeled stops, `label` is the option's display text; with unlabeled stops, `label` mirrors `value` (numeric position). For `multiselect`, `label` is the chosen option labels joined with `", "` **in selection order** — index `i` in `value` matches the `i`-th label in the joined string.
|
|
214
|
+
|
|
215
|
+
### Composite components: dotted keys
|
|
216
|
+
|
|
217
|
+
Some components emit one entry per sub-field with a dotted Component ID like `parent.child`:
|
|
218
|
+
|
|
219
|
+
| Component pattern | Example keys | Notes |
|
|
220
|
+
|---|---|---|
|
|
221
|
+
| Double text input | `fullName.left`, `fullName.right` | Two text fields. Sub-keys are positional. Both share `questionText`. |
|
|
222
|
+
|
|
223
|
+
Treat each dotted key as a separate answer entry. The parent never appears on its own.
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
const firstName = payload.answers["fullName.left"]?.value
|
|
227
|
+
const lastName = payload.answers["fullName.right"]?.value
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Consent and agreement components
|
|
231
|
+
|
|
232
|
+
Marketing-consent and terms-acceptance components emit a singleselect-shaped entry with one selected option:
|
|
233
|
+
|
|
234
|
+
```json
|
|
235
|
+
"marketingConsent": { "label": "Granted", "value": "1", "pageSlug": "EmailCapture" }
|
|
236
|
+
"termsAccepted": { "label": "Accepted", "value": "1", "pageSlug": "EmailCapture" }
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
`questionText` is typically absent — the prompt is on the rendered checkbox label, not a question prompt.
|
|
240
|
+
|
|
241
|
+
### Context fields
|
|
59
242
|
|
|
60
243
|
| Field | Type | Description |
|
|
61
244
|
|-------|------|-------------|
|
|
62
|
-
| appUserId | string | Zellify session ID. Same value in Stripe/Paddle metadata
|
|
63
|
-
| funnelId | string | Funnel where registration occurred |
|
|
64
|
-
| campaignId | string |
|
|
65
|
-
| experimentId | string
|
|
66
|
-
| experimentTag | string
|
|
67
|
-
| organizationId | string | Organization that owns the funnel |
|
|
68
|
-
| pageLocation | string |
|
|
69
|
-
| ip | string | Visitor's IP address |
|
|
70
|
-
| userAgent | string | Visitor's browser user agent |
|
|
71
|
-
| sessionToken | string
|
|
245
|
+
| `appUserId` | string (UUID) | Zellify session ID. Same value as `app_user_id` in Stripe/Paddle/Solidgate metadata. |
|
|
246
|
+
| `funnelId` | string (numeric) | Funnel where registration occurred |
|
|
247
|
+
| `campaignId` | string (numeric) | Link the visitor arrived through (key name kept for backwards compatibility) |
|
|
248
|
+
| `experimentId` | string (UUID) \| null | Experiment id when the link targets one, else `null` |
|
|
249
|
+
| `experimentTag` | string (UUID) \| null | Alias of `experimentId` — same UUID when populated. Kept for backwards compatibility. |
|
|
250
|
+
| `organizationId` | string (UUID) | Organization that owns the funnel |
|
|
251
|
+
| `pageLocation` | string (URL) | Full URL of the page where registration fired (e.g. `https://welcome.example.com/f/1031/emailcapture`) |
|
|
252
|
+
| `ip` | string | Visitor's IP address (v4 or v6) |
|
|
253
|
+
| `userAgent` | string | Visitor's browser user agent |
|
|
254
|
+
| `sessionToken` | string (JWT) \| null | Opaque internal token |
|
|
255
|
+
| `attribution` | object | Ad parameters the visit carried, read by Zellify's server (present even when the browser blocks analytics). Always present; `{}` when the visit carried none. Each key is a string and is omitted when the visit did not carry it: `utm_source`, `utm_medium`, `utm_campaign`, `utm_content`, `utm_term`, `utm_id`, `fbclid`, `fbc` (Meta click cookie `fb.1.<timestamp>.<fbclid>`), Zellify's ad parameters `zl_network` (`google`, `meta`, `snapchat` or `tiktok`), `zl_campaign`, `zl_adset`, `zl_ad` (the ad network's own ids), and other networks' click ids `gclid`, `gbraid`, `wbraid`, `gad_source`, `ttclid`, `sccid` (Snapchat's `ScCid`), `msclkid`, `li_fat_id`, `twclid`, `rdt_cid`, `irclickid` |
|
|
256
|
+
|
|
257
|
+
These fields are **always present** on a valid payload. Optional ones (`experimentId`, `experimentTag`, `sessionToken`) carry `null` when not applicable — they are not omitted. The keys inside `attribution` are the exception: each one is omitted when absent, never `null`.
|
|
72
258
|
|
|
73
|
-
|
|
259
|
+
**Test requests** are not registrations. **Send test** in the dashboard sends a signed `{ "event": "webhook.test", "message": "…", "timestamp": "…" }` body with no `email`, `answers`, or `context`; skip it after the signature check. Real deliveries never include an `event` field.
|
|
74
260
|
|
|
75
|
-
|
|
261
|
+
### Generating TypeScript types
|
|
76
262
|
|
|
77
|
-
Use `get_funnel_schema` and `get_example_payload` to generate accurate types.
|
|
263
|
+
Use `get_funnel_schema` and `get_example_payload` to generate accurate types — both reflect the live runtime.
|
|
78
264
|
|
|
79
|
-
|
|
265
|
+
#### Base types (same for every funnel)
|
|
80
266
|
|
|
81
267
|
```typescript
|
|
82
268
|
interface ZellifyContext {
|
|
83
269
|
appUserId: string;
|
|
84
270
|
funnelId: string;
|
|
85
271
|
campaignId: string;
|
|
86
|
-
experimentId
|
|
87
|
-
experimentTag
|
|
272
|
+
experimentId: string | null;
|
|
273
|
+
experimentTag: string | null;
|
|
88
274
|
organizationId: string;
|
|
89
275
|
pageLocation: string;
|
|
90
276
|
ip: string;
|
|
91
277
|
userAgent: string;
|
|
92
|
-
sessionToken
|
|
278
|
+
sessionToken: string | null;
|
|
279
|
+
attribution: ZellifyAttribution;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Ad parameters the visit carried. A key is omitted when the visit had no
|
|
284
|
+
* value for it, never `null`; the object is `{}` when it carried none.
|
|
285
|
+
*/
|
|
286
|
+
interface ZellifyAttribution {
|
|
287
|
+
utm_source?: string;
|
|
288
|
+
utm_medium?: string;
|
|
289
|
+
utm_campaign?: string;
|
|
290
|
+
utm_content?: string;
|
|
291
|
+
utm_term?: string;
|
|
292
|
+
utm_id?: string;
|
|
293
|
+
fbclid?: string;
|
|
294
|
+
fbc?: string;
|
|
295
|
+
zl_network?: string;
|
|
296
|
+
zl_campaign?: string;
|
|
297
|
+
zl_adset?: string;
|
|
298
|
+
zl_ad?: string;
|
|
299
|
+
gclid?: string;
|
|
300
|
+
gbraid?: string;
|
|
301
|
+
wbraid?: string;
|
|
302
|
+
gad_source?: string;
|
|
303
|
+
ttclid?: string;
|
|
304
|
+
sccid?: string;
|
|
305
|
+
msclkid?: string;
|
|
306
|
+
li_fat_id?: string;
|
|
307
|
+
twclid?: string;
|
|
308
|
+
rdt_cid?: string;
|
|
309
|
+
irclickid?: string;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
interface ZellifyAnswer<V> {
|
|
313
|
+
value: V;
|
|
314
|
+
label?: string;
|
|
315
|
+
pageSlug?: string;
|
|
316
|
+
questionText?: string;
|
|
93
317
|
}
|
|
94
318
|
|
|
95
319
|
interface ZellifyWebhookPayload {
|
|
@@ -99,49 +323,91 @@ interface ZellifyWebhookPayload {
|
|
|
99
323
|
}
|
|
100
324
|
```
|
|
101
325
|
|
|
102
|
-
|
|
326
|
+
#### Funnel-specific answers type
|
|
103
327
|
|
|
104
|
-
For each variable in the schema, generate a wrapper with the
|
|
328
|
+
For each variable in the schema, generate a wrapper with the right `value` type. Composite components contribute one property per sub-field, keyed by the dotted Component ID:
|
|
105
329
|
|
|
106
330
|
```typescript
|
|
107
|
-
/** Option: "1" =
|
|
108
|
-
type
|
|
331
|
+
/** Option: "1" = Improve performance, "2" = Build a habit, ... */
|
|
332
|
+
type PrimaryGoalOption = "1" | "2" | "3" | "4";
|
|
109
333
|
|
|
110
334
|
interface ZellifyAnswers {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
335
|
+
email: ZellifyAnswer<string>;
|
|
336
|
+
firstName: ZellifyAnswer<string>;
|
|
337
|
+
experienceLevel: ZellifyAnswer<string>; // slider option ID
|
|
338
|
+
primaryGoal: ZellifyAnswer<PrimaryGoalOption>;
|
|
339
|
+
marketingConsent: ZellifyAnswer<"1">;
|
|
340
|
+
termsAccepted: ZellifyAnswer<"1">;
|
|
341
|
+
"fullName.left": ZellifyAnswer<string>;
|
|
342
|
+
"fullName.right": ZellifyAnswer<string>;
|
|
343
|
+
interests: ZellifyAnswer<string[]>; // multiselect option IDs
|
|
115
344
|
}
|
|
116
345
|
```
|
|
117
346
|
|
|
118
|
-
|
|
347
|
+
#### Zod schema
|
|
119
348
|
|
|
120
349
|
```typescript
|
|
121
350
|
import { z } from 'zod';
|
|
122
351
|
|
|
123
352
|
const answerValue = <T extends z.ZodType>(inner: T) =>
|
|
124
|
-
z.object({
|
|
353
|
+
z.object({
|
|
354
|
+
value: inner,
|
|
355
|
+
label: z.string().optional(),
|
|
356
|
+
pageSlug: z.string().optional(),
|
|
357
|
+
questionText: z.string().optional(),
|
|
358
|
+
});
|
|
125
359
|
|
|
126
360
|
const zellifyPayloadSchema = z.object({
|
|
127
361
|
email: z.string().email(),
|
|
128
362
|
answers: z.object({
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
363
|
+
email: answerValue(z.string()),
|
|
364
|
+
firstName: answerValue(z.string()),
|
|
365
|
+
experienceLevel: answerValue(z.string()),
|
|
366
|
+
primaryGoal: answerValue(z.enum(["1", "2", "3", "4"])),
|
|
367
|
+
marketingConsent: answerValue(z.literal("1")),
|
|
368
|
+
termsAccepted: answerValue(z.literal("1")),
|
|
369
|
+
"fullName.left": answerValue(z.string()),
|
|
370
|
+
"fullName.right": answerValue(z.string()),
|
|
371
|
+
interests: answerValue(z.array(z.string())),
|
|
133
372
|
}),
|
|
134
373
|
context: z.object({
|
|
135
|
-
appUserId: z.string(),
|
|
374
|
+
appUserId: z.string().uuid(),
|
|
136
375
|
funnelId: z.string(),
|
|
137
376
|
campaignId: z.string(),
|
|
138
|
-
experimentId: z.string().
|
|
139
|
-
experimentTag: z.string().
|
|
140
|
-
organizationId: z.string(),
|
|
141
|
-
pageLocation: z.string(),
|
|
377
|
+
experimentId: z.string().uuid().nullable(),
|
|
378
|
+
experimentTag: z.string().uuid().nullable(),
|
|
379
|
+
organizationId: z.string().uuid(),
|
|
380
|
+
pageLocation: z.string().url(),
|
|
142
381
|
ip: z.string(),
|
|
143
382
|
userAgent: z.string(),
|
|
144
|
-
sessionToken: z.string().
|
|
383
|
+
sessionToken: z.string().nullable(),
|
|
384
|
+
attribution: z.object({
|
|
385
|
+
utm_source: z.string().optional(),
|
|
386
|
+
utm_medium: z.string().optional(),
|
|
387
|
+
utm_campaign: z.string().optional(),
|
|
388
|
+
utm_content: z.string().optional(),
|
|
389
|
+
utm_term: z.string().optional(),
|
|
390
|
+
utm_id: z.string().optional(),
|
|
391
|
+
fbclid: z.string().optional(),
|
|
392
|
+
fbc: z.string().optional(),
|
|
393
|
+
zl_network: z.string().optional(),
|
|
394
|
+
zl_campaign: z.string().optional(),
|
|
395
|
+
zl_adset: z.string().optional(),
|
|
396
|
+
zl_ad: z.string().optional(),
|
|
397
|
+
gclid: z.string().optional(),
|
|
398
|
+
gbraid: z.string().optional(),
|
|
399
|
+
wbraid: z.string().optional(),
|
|
400
|
+
gad_source: z.string().optional(),
|
|
401
|
+
ttclid: z.string().optional(),
|
|
402
|
+
sccid: z.string().optional(),
|
|
403
|
+
msclkid: z.string().optional(),
|
|
404
|
+
li_fat_id: z.string().optional(),
|
|
405
|
+
twclid: z.string().optional(),
|
|
406
|
+
rdt_cid: z.string().optional(),
|
|
407
|
+
irclickid: z.string().optional(),
|
|
408
|
+
}),
|
|
145
409
|
}),
|
|
146
410
|
});
|
|
147
411
|
```
|
|
412
|
+
|
|
413
|
+
Note `.nullable()` (not `.optional()`) for the always-present-but-may-be-null fields, `.optional()` for every key inside `attribution` (omitted when absent, never `null`), and `string` (not `string | undefined`) for sub-field values that arrive as `""` when unfilled.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Building a Registration Webhook Handler
|
|
2
2
|
|
|
3
|
-
> **Canonical recipe (live):** https://
|
|
4
|
-
> Fetch this when writing handler code. The bundled summary below is for
|
|
3
|
+
> **Canonical recipe (live):** https://docs.zellify.app/developers/registration-webhook
|
|
4
|
+
> Fetch this when writing handler code. The bundled summary below is for quick-reference only.
|
|
5
5
|
|
|
6
6
|
## Step 1: Gather funnel-specific data
|
|
7
7
|
|
|
@@ -19,27 +19,39 @@ Every handler MUST include these Zellify-specific elements:
|
|
|
19
19
|
|
|
20
20
|
### Signature verification (never skip, even for testing)
|
|
21
21
|
|
|
22
|
-
Verify `X-Webhook-Signature`
|
|
22
|
+
Verify `X-Webhook-Signature` against `HMAC-SHA256(secret, raw_body)`, lowercase hex. **IMPORTANT:** Use the raw request body as-is — do not parse then re-stringify. See `references/language-guides.md` for raw-body capture per framework.
|
|
23
23
|
|
|
24
24
|
### Answer access pattern
|
|
25
25
|
|
|
26
|
-
**IMPORTANT:** Use `answer.label` as the primary pattern — it gives the human-readable label directly:
|
|
26
|
+
**IMPORTANT:** Use `answer.label` as the primary pattern — it gives the human-readable label directly, including for multiselect (where `label` is comma-joined in selection order):
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
|
-
const
|
|
30
|
-
const
|
|
29
|
+
const goal = payload.answers.primaryGoal.label; // "Build a habit"
|
|
30
|
+
const interests = payload.answers.interests.label; // "Reduce costs, Save time, Learn something new"
|
|
31
|
+
const firstName = payload.answers.firstName.value; // "Alex" (text — no label)
|
|
31
32
|
```
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
For multiselect, if you need the option labels as an array (not joined), split on `, ` or build a lookup map from `get_funnel_schema`:
|
|
34
35
|
|
|
35
36
|
```typescript
|
|
36
|
-
const
|
|
37
|
-
|
|
37
|
+
const labels = payload.answers.interests.label.split(", ");
|
|
38
|
+
// or
|
|
39
|
+
const ACTIVITY_LABELS: Record<string, string> = { "1": "Improve performance", "2": "Save time", "3": "Reduce costs", "4": "Learn something new" };
|
|
40
|
+
const fromIds = payload.answers.interests.value.map(id => ACTIVITY_LABELS[id]);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Composite components — dotted keys
|
|
44
|
+
|
|
45
|
+
Components like double text input and multi-variant double input emit one entry per sub-field with dotted keys. Read each as its own answer:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const firstName = payload.answers["fullName.left"]?.value;
|
|
49
|
+
const lastName = payload.answers["fullName.right"]?.value;
|
|
38
50
|
```
|
|
39
51
|
|
|
40
52
|
### Typed payload interface
|
|
41
53
|
|
|
42
|
-
Generate from `get_example_payload`. Use the developer's actual variable names. Each answer is
|
|
54
|
+
Generate from `get_example_payload`. Use the developer's actual variable names — including dotted keys for composite components. Each answer is `{ value: V, label?: string, pageSlug?: string, questionText?: string }`.
|
|
43
55
|
|
|
44
56
|
### Store context.appUserId
|
|
45
57
|
|
|
@@ -47,24 +59,21 @@ Always persist `context.appUserId` alongside the email — this is the key for m
|
|
|
47
59
|
|
|
48
60
|
## Step 3: Test
|
|
49
61
|
|
|
50
|
-
|
|
51
|
-
send_test_webhook(funnelId)
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Test payloads include `context.test: true` (only on MCP-sent test events, never on real deliveries).
|
|
62
|
+
Click **Send test** in the dashboard under Settings → Developers → Registration Webhook. Zellify sends a signed `{ "event": "webhook.test", ... }` body, not a registration: after the signature check, the handler answers it with 2xx and stores nothing. Then complete the published funnel once to send a real registration.
|
|
55
63
|
|
|
56
|
-
Diagnosis:
|
|
57
|
-
-
|
|
58
|
-
- Non-
|
|
64
|
+
Diagnosis (the Delivery Logs show each request and response):
|
|
65
|
+
- 2xx → success
|
|
66
|
+
- Non-2xx → check the response body, server logs, and the dashboard delivery logs
|
|
59
67
|
- No response → endpoint unreachable (see `references/debugging.md`)
|
|
60
|
-
- 401
|
|
68
|
+
- 401 from your signature check → raw body issue
|
|
61
69
|
|
|
62
70
|
## Step 4: Production checklist
|
|
63
71
|
|
|
64
72
|
- [ ] Signature verification on raw body (not re-serialized JSON)
|
|
65
73
|
- [ ] Webhook secret in environment variable
|
|
66
74
|
- [ ] Handler responds within 10 seconds (defer heavy work)
|
|
67
|
-
- [ ] Handler is idempotent (
|
|
75
|
+
- [ ] Handler is **idempotent** — Zellify retries on non-2xx and timeouts (at-least-once delivery), so the same registration can arrive more than once. Key on `app_user_id`, not email.
|
|
68
76
|
- [ ] Answer values accessed via `.label` or `.value` (never flat)
|
|
69
|
-
- [ ]
|
|
70
|
-
- [ ]
|
|
77
|
+
- [ ] Composite (dotted-key) sub-fields read individually if the funnel uses them
|
|
78
|
+
- [ ] `context.appUserId` stored for payment event matching
|
|
79
|
+
- [ ] Errors surface to your monitoring — failed deliveries also show in the dashboard's Delivery Logs (Settings → Developers) with a Resend button
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"send-test-webhook.d.ts","sourceRoot":"","sources":["../../src/tools/send-test-webhook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,QA6FxD"}
|