getricky 0.1.28 → 0.1.30

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.
@@ -26,233 +26,834 @@ export type Error = {
26
26
  };
27
27
  };
28
28
  /**
29
- * A campaign of a connected ad account.
29
+ * The ad as Ricky's Meta Ads sync last stored it, matched by `ad_id`. It is Ricky's lookup in the connected ad account, not part of the message Meta sent. `GET /ads/ads` reads the same ad live from Meta.
30
30
  */
31
- export type MetaAdsCampaign = {
31
+ export type AdReferralResolution = {
32
+ /**
33
+ * Name of the ad in Meta.
34
+ */
35
+ ad_name: string | null;
32
36
  /**
33
37
  * Campaign ID at Meta.
34
38
  */
35
- id: string;
39
+ campaign_id: string | null;
36
40
  /**
37
- * Ad account ID at Meta.
41
+ * Campaign name in Meta.
38
42
  */
39
- account_id: string;
43
+ campaign_name: string | null;
40
44
  /**
41
- * Name in Meta.
45
+ * Ad set ID at Meta.
42
46
  */
43
- name: string;
47
+ ad_set_id: string | null;
44
48
  /**
45
- * Objective, such as `OUTCOME_ENGAGEMENT`.
49
+ * Ad set name in Meta.
46
50
  */
47
- objective: string | null;
51
+ ad_set_name: string | null;
48
52
  /**
49
- * Status the advertiser set: `ACTIVE`, `PAUSED`, …
53
+ * Ad account ID at Meta.
50
54
  */
51
- status: string;
55
+ ad_account_id: string | null;
52
56
  /**
53
- * Delivery status, including a parent paused: `ACTIVE`, `CAMPAIGN_PAUSED`, …
57
+ * When Ricky last synced this ad from Meta.
54
58
  */
55
- effective_status: string;
59
+ synced_at: string | null;
60
+ };
61
+ /**
62
+ * A Meta ad a customer came from: an inbound message whose Meta referral names an ad (Click to WhatsApp, Instagram or Messenger ads). The same definition as `GET /reports/ads`.
63
+ */
64
+ export type AdReferral = {
56
65
  /**
57
- * `AUCTION` or `RESERVED`.
66
+ * Meta's ID of the ad, as Meta sent it in the message's referral: WhatsApp `source_id`, Instagram and Messenger `ad_id`. The same ID as `GET /ads/ads` and `ad_id` in `GET /ads/insights`.
58
67
  */
59
- buying_type: string | null;
68
+ ad_id: string;
60
69
  /**
61
- * Bid strategy, when the campaign sets one.
70
+ * Channel the customer wrote on.
62
71
  */
63
- bid_strategy: string | null;
72
+ channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
64
73
  /**
65
- * Budget as Meta reports it, in the ad account currency.
74
+ * The customer message that carried the referral.
66
75
  */
67
- budget: {
68
- /**
69
- * Daily budget in the account currency; null when not set.
70
- */
71
- daily: number | null;
72
- /**
73
- * Lifetime budget in the account currency; null when not set.
74
- */
75
- lifetime: number | null;
76
- /**
77
- * Budget left in the account currency.
78
- */
79
- remaining: number | null;
80
- };
76
+ message_id: string;
81
77
  /**
82
- * ISO 8601 time as Meta reports it; null if unset.
78
+ * Conversation of that message.
83
79
  */
84
- start_time: string | null;
80
+ conversation_id: string;
81
+ contact_id: string | null;
85
82
  /**
86
- * ISO 8601 time as Meta reports it; null if unset.
83
+ * When the customer sent that message.
87
84
  */
88
- stop_time: string | null;
85
+ referred_at: string;
89
86
  /**
90
- * ISO 8601 time as Meta reports it; null if unset.
87
+ * Meta's kind of source: WhatsApp's `source_type` (`ad`) or Instagram and Messenger's `source` (`ADS`).
91
88
  */
92
- created_time: string | null;
89
+ source_type: string | null;
93
90
  /**
94
- * ISO 8601 time as Meta reports it; null if unset.
91
+ * Link to the ad's post on Facebook or Instagram, as Meta sent it. WhatsApp only.
95
92
  */
96
- updated_time: string | null;
97
- };
98
- /**
99
- * An ad set of a connected ad account.
100
- */
101
- export type MetaAdsAdSet = {
93
+ source_url: string | null;
102
94
  /**
103
- * Ad set ID at Meta.
95
+ * The ad's title as Meta sent it: WhatsApp `headline`, Instagram and Messenger `ads_context_data.ad_title`.
104
96
  */
105
- id: string;
97
+ headline: string | null;
106
98
  /**
107
- * Ad account ID at Meta.
99
+ * The ad's text as Meta sent it. WhatsApp only.
108
100
  */
109
- account_id: string;
101
+ body: string | null;
110
102
  /**
111
- * Campaign ID at Meta.
103
+ * `image` or `video`, as Meta sent it. WhatsApp only.
112
104
  */
113
- campaign_id: string;
105
+ media_type: string | null;
114
106
  /**
115
- * Name in Meta.
107
+ * The ad's image: Ricky's permanent copy of the image Meta sent, else Meta's own link while it has not expired; null otherwise.
116
108
  */
117
- name: string;
109
+ image_url: string | null;
118
110
  /**
119
- * Status the advertiser set: `ACTIVE`, `PAUSED`, …
111
+ * Meta's link to the ad's video, as Meta sent it; it can expire.
120
112
  */
121
- status: string;
113
+ video_url: string | null;
122
114
  /**
123
- * Delivery status, including a parent paused: `ACTIVE`, `CAMPAIGN_PAUSED`, …
115
+ * Meta's click ID of the Click to WhatsApp ad, as Meta sent it; send it back to Meta's Conversions API to attribute an event. WhatsApp only.
124
116
  */
125
- effective_status: string;
117
+ ctwa_clid: string | null;
126
118
  /**
127
- * What Meta optimizes delivery for.
119
+ * The `ref` parameter of the ad link, as Meta sent it. Instagram and Messenger only.
128
120
  */
129
- optimization_goal: string | null;
121
+ ref: string | null;
130
122
  /**
131
- * What Meta charges for.
123
+ * The ad's name, campaign and ad set from Ricky's Meta Ads sync; null when the ad is not in a connected ad account Ricky has synced.
132
124
  */
133
- billing_event: string | null;
125
+ resolved: AdReferralResolution | null;
126
+ };
127
+ /**
128
+ * The days a report covers, in America/Panama time, and the period it is compared with.
129
+ */
130
+ export type ReportPeriod = {
134
131
  /**
135
- * Bid strategy, when the campaign sets one.
132
+ * First day, inclusive.
136
133
  */
137
- bid_strategy: string | null;
134
+ from: string;
138
135
  /**
139
- * Budget as Meta reports it, in the ad account currency.
136
+ * Last day, inclusive. A `to` after today is today.
140
137
  */
141
- budget: {
142
- /**
143
- * Daily budget in the account currency; null when not set.
144
- */
145
- daily: number | null;
146
- /**
147
- * Lifetime budget in the account currency; null when not set.
148
- */
149
- lifetime: number | null;
150
- /**
151
- * Budget left in the account currency.
152
- */
153
- remaining: number | null;
154
- };
138
+ to: string;
155
139
  /**
156
- * ISO 8601 time as Meta reports it; null if unset.
140
+ * Days in the period.
157
141
  */
158
- start_time: string | null;
142
+ days: number;
159
143
  /**
160
- * ISO 8601 time as Meta reports it; null if unset.
144
+ * `hour` when the period is one day: series then have 24 hourly slots.
161
145
  */
162
- end_time: string | null;
146
+ granularity: 'day' | 'hour';
163
147
  /**
164
- * Meta's targeting spec as Meta returns it: ages, locations, interests, …
148
+ * The time zone of every day and hour in the report.
165
149
  */
166
- targeting: unknown;
150
+ time_zone: 'America/Panama';
167
151
  /**
168
- * ISO 8601 time as Meta reports it; null if unset.
152
+ * First day of the previous period: the same number of days, right before.
169
153
  */
170
- created_time: string | null;
154
+ previous_from: string;
171
155
  /**
172
- * ISO 8601 time as Meta reports it; null if unset.
156
+ * Last day of the previous period.
173
157
  */
174
- updated_time: string | null;
158
+ previous_to: string;
175
159
  };
176
160
  /**
177
- * An ad of a connected ad account, with its creative copy.
161
+ * How many customers write, whether they are new, and when. Only messages customers send count: a customer is a conversation with at least one of them in the period, and it is new when its first message ever falls in the period. Messages from the team, AI agents or campaigns and conversation openings and closes play no part.
178
162
  */
179
- export type MetaAdsAd = {
180
- /**
181
- * Ad ID at Meta.
182
- */
183
- id: string;
184
- /**
185
- * Ad account ID at Meta.
186
- */
187
- account_id: string;
188
- /**
189
- * Campaign ID at Meta.
190
- */
191
- campaign_id: string;
192
- /**
193
- * Ad set ID at Meta.
194
- */
195
- ad_set_id: string;
163
+ export type ConversationsReport = {
164
+ period: ReportPeriod;
196
165
  /**
197
- * Name in Meta.
166
+ * The channel filter the report applied.
198
167
  */
199
- name: string;
168
+ channel: 'all' | 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
200
169
  /**
201
- * Status the advertiser set: `ACTIVE`, `PAUSED`, …
170
+ * The period.
202
171
  */
203
- status: string;
172
+ totals: {
173
+ /**
174
+ * Conversations with at least one customer message in the period.
175
+ */
176
+ customers: number;
177
+ /**
178
+ * Customers whose first message ever falls in the period.
179
+ */
180
+ new_customers: number;
181
+ /**
182
+ * Customers who had written before the period.
183
+ */
184
+ returning_customers: number;
185
+ /**
186
+ * Messages customers sent in the period.
187
+ */
188
+ messages: number;
189
+ };
204
190
  /**
205
- * Delivery status, including a parent paused: `ACTIVE`, `CAMPAIGN_PAUSED`, …
191
+ * The previous period.
206
192
  */
207
- effective_status: string;
193
+ previous: {
194
+ /**
195
+ * Conversations with at least one customer message in the period.
196
+ */
197
+ customers: number;
198
+ /**
199
+ * Customers whose first message ever falls in the period.
200
+ */
201
+ new_customers: number;
202
+ /**
203
+ * Customers who had written before the period.
204
+ */
205
+ returning_customers: number;
206
+ /**
207
+ * Messages customers sent in the period.
208
+ */
209
+ messages: number;
210
+ };
208
211
  /**
209
- * The creative the ad runs; null when Meta returns none.
212
+ * The period per channel, most customers first.
210
213
  */
211
- creative: {
214
+ by_channel: Array<{
212
215
  /**
213
- * Creative ID at Meta.
216
+ * Channel.
214
217
  */
215
- id: string;
218
+ channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
216
219
  /**
217
- * Headline.
220
+ * Conversations with at least one customer message in the period.
218
221
  */
219
- title: string | null;
222
+ customers: number;
220
223
  /**
221
- * Primary text.
224
+ * Customers whose first message ever falls in the period.
222
225
  */
223
- body: string | null;
226
+ new_customers: number;
224
227
  /**
225
- * Button, such as `LEARN_MORE`.
228
+ * Customers who had written before the period.
226
229
  */
227
- call_to_action_type: string | null;
230
+ returning_customers: number;
228
231
  /**
229
- * Image URL Meta returns.
232
+ * Messages customers sent in the period.
230
233
  */
231
- image_url: string | null;
234
+ messages: number;
235
+ }>;
236
+ /**
237
+ * One entry per day of the period, or per hour of a one-day period.
238
+ */
239
+ series: Array<{
232
240
  /**
233
- * Thumbnail URL Meta returns; it expires.
241
+ * America/Panama day `YYYY-MM-DD`, or hour `YYYY-MM-DDTHH` when the period is one day.
234
242
  */
235
- thumbnail_url: string | null;
243
+ slot: string;
236
244
  /**
237
- * The Instagram post it runs.
245
+ * Customers whose first message ever falls in this slot.
238
246
  */
239
- instagram_permalink_url: string | null;
247
+ new_customers: number;
240
248
  /**
241
- * Meta's story spec as Meta returns it: page, link, message and media.
249
+ * Customers who wrote in this slot and had written before.
242
250
  */
243
- object_story_spec: unknown;
244
- } | null;
251
+ returning_customers: number;
252
+ previous_customers: number | null;
253
+ }>;
245
254
  /**
246
- * ISO 8601 time as Meta reports it; null if unset.
255
+ * Customer messages of the period per weekday and hour; slots without any are left out.
247
256
  */
248
- created_time: string | null;
257
+ heatmap: Array<{
258
+ /**
259
+ * 0 is Sunday, 6 is Saturday.
260
+ */
261
+ day_of_week: number;
262
+ /**
263
+ * Hour of the day, 0–23.
264
+ */
265
+ hour: number;
266
+ /**
267
+ * Customer messages in that hour of that weekday.
268
+ */
269
+ messages: number;
270
+ }>;
249
271
  /**
250
- * ISO 8601 time as Meta reports it; null if unset.
272
+ * When Ricky computed the report.
251
273
  */
252
- updated_time: string | null;
274
+ generated_at: string;
253
275
  };
254
276
  /**
255
- * Performance Meta computed for one row of the requested level, period and breakdowns.
277
+ * Messages received from customers and sent to them in the period, and who sent them, dated when each message was sent.
278
+ */
279
+ export type MessagesReport = {
280
+ period: ReportPeriod;
281
+ /**
282
+ * The channel filter the report applied.
283
+ */
284
+ channel: 'all' | 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
285
+ /**
286
+ * The period.
287
+ */
288
+ totals: {
289
+ /**
290
+ * Messages customers sent.
291
+ */
292
+ received: number;
293
+ /**
294
+ * Messages sent to customers, by anyone; the sum of `sent_by`.
295
+ */
296
+ sent: number;
297
+ /**
298
+ * Sent messages by sender; each message counts in one of them.
299
+ */
300
+ sent_by: {
301
+ /**
302
+ * Sent by a person in Ricky.
303
+ */
304
+ human: number;
305
+ /**
306
+ * Sent by an AI agent.
307
+ */
308
+ ai: number;
309
+ /**
310
+ * Sent by an automation.
311
+ */
312
+ automation: number;
313
+ /**
314
+ * Templates not sent by an automation: broadcasts and templates sent by hand or through the API.
315
+ */
316
+ campaign: number;
317
+ /**
318
+ * Sent from the channel's own app, with no sender in Ricky: WhatsApp Business app coexistence and imported history.
319
+ */
320
+ external: number;
321
+ };
322
+ };
323
+ /**
324
+ * The previous period.
325
+ */
326
+ previous: {
327
+ /**
328
+ * Messages customers sent.
329
+ */
330
+ received: number;
331
+ /**
332
+ * Messages sent to customers, by anyone; the sum of `sent_by`.
333
+ */
334
+ sent: number;
335
+ /**
336
+ * Sent messages by sender; each message counts in one of them.
337
+ */
338
+ sent_by: {
339
+ /**
340
+ * Sent by a person in Ricky.
341
+ */
342
+ human: number;
343
+ /**
344
+ * Sent by an AI agent.
345
+ */
346
+ ai: number;
347
+ /**
348
+ * Sent by an automation.
349
+ */
350
+ automation: number;
351
+ /**
352
+ * Templates not sent by an automation: broadcasts and templates sent by hand or through the API.
353
+ */
354
+ campaign: number;
355
+ /**
356
+ * Sent from the channel's own app, with no sender in Ricky: WhatsApp Business app coexistence and imported history.
357
+ */
358
+ external: number;
359
+ };
360
+ };
361
+ /**
362
+ * The period per channel, most messages first.
363
+ */
364
+ by_channel: Array<{
365
+ /**
366
+ * Channel.
367
+ */
368
+ channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
369
+ /**
370
+ * Messages customers sent.
371
+ */
372
+ received: number;
373
+ /**
374
+ * Messages sent to customers, by anyone; the sum of `sent_by`.
375
+ */
376
+ sent: number;
377
+ /**
378
+ * Sent messages by sender; each message counts in one of them.
379
+ */
380
+ sent_by: {
381
+ /**
382
+ * Sent by a person in Ricky.
383
+ */
384
+ human: number;
385
+ /**
386
+ * Sent by an AI agent.
387
+ */
388
+ ai: number;
389
+ /**
390
+ * Sent by an automation.
391
+ */
392
+ automation: number;
393
+ /**
394
+ * Templates not sent by an automation: broadcasts and templates sent by hand or through the API.
395
+ */
396
+ campaign: number;
397
+ /**
398
+ * Sent from the channel's own app, with no sender in Ricky: WhatsApp Business app coexistence and imported history.
399
+ */
400
+ external: number;
401
+ };
402
+ }>;
403
+ /**
404
+ * One entry per day of the period, or per hour of a one-day period.
405
+ */
406
+ series: Array<{
407
+ /**
408
+ * America/Panama day `YYYY-MM-DD`, or hour `YYYY-MM-DDTHH` when the period is one day.
409
+ */
410
+ slot: string;
411
+ /**
412
+ * Messages customers sent.
413
+ */
414
+ received: number;
415
+ /**
416
+ * Messages sent to customers, by anyone; the sum of `sent_by`.
417
+ */
418
+ sent: number;
419
+ /**
420
+ * Sent messages by sender; each message counts in one of them.
421
+ */
422
+ sent_by: {
423
+ /**
424
+ * Sent by a person in Ricky.
425
+ */
426
+ human: number;
427
+ /**
428
+ * Sent by an AI agent.
429
+ */
430
+ ai: number;
431
+ /**
432
+ * Sent by an automation.
433
+ */
434
+ automation: number;
435
+ /**
436
+ * Templates not sent by an automation: broadcasts and templates sent by hand or through the API.
437
+ */
438
+ campaign: number;
439
+ /**
440
+ * Sent from the channel's own app, with no sender in Ricky: WhatsApp Business app coexistence and imported history.
441
+ */
442
+ external: number;
443
+ };
444
+ previous_received: number | null;
445
+ previous_sent: number | null;
446
+ }>;
447
+ /**
448
+ * When Ricky computed the report.
449
+ */
450
+ generated_at: string;
451
+ };
452
+ /**
453
+ * What the inbox looks like right now; it has no period.
454
+ */
455
+ export type DashboardReport = {
456
+ /**
457
+ * Now.
458
+ */
459
+ totals: {
460
+ /**
461
+ * Open conversations.
462
+ */
463
+ open_now: number;
464
+ /**
465
+ * Open conversations with no member or AI agent assigned.
466
+ */
467
+ unassigned: number;
468
+ /**
469
+ * Open conversations whose last message, reactions aside, is from the customer.
470
+ */
471
+ awaiting_reply: number;
472
+ /**
473
+ * Handoffs from an AI agent to a person still waiting.
474
+ */
475
+ pending_handoffs: number;
476
+ /**
477
+ * Conversations opened or reopened today, America/Panama.
478
+ */
479
+ opened_today: number;
480
+ /**
481
+ * Conversations closed today, America/Panama.
482
+ */
483
+ closed_today: number;
484
+ };
485
+ /**
486
+ * Open conversations per channel, most first.
487
+ */
488
+ by_channel: Array<{
489
+ /**
490
+ * Channel.
491
+ */
492
+ channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
493
+ /**
494
+ * Open conversations.
495
+ */
496
+ open: number;
497
+ }>;
498
+ /**
499
+ * Open conversations per assignee, most first.
500
+ */
501
+ assignees: Array<{
502
+ /**
503
+ * `human` is a member, `ai` an AI agent, `unassigned` nobody.
504
+ */
505
+ type: 'human' | 'ai' | 'unassigned';
506
+ /**
507
+ * User ID or AI agent ID; null for `unassigned`.
508
+ */
509
+ id: string | null;
510
+ /**
511
+ * Name; null when it has none and for `unassigned`.
512
+ */
513
+ name: string | null;
514
+ /**
515
+ * Open conversations they hold.
516
+ */
517
+ open: number;
518
+ /**
519
+ * Of those, the ones whose last message is from the customer.
520
+ */
521
+ awaiting_reply: number;
522
+ }>;
523
+ /**
524
+ * The 15 open conversations waiting longest for a reply, oldest first.
525
+ */
526
+ longest_waiting: Array<{
527
+ /**
528
+ * Conversation ID.
529
+ */
530
+ conversation_id: string;
531
+ /**
532
+ * Channel.
533
+ */
534
+ channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
535
+ /**
536
+ * Customer name as the inbox shows it: the contact’s saved name, else the channel profile name, else the contact’s phone.
537
+ */
538
+ participant_name: string | null;
539
+ /**
540
+ * When the customer message they wait on arrived.
541
+ */
542
+ waiting_since: string;
543
+ /**
544
+ * `human` is a member, `ai` an AI agent, `unassigned` nobody.
545
+ */
546
+ assignee_type: 'human' | 'ai' | 'unassigned';
547
+ /**
548
+ * Assignee name; null when there is none.
549
+ */
550
+ assignee_name: string | null;
551
+ }>;
552
+ /**
553
+ * When Ricky computed the report.
554
+ */
555
+ generated_at: string;
556
+ };
557
+ /**
558
+ * A conversation a Meta ad opened or brought back in the period, with what happened after. One row per conversation and ad: a conversation two ads brought back has two rows.
559
+ */
560
+ export type AdConversation = {
561
+ /**
562
+ * The first customer message from this ad in this conversation within the period.
563
+ */
564
+ ad_referral: AdReferral;
565
+ /**
566
+ * Whether that message started the conversation: no message came before it. False when the ad brought back someone who had written before.
567
+ */
568
+ opened_conversation: boolean;
569
+ /**
570
+ * Text of that message: what the customer wrote, often the greeting the ad prefilled.
571
+ */
572
+ message_text: string | null;
573
+ /**
574
+ * Who wrote.
575
+ */
576
+ contact: {
577
+ id: string | null;
578
+ /**
579
+ * Name saved on the contact, else the name on the channel.
580
+ */
581
+ name: string | null;
582
+ /**
583
+ * Phone saved on the contact, in E.164.
584
+ */
585
+ phone: string | null;
586
+ /**
587
+ * Address on the channel: phone digits for WhatsApp, account ID otherwise.
588
+ */
589
+ external_id: string;
590
+ };
591
+ /**
592
+ * The conversation as it is now.
593
+ */
594
+ conversation: {
595
+ /**
596
+ * Conversation ID.
597
+ */
598
+ id: string;
599
+ /**
600
+ * Its state now.
601
+ */
602
+ status: 'open' | 'closed';
603
+ /**
604
+ * Why it was closed: `sale` when a member closed it as a sale, the only sign of a purchase Ricky records, without an amount. Null while open or when closed without a category.
605
+ */
606
+ close_category: 'resolved' | 'sale' | 'no_response' | 'spam' | 'other' | null;
607
+ /**
608
+ * When it was closed; null while open.
609
+ */
610
+ closed_at: string | null;
611
+ /**
612
+ * When Ricky created it.
613
+ */
614
+ created_at: string;
615
+ };
616
+ /**
617
+ * Messages the customer sent in the conversation from that message on, that one included; reactions do not count.
618
+ */
619
+ customer_messages: number;
620
+ /**
621
+ * Replies from that message on by a member in Ricky, an AI agent or someone in the channel's own app. Automations, broadcasts, templates and reactions do not count.
622
+ */
623
+ replies: number;
624
+ /**
625
+ * Seconds from that message to the first reply; null while unanswered.
626
+ */
627
+ first_reply_seconds: number | null;
628
+ };
629
+ /**
630
+ * A campaign of a connected ad account.
631
+ */
632
+ export type MetaAdsCampaign = {
633
+ /**
634
+ * Campaign ID at Meta.
635
+ */
636
+ id: string;
637
+ /**
638
+ * Ad account ID at Meta.
639
+ */
640
+ account_id: string;
641
+ /**
642
+ * Name in Meta.
643
+ */
644
+ name: string;
645
+ /**
646
+ * Objective, such as `OUTCOME_ENGAGEMENT`.
647
+ */
648
+ objective: string | null;
649
+ /**
650
+ * Status the advertiser set: `ACTIVE`, `PAUSED`, …
651
+ */
652
+ status: string;
653
+ /**
654
+ * Delivery status, including a parent paused: `ACTIVE`, `CAMPAIGN_PAUSED`, …
655
+ */
656
+ effective_status: string;
657
+ /**
658
+ * `AUCTION` or `RESERVED`.
659
+ */
660
+ buying_type: string | null;
661
+ /**
662
+ * Bid strategy, when the campaign sets one.
663
+ */
664
+ bid_strategy: string | null;
665
+ /**
666
+ * Budget as Meta reports it, in the ad account currency.
667
+ */
668
+ budget: {
669
+ /**
670
+ * Daily budget in the account currency; null when not set.
671
+ */
672
+ daily: number | null;
673
+ /**
674
+ * Lifetime budget in the account currency; null when not set.
675
+ */
676
+ lifetime: number | null;
677
+ /**
678
+ * Budget left in the account currency.
679
+ */
680
+ remaining: number | null;
681
+ };
682
+ /**
683
+ * ISO 8601 time as Meta reports it; null if unset.
684
+ */
685
+ start_time: string | null;
686
+ /**
687
+ * ISO 8601 time as Meta reports it; null if unset.
688
+ */
689
+ stop_time: string | null;
690
+ /**
691
+ * ISO 8601 time as Meta reports it; null if unset.
692
+ */
693
+ created_time: string | null;
694
+ /**
695
+ * ISO 8601 time as Meta reports it; null if unset.
696
+ */
697
+ updated_time: string | null;
698
+ };
699
+ /**
700
+ * An ad set of a connected ad account.
701
+ */
702
+ export type MetaAdsAdSet = {
703
+ /**
704
+ * Ad set ID at Meta.
705
+ */
706
+ id: string;
707
+ /**
708
+ * Ad account ID at Meta.
709
+ */
710
+ account_id: string;
711
+ /**
712
+ * Campaign ID at Meta.
713
+ */
714
+ campaign_id: string;
715
+ /**
716
+ * Name in Meta.
717
+ */
718
+ name: string;
719
+ /**
720
+ * Status the advertiser set: `ACTIVE`, `PAUSED`, …
721
+ */
722
+ status: string;
723
+ /**
724
+ * Delivery status, including a parent paused: `ACTIVE`, `CAMPAIGN_PAUSED`, …
725
+ */
726
+ effective_status: string;
727
+ /**
728
+ * What Meta optimizes delivery for.
729
+ */
730
+ optimization_goal: string | null;
731
+ /**
732
+ * What Meta charges for.
733
+ */
734
+ billing_event: string | null;
735
+ /**
736
+ * Bid strategy, when the campaign sets one.
737
+ */
738
+ bid_strategy: string | null;
739
+ /**
740
+ * Budget as Meta reports it, in the ad account currency.
741
+ */
742
+ budget: {
743
+ /**
744
+ * Daily budget in the account currency; null when not set.
745
+ */
746
+ daily: number | null;
747
+ /**
748
+ * Lifetime budget in the account currency; null when not set.
749
+ */
750
+ lifetime: number | null;
751
+ /**
752
+ * Budget left in the account currency.
753
+ */
754
+ remaining: number | null;
755
+ };
756
+ /**
757
+ * ISO 8601 time as Meta reports it; null if unset.
758
+ */
759
+ start_time: string | null;
760
+ /**
761
+ * ISO 8601 time as Meta reports it; null if unset.
762
+ */
763
+ end_time: string | null;
764
+ /**
765
+ * Meta's targeting spec as Meta returns it: ages, locations, interests, …
766
+ */
767
+ targeting: unknown;
768
+ /**
769
+ * ISO 8601 time as Meta reports it; null if unset.
770
+ */
771
+ created_time: string | null;
772
+ /**
773
+ * ISO 8601 time as Meta reports it; null if unset.
774
+ */
775
+ updated_time: string | null;
776
+ };
777
+ /**
778
+ * An ad of a connected ad account, with its creative copy.
779
+ */
780
+ export type MetaAdsAd = {
781
+ /**
782
+ * Ad ID at Meta.
783
+ */
784
+ id: string;
785
+ /**
786
+ * Ad account ID at Meta.
787
+ */
788
+ account_id: string;
789
+ /**
790
+ * Campaign ID at Meta.
791
+ */
792
+ campaign_id: string;
793
+ /**
794
+ * Ad set ID at Meta.
795
+ */
796
+ ad_set_id: string;
797
+ /**
798
+ * Name in Meta.
799
+ */
800
+ name: string;
801
+ /**
802
+ * Status the advertiser set: `ACTIVE`, `PAUSED`, …
803
+ */
804
+ status: string;
805
+ /**
806
+ * Delivery status, including a parent paused: `ACTIVE`, `CAMPAIGN_PAUSED`, …
807
+ */
808
+ effective_status: string;
809
+ /**
810
+ * The creative the ad runs; null when Meta returns none.
811
+ */
812
+ creative: {
813
+ /**
814
+ * Creative ID at Meta.
815
+ */
816
+ id: string;
817
+ /**
818
+ * Headline.
819
+ */
820
+ title: string | null;
821
+ /**
822
+ * Primary text.
823
+ */
824
+ body: string | null;
825
+ /**
826
+ * Button, such as `LEARN_MORE`.
827
+ */
828
+ call_to_action_type: string | null;
829
+ /**
830
+ * Image URL Meta returns.
831
+ */
832
+ image_url: string | null;
833
+ /**
834
+ * Thumbnail URL Meta returns; it expires.
835
+ */
836
+ thumbnail_url: string | null;
837
+ /**
838
+ * The Instagram post it runs.
839
+ */
840
+ instagram_permalink_url: string | null;
841
+ /**
842
+ * Meta's story spec as Meta returns it: page, link, message and media.
843
+ */
844
+ object_story_spec: unknown;
845
+ } | null;
846
+ /**
847
+ * ISO 8601 time as Meta reports it; null if unset.
848
+ */
849
+ created_time: string | null;
850
+ /**
851
+ * ISO 8601 time as Meta reports it; null if unset.
852
+ */
853
+ updated_time: string | null;
854
+ };
855
+ /**
856
+ * Performance Meta computed for one row of the requested level, period and breakdowns.
256
857
  */
257
858
  export type MetaAdsInsight = {
258
859
  /**
@@ -586,6 +1187,14 @@ export type Contact = {
586
1187
  */
587
1188
  last_activity_preview: string | null;
588
1189
  last_conversation_id: string | null;
1190
+ /**
1191
+ * First touch: the earliest Meta ad this contact came from, in any of its conversations; null when none came from an ad.
1192
+ */
1193
+ first_ad_referral: AdReferral | null;
1194
+ /**
1195
+ * Last touch: the latest Meta ad this contact came from; the same as `first_ad_referral` when only one ad brought them.
1196
+ */
1197
+ last_ad_referral: AdReferral | null;
589
1198
  /**
590
1199
  * Last change to the contact.
591
1200
  */
@@ -736,6 +1345,14 @@ export type Conversation = {
736
1345
  * The handoff to a person waiting to be resolved; null when there is none.
737
1346
  */
738
1347
  active_handoff: ConversationHandoff | null;
1348
+ /**
1349
+ * The earliest Meta ad that brought the contact to this conversation; null when none did.
1350
+ */
1351
+ first_ad_referral: AdReferral | null;
1352
+ /**
1353
+ * The latest Meta ad that brought the contact back to this conversation; the same as `first_ad_referral` when only one did.
1354
+ */
1355
+ latest_ad_referral: AdReferral | null;
739
1356
  };
740
1357
  /**
741
1358
  * One message in a conversation.
@@ -827,6 +1444,10 @@ export type Message = {
827
1444
  * When the sender deleted it.
828
1445
  */
829
1446
  deleted_at: string | null;
1447
+ /**
1448
+ * The Meta ad this customer message came from; null for every other message.
1449
+ */
1450
+ ad_referral: AdReferral | null;
830
1451
  };
831
1452
  /**
832
1453
  * An outbound message Ricky accepted and is delivering.
@@ -978,1010 +1599,623 @@ export type Broadcast = {
978
1599
  /**
979
1600
  * Delivered to the phone, not yet read.
980
1601
  */
981
- delivered: number;
982
- /**
983
- * Read by the recipient.
984
- */
985
- read: number;
986
- /**
987
- * Not delivered; each recipient says why.
988
- */
989
- failed: number;
990
- };
991
- /**
992
- * When it starts sending; null if it was sent at once.
993
- */
994
- scheduled_at: string | null;
995
- /**
996
- * When it was canceled; null otherwise.
997
- */
998
- canceled_at: string | null;
999
- /**
1000
- * When the last message was handed to WhatsApp.
1001
- */
1002
- completed_at: string | null;
1003
- /**
1004
- * Member who created it, or who created the API key.
1005
- */
1006
- created_by_user_id: string;
1007
- /**
1008
- * When it was created.
1009
- */
1010
- created_at: string;
1011
- };
1012
- /**
1013
- * One number of a broadcast and where its message stands.
1014
- */
1015
- export type BroadcastRecipient = {
1016
- /**
1017
- * Recipient ID.
1018
- */
1019
- id: string;
1020
- /**
1021
- * Number in E.164.
1022
- */
1023
- phone: string;
1024
- contact_id: string | null;
1025
- /**
1026
- * `pending` until WhatsApp accepts or refuses the message; then `sent`, `delivered` and `read` as WhatsApp reports them, or `failed`.
1027
- */
1028
- status: 'pending' | 'sent' | 'delivered' | 'read' | 'failed';
1029
- /**
1030
- * Why it failed; null unless `failed`.
1031
- */
1032
- failure_reason: string | null;
1033
- conversation_id: string | null;
1034
- message_id: string | null;
1035
- /**
1036
- * When the broadcast handed the message to WhatsApp or recorded why it could not.
1037
- */
1038
- processed_at: string | null;
1039
- /**
1040
- * When WhatsApp reported the latest status of the message; null before.
1041
- */
1042
- status_updated_at: string | null;
1043
- };
1044
- /**
1045
- * How many numbers an audience resolves to now.
1046
- */
1047
- export type BroadcastAudiencePreview = {
1048
- /**
1049
- * Numbers a broadcast to this audience would go to now, at most 5,000.
1050
- */
1051
- recipients: number;
1052
- /**
1053
- * Contacts or numbers left out because they have no valid WhatsApp number.
1054
- */
1055
- skipped: number;
1056
- };
1057
- /**
1058
- * The photo of a location, which the agents can look at and send when it helps.
1059
- */
1060
- export type KnowledgeLocationPhoto = {
1061
- /**
1062
- * File type.
1063
- */
1064
- mime_type: 'image/jpeg' | 'image/png';
1065
- /**
1066
- * Size in bytes.
1067
- */
1068
- size_bytes: number;
1069
- /**
1070
- * Signed download URL, valid for five minutes. Only `GET /knowledge/locations/{location_id}` carries it; null elsewhere.
1071
- */
1072
- download_url: string | null;
1073
- };
1074
- /**
1075
- * A branch or place the agents can send as a WhatsApp location.
1076
- */
1077
- export type KnowledgeLocation = {
1078
- /**
1079
- * Location ID.
1080
- */
1081
- id: string;
1082
- /**
1083
- * Name customers know it by.
1084
- */
1085
- name: string;
1086
- /**
1087
- * Full address as customers read it.
1088
- */
1089
- address: string;
1090
- /**
1091
- * Latitude of the map pin.
1092
- */
1093
- latitude: number;
1094
- /**
1095
- * Longitude of the map pin.
1096
- */
1097
- longitude: number;
1098
- /**
1099
- * Street.
1100
- */
1101
- street: string | null;
1102
- /**
1103
- * City.
1104
- */
1105
- city: string | null;
1106
- /**
1107
- * State, province or region.
1108
- */
1109
- state: string | null;
1110
- /**
1111
- * Postal code.
1112
- */
1113
- postal_code: string | null;
1114
- /**
1115
- * Country.
1116
- */
1117
- country: string | null;
1118
- /**
1119
- * Country code, ISO 3166-1 alpha-2.
1120
- */
1121
- country_code: string | null;
1122
- /**
1123
- * Phone in E.164.
1124
- */
1125
- phone: string | null;
1126
- /**
1127
- * Email.
1128
- */
1129
- email: string | null;
1130
- /**
1131
- * Opening hours, as free text.
1132
- */
1133
- hours: string | null;
1134
- /**
1135
- * Its photo; null when it has none.
1136
- */
1137
- photo: KnowledgeLocationPhoto | null;
1138
- };
1139
- /**
1140
- * A location, with its current photo, and where to put the bytes of the next one.
1141
- */
1142
- export type KnowledgeLocationPhotoUpload = {
1143
- location: KnowledgeLocation;
1144
- /**
1145
- * Signed URL valid for two hours. `PUT` the photo bytes to it with `Content-Type` set to `mime_type`, then call `POST /knowledge/locations/{location_id}/photo/complete`.
1146
- */
1147
- upload_url: string;
1148
- };
1149
- /**
1150
- * A contact card in the knowledge directory, which agents can send to customers.
1151
- */
1152
- export type KnowledgeContact = {
1153
- /**
1154
- * Knowledge contact ID.
1155
- */
1156
- id: string;
1157
- /**
1158
- * Name shown on the contact card.
1159
- */
1160
- display_name: string;
1161
- /**
1162
- * First name.
1163
- */
1164
- first_name: string | null;
1165
- /**
1166
- * Last name.
1167
- */
1168
- last_name: string | null;
1169
- /**
1170
- * Name prefix, such as `Dr.`.
1171
- */
1172
- prefix: string | null;
1173
- /**
1174
- * Name suffix.
1175
- */
1176
- suffix: string | null;
1177
- /**
1178
- * Company.
1179
- */
1180
- company: string | null;
1181
- /**
1182
- * Department.
1183
- */
1184
- department: string | null;
1185
- /**
1186
- * Job title.
1187
- */
1188
- job_title: string | null;
1189
- /**
1190
- * When the agents should share it.
1191
- */
1192
- description: string | null;
1193
- /**
1194
- * Phone in E.164.
1195
- */
1196
- phone: string | null;
1197
- /**
1198
- * `CELL`, `WORK` or `HOME`.
1199
- */
1200
- phone_type: string | null;
1201
- /**
1202
- * Email.
1203
- */
1204
- email: string | null;
1205
- /**
1206
- * `WORK` or `PERSONAL`.
1207
- */
1208
- email_type: string | null;
1209
- };
1210
- /**
1211
- * A document or image the agents can consult or send.
1212
- */
1213
- export type KnowledgeFile = {
1214
- /**
1215
- * File ID.
1216
- */
1217
- id: string;
1602
+ delivered: number;
1603
+ /**
1604
+ * Read by the recipient.
1605
+ */
1606
+ read: number;
1607
+ /**
1608
+ * Not delivered; each recipient says why.
1609
+ */
1610
+ failed: number;
1611
+ };
1218
1612
  /**
1219
- * Title the agents see.
1613
+ * When it starts sending; null if it was sent at once.
1220
1614
  */
1221
- title: string;
1615
+ scheduled_at: string | null;
1222
1616
  /**
1223
- * When the agents should use it; may be empty.
1617
+ * When it was canceled; null otherwise.
1224
1618
  */
1225
- description: string;
1619
+ canceled_at: string | null;
1226
1620
  /**
1227
- * Original file name.
1621
+ * When the last message was handed to WhatsApp.
1228
1622
  */
1229
- filename: string;
1623
+ completed_at: string | null;
1230
1624
  /**
1231
- * File type.
1625
+ * Member who created it, or who created the API key.
1232
1626
  */
1233
- mime_type: 'application/pdf' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'image/jpeg' | 'image/png';
1627
+ created_by_user_id: string;
1234
1628
  /**
1235
- * Size in bytes.
1629
+ * When it was created.
1236
1630
  */
1237
- size_bytes: number;
1631
+ created_at: string;
1632
+ };
1633
+ /**
1634
+ * One number of a broadcast and where its message stands.
1635
+ */
1636
+ export type BroadcastRecipient = {
1238
1637
  /**
1239
- * `uploading` until `POST /knowledge/files/{file_id}/complete` reads it; then `ready`, also when Ricky could not read useful content, which `extraction_error` then says. Ricky does not set `failed` today.
1638
+ * Recipient ID.
1240
1639
  */
1241
- status: 'uploading' | 'ready' | 'failed';
1640
+ id: string;
1242
1641
  /**
1243
- * Agents may read it to answer.
1642
+ * Number in E.164.
1244
1643
  */
1245
- consult_enabled: boolean;
1644
+ phone: string;
1645
+ contact_id: string | null;
1246
1646
  /**
1247
- * Agents may send the file itself to customers.
1647
+ * `pending` until WhatsApp accepts or refuses the message; then `sent`, `delivered` and `read` as WhatsApp reports them, or `failed`.
1248
1648
  */
1249
- send_enabled: boolean;
1649
+ status: 'pending' | 'sent' | 'delivered' | 'read' | 'failed';
1250
1650
  /**
1251
- * Pages of a PDF; null otherwise.
1651
+ * Why it failed; null unless `failed`.
1252
1652
  */
1253
- page_count: number | null;
1653
+ failure_reason: string | null;
1654
+ conversation_id: string | null;
1655
+ message_id: string | null;
1254
1656
  /**
1255
- * Why Ricky could not read useful content; null when it could.
1657
+ * When the broadcast handed the message to WhatsApp or recorded why it could not.
1256
1658
  */
1257
- extraction_error: string | null;
1659
+ processed_at: string | null;
1258
1660
  /**
1259
- * Signed download URL, valid for five minutes. Only `GET /knowledge/files/{file_id}` of a `ready` file carries it; null elsewhere.
1661
+ * When WhatsApp reported the latest status of the message; null before.
1260
1662
  */
1261
- download_url: string | null;
1663
+ status_updated_at: string | null;
1664
+ };
1665
+ /**
1666
+ * How many numbers an audience resolves to now.
1667
+ */
1668
+ export type BroadcastAudiencePreview = {
1262
1669
  /**
1263
- * When the upload began.
1670
+ * Numbers a broadcast to this audience would go to now, at most 5,000.
1264
1671
  */
1265
- created_at: string;
1672
+ recipients: number;
1266
1673
  /**
1267
- * Last change.
1674
+ * Contacts or numbers left out because they have no valid WhatsApp number.
1268
1675
  */
1269
- updated_at: string;
1676
+ skipped: number;
1270
1677
  };
1271
1678
  /**
1272
- * Everything Ricky read from a file, what the agents consult to answer.
1679
+ * The photo of a location, which the agents can look at and send when it helps.
1273
1680
  */
1274
- export type KnowledgeFileReading = {
1681
+ export type KnowledgeLocationPhoto = {
1275
1682
  /**
1276
- * File ID.
1683
+ * File type.
1277
1684
  */
1278
- file_id: string;
1685
+ mime_type: 'image/jpeg' | 'image/png';
1279
1686
  /**
1280
- * In page order. Empty when Ricky read no useful content (`extraction_error`).
1687
+ * Size in bytes.
1281
1688
  */
1282
- sections: Array<{
1283
- /**
1284
- * PDF page it was read from; null for formats without pages.
1285
- */
1286
- page: number | null;
1287
- /**
1288
- * Everything Ricky read from that page, in Markdown: text in reading order, tables, and one line per picture saying what it shows.
1289
- */
1290
- text: string;
1291
- }>;
1292
- };
1293
- /**
1294
- * A file waiting for its bytes, and where to put them.
1295
- */
1296
- export type KnowledgeFileUpload = {
1297
- file: KnowledgeFile;
1689
+ size_bytes: number;
1298
1690
  /**
1299
- * Signed URL valid for two hours. `PUT` the file bytes to it with `Content-Type` set to `mime_type`, then call `POST /knowledge/files/{file_id}/complete`.
1691
+ * Signed download URL, valid for five minutes. Only `GET /knowledge/locations/{location_id}` carries it; null elsewhere.
1300
1692
  */
1301
- upload_url: string;
1693
+ download_url: string | null;
1302
1694
  };
1303
1695
  /**
1304
- * A webhook subscription.
1696
+ * A branch or place the agents can send as a WhatsApp location.
1305
1697
  */
1306
- export type Webhook = {
1698
+ export type KnowledgeLocation = {
1307
1699
  /**
1308
- * Webhook ID.
1700
+ * Location ID.
1309
1701
  */
1310
1702
  id: string;
1311
1703
  /**
1312
- * HTTPS endpoint Ricky posts to.
1313
- */
1314
- url: string;
1315
- event_types: Array<'message.received' | 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'conversation.opened' | 'conversation.closed' | 'conversation.assignment_changed' | 'conversation.agent_changed' | 'conversation.handoff_requested' | 'conversation.handoff_resolved' | 'contact.created' | 'contact.updated' | 'contact.tags_changed' | 'broadcast.completed' | 'broadcast.failed' | 'template.status_changed' | 'workflow.execution_failed' | 'knowledge_file.ready'>;
1316
- status: 'active' | 'disabled';
1317
- /**
1318
- * When it was created.
1704
+ * Name customers know it by.
1319
1705
  */
1320
- created_at: string;
1706
+ name: string;
1321
1707
  /**
1322
- * When it was disabled.
1708
+ * Full address as customers read it.
1323
1709
  */
1324
- disabled_at: string | null;
1325
- };
1326
- /**
1327
- * A new webhook subscription with its signing secret.
1328
- */
1329
- export type CreatedWebhook = {
1710
+ address: string;
1330
1711
  /**
1331
- * Webhook ID.
1712
+ * Latitude of the map pin.
1332
1713
  */
1333
- id: string;
1714
+ latitude: number;
1334
1715
  /**
1335
- * HTTPS endpoint Ricky posts to.
1716
+ * Longitude of the map pin.
1336
1717
  */
1337
- url: string;
1338
- event_types: Array<'message.received' | 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'conversation.opened' | 'conversation.closed' | 'conversation.assignment_changed' | 'conversation.agent_changed' | 'conversation.handoff_requested' | 'conversation.handoff_resolved' | 'contact.created' | 'contact.updated' | 'contact.tags_changed' | 'broadcast.completed' | 'broadcast.failed' | 'template.status_changed' | 'workflow.execution_failed' | 'knowledge_file.ready'>;
1339
- status: 'active' | 'disabled';
1718
+ longitude: number;
1340
1719
  /**
1341
- * When it was created.
1720
+ * Street.
1342
1721
  */
1343
- created_at: string;
1722
+ street: string | null;
1344
1723
  /**
1345
- * When it was disabled.
1724
+ * City.
1346
1725
  */
1347
- disabled_at: string | null;
1726
+ city: string | null;
1348
1727
  /**
1349
- * HMAC key for `X-Ricky-Signature`. Returned only here, once.
1728
+ * State, province or region.
1350
1729
  */
1351
- signing_secret: string;
1352
- };
1353
- /**
1354
- * One webhook delivery.
1355
- */
1356
- export type WebhookDelivery = {
1730
+ state: string | null;
1357
1731
  /**
1358
- * Delivery ID; equals the event `id` and `X-Ricky-Delivery-Id`.
1732
+ * Postal code.
1359
1733
  */
1360
- id: string;
1361
- event_type: 'message.received' | 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'conversation.opened' | 'conversation.closed' | 'conversation.assignment_changed' | 'conversation.agent_changed' | 'conversation.handoff_requested' | 'conversation.handoff_resolved' | 'contact.created' | 'contact.updated' | 'contact.tags_changed' | 'broadcast.completed' | 'broadcast.failed' | 'template.status_changed' | 'workflow.execution_failed' | 'knowledge_file.ready';
1362
- status: 'pending' | 'processing' | 'delivered' | 'failed';
1734
+ postal_code: string | null;
1363
1735
  /**
1364
- * Delivery attempts so far; Ricky makes at most ten.
1736
+ * Country.
1365
1737
  */
1366
- attempts: number;
1738
+ country: string | null;
1367
1739
  /**
1368
- * HTTP status of the last attempt.
1740
+ * Country code, ISO 3166-1 alpha-2.
1369
1741
  */
1370
- last_response_status: number | null;
1742
+ country_code: string | null;
1371
1743
  /**
1372
- * Why the last attempt failed.
1744
+ * Phone in E.164.
1373
1745
  */
1374
- last_error: string | null;
1746
+ phone: string | null;
1375
1747
  /**
1376
- * When the event happened.
1748
+ * Email.
1377
1749
  */
1378
- created_at: string;
1750
+ email: string | null;
1379
1751
  /**
1380
- * When Ricky tries next, while pending.
1752
+ * Opening hours, as free text.
1381
1753
  */
1382
- next_attempt_at: string;
1754
+ hours: string | null;
1383
1755
  /**
1384
- * When the endpoint answered 2xx.
1756
+ * Its photo; null when it has none.
1385
1757
  */
1386
- delivered_at: string | null;
1758
+ photo: KnowledgeLocationPhoto | null;
1387
1759
  };
1388
1760
  /**
1389
- * The JSON body Ricky posts to a webhook endpoint.
1761
+ * A location, with its current photo, and where to put the bytes of the next one.
1390
1762
  */
1391
- export type WebhookEvent = {
1392
- /**
1393
- * Delivery ID. Deduplicate by it.
1394
- */
1395
- id: string;
1396
- type: 'message.received' | 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'conversation.opened' | 'conversation.closed' | 'conversation.assignment_changed' | 'conversation.agent_changed' | 'conversation.handoff_requested' | 'conversation.handoff_resolved' | 'contact.created' | 'contact.updated' | 'contact.tags_changed' | 'broadcast.completed' | 'broadcast.failed' | 'template.status_changed' | 'workflow.execution_failed' | 'knowledge_file.ready' | 'webhook.test';
1397
- /**
1398
- * When it happened.
1399
- */
1400
- occurred_at: string;
1763
+ export type KnowledgeLocationPhotoUpload = {
1764
+ location: KnowledgeLocation;
1401
1765
  /**
1402
- * Organization.
1766
+ * Signed URL valid for two hours. `PUT` the photo bytes to it with `Content-Type` set to `mime_type`, then call `POST /knowledge/locations/{location_id}/photo/complete`.
1403
1767
  */
1404
- organization_id: string;
1405
- data: {
1406
- /**
1407
- * Conversation, for `message.*` and `conversation.*` events.
1408
- */
1409
- conversation_id?: string;
1410
- /**
1411
- * Message, for `message.*` events.
1412
- */
1413
- message_id?: string;
1414
- /**
1415
- * Contact, for `contact.*` events.
1416
- */
1417
- contact_id?: string;
1418
- /**
1419
- * Broadcast, for `broadcast.*` events.
1420
- */
1421
- broadcast_id?: string;
1422
- /**
1423
- * Template ID at Meta, for `template.status_changed`.
1424
- */
1425
- template_id?: string;
1426
- /**
1427
- * Workflow, for `workflow.execution_failed`.
1428
- */
1429
- workflow_id?: string;
1430
- /**
1431
- * Execution, for `workflow.execution_failed`.
1432
- */
1433
- workflow_execution_id?: string;
1434
- /**
1435
- * Knowledge file, for `knowledge_file.ready`.
1436
- */
1437
- knowledge_file_id?: string;
1438
- /**
1439
- * Webhook, for `webhook.test`.
1440
- */
1441
- webhook_id?: string;
1442
- };
1768
+ upload_url: string;
1443
1769
  };
1444
1770
  /**
1445
- * What the endpoint answered to a `webhook.test` event.
1771
+ * A contact card in the knowledge directory, which agents can send to customers.
1446
1772
  */
1447
- export type WebhookTestResult = {
1773
+ export type KnowledgeContact = {
1448
1774
  /**
1449
- * True when the endpoint answered 2xx.
1775
+ * Knowledge contact ID.
1450
1776
  */
1451
- delivered: boolean;
1777
+ id: string;
1778
+ /**
1779
+ * Name shown on the contact card.
1780
+ */
1781
+ display_name: string;
1452
1782
  /**
1453
- * HTTP status the endpoint answered; null if none.
1783
+ * First name.
1454
1784
  */
1455
- response_status: number | null;
1785
+ first_name: string | null;
1456
1786
  /**
1457
- * Why it failed: the HTTP status, a timeout or a refused destination.
1787
+ * Last name.
1458
1788
  */
1459
- error: string | null;
1789
+ last_name: string | null;
1460
1790
  /**
1461
- * Time until the endpoint answered.
1791
+ * Name prefix, such as `Dr.`.
1462
1792
  */
1463
- duration_ms: number;
1464
- };
1465
- /**
1466
- * What a tag change did to one contact.
1467
- */
1468
- export type ContactTagChange = {
1793
+ prefix: string | null;
1469
1794
  /**
1470
- * Contact ID.
1795
+ * Name suffix.
1471
1796
  */
1472
- contact_id: string;
1797
+ suffix: string | null;
1473
1798
  /**
1474
- * `updated`; `not_found` when the organization has no such contact; `failed` when Ricky could not save it, so retry that contact.
1799
+ * Company.
1475
1800
  */
1476
- status: 'updated' | 'not_found' | 'failed';
1801
+ company: string | null;
1477
1802
  /**
1478
- * The contact's tags after the change; null unless `updated`.
1803
+ * Department.
1479
1804
  */
1480
- tags: Array<Tag> | null;
1481
- };
1482
- /**
1483
- * A message whose text matches the search.
1484
- */
1485
- export type MessageSearchResult = {
1805
+ department: string | null;
1486
1806
  /**
1487
- * Message ID.
1807
+ * Job title.
1488
1808
  */
1489
- message_id: string;
1809
+ job_title: string | null;
1490
1810
  /**
1491
- * Conversation ID.
1811
+ * When the agents should share it.
1492
1812
  */
1493
- conversation_id: string;
1494
- direction: 'inbound' | 'outbound';
1813
+ description: string | null;
1495
1814
  /**
1496
- * Message type: `text`, `image`, `audio`, `template`, …
1815
+ * Phone in E.164.
1497
1816
  */
1498
- type: string;
1817
+ phone: string | null;
1499
1818
  /**
1500
- * The matching text: the message, or what Ricky derived from a voice note or file.
1819
+ * `CELL`, `WORK` or `HOME`.
1501
1820
  */
1502
- text: string;
1503
- contact: {
1504
- /**
1505
- * Contact name, or the name on the channel.
1506
- */
1507
- name: string | null;
1508
- /**
1509
- * Address on the channel.
1510
- */
1511
- external_id: string;
1512
- };
1821
+ phone_type: string | null;
1513
1822
  /**
1514
- * AI agent that wrote it; null otherwise.
1823
+ * Email.
1515
1824
  */
1516
- agent_name: string | null;
1825
+ email: string | null;
1517
1826
  /**
1518
- * When it was sent or received.
1827
+ * `WORK` or `PERSONAL`.
1519
1828
  */
1520
- messaged_at: string;
1829
+ email_type: string | null;
1521
1830
  };
1522
1831
  /**
1523
- * A saved answer operators insert into a message.
1832
+ * A document or image the agents can consult or send.
1524
1833
  */
1525
- export type QuickReply = {
1834
+ export type KnowledgeFile = {
1526
1835
  /**
1527
- * Quick reply ID.
1836
+ * File ID.
1528
1837
  */
1529
1838
  id: string;
1530
1839
  /**
1531
- * Name operators pick it by, unique in the organization regardless of case.
1840
+ * Title the agents see.
1532
1841
  */
1533
1842
  title: string;
1534
1843
  /**
1535
- * Text inserted into the message.
1844
+ * When the agents should use it; may be empty.
1536
1845
  */
1537
- body: string;
1538
- };
1539
- /**
1540
- * What a bulk assignment did to one conversation.
1541
- */
1542
- export type ConversationAssignmentResult = {
1846
+ description: string;
1543
1847
  /**
1544
- * Conversation ID.
1848
+ * Original file name.
1545
1849
  */
1546
- conversation_id: string;
1850
+ filename: string;
1547
1851
  /**
1548
- * Member it was to be assigned to.
1852
+ * File type.
1549
1853
  */
1550
- assigned_user_id: string;
1854
+ mime_type: 'application/pdf' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'image/jpeg' | 'image/png';
1551
1855
  /**
1552
- * `assigned`; `not_found` when the organization has no such conversation; `failed` when Ricky could not save it, so retry that conversation.
1856
+ * Size in bytes.
1553
1857
  */
1554
- status: 'assigned' | 'not_found' | 'failed';
1555
- };
1556
- /**
1557
- * The days a report covers, in America/Panama time, and the period it is compared with.
1558
- */
1559
- export type ReportPeriod = {
1858
+ size_bytes: number;
1560
1859
  /**
1561
- * First day, inclusive.
1860
+ * `uploading` until `POST /knowledge/files/{file_id}/complete` reads it; then `ready`, also when Ricky could not read useful content, which `extraction_error` then says. Ricky does not set `failed` today.
1562
1861
  */
1563
- from: string;
1862
+ status: 'uploading' | 'ready' | 'failed';
1564
1863
  /**
1565
- * Last day, inclusive. A `to` after today is today.
1864
+ * Agents may read it to answer.
1566
1865
  */
1567
- to: string;
1866
+ consult_enabled: boolean;
1568
1867
  /**
1569
- * Days in the period.
1868
+ * Agents may send the file itself to customers.
1570
1869
  */
1571
- days: number;
1870
+ send_enabled: boolean;
1572
1871
  /**
1573
- * `hour` when the period is one day: series then have 24 hourly slots.
1872
+ * Pages of a PDF; null otherwise.
1574
1873
  */
1575
- granularity: 'day' | 'hour';
1874
+ page_count: number | null;
1576
1875
  /**
1577
- * The time zone of every day and hour in the report.
1876
+ * Why Ricky could not read useful content; null when it could.
1578
1877
  */
1579
- time_zone: 'America/Panama';
1878
+ extraction_error: string | null;
1580
1879
  /**
1581
- * First day of the previous period: the same number of days, right before.
1880
+ * Signed download URL, valid for five minutes. Only `GET /knowledge/files/{file_id}` of a `ready` file carries it; null elsewhere.
1582
1881
  */
1583
- previous_from: string;
1882
+ download_url: string | null;
1584
1883
  /**
1585
- * Last day of the previous period.
1884
+ * When the upload began.
1586
1885
  */
1587
- previous_to: string;
1886
+ created_at: string;
1887
+ /**
1888
+ * Last change.
1889
+ */
1890
+ updated_at: string;
1588
1891
  };
1589
1892
  /**
1590
- * How many customers write, whether they are new, and when. Only messages customers send count: a customer is a conversation with at least one of them in the period, and it is new when its first message ever falls in the period. Messages from the team, AI agents or campaigns and conversation openings and closes play no part.
1893
+ * Everything Ricky read from a file, what the agents consult to answer.
1591
1894
  */
1592
- export type ConversationsReport = {
1593
- period: ReportPeriod;
1895
+ export type KnowledgeFileReading = {
1594
1896
  /**
1595
- * The channel filter the report applied.
1897
+ * File ID.
1596
1898
  */
1597
- channel: 'all' | 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
1899
+ file_id: string;
1598
1900
  /**
1599
- * The period.
1901
+ * In page order. Empty when Ricky read no useful content (`extraction_error`).
1600
1902
  */
1601
- totals: {
1602
- /**
1603
- * Conversations with at least one customer message in the period.
1604
- */
1605
- customers: number;
1606
- /**
1607
- * Customers whose first message ever falls in the period.
1608
- */
1609
- new_customers: number;
1903
+ sections: Array<{
1610
1904
  /**
1611
- * Customers who had written before the period.
1905
+ * PDF page it was read from; null for formats without pages.
1612
1906
  */
1613
- returning_customers: number;
1907
+ page: number | null;
1614
1908
  /**
1615
- * Messages customers sent in the period.
1909
+ * Everything Ricky read from that page, in Markdown: text in reading order, tables, and one line per picture saying what it shows.
1616
1910
  */
1617
- messages: number;
1618
- };
1911
+ text: string;
1912
+ }>;
1913
+ };
1914
+ /**
1915
+ * A file waiting for its bytes, and where to put them.
1916
+ */
1917
+ export type KnowledgeFileUpload = {
1918
+ file: KnowledgeFile;
1619
1919
  /**
1620
- * The previous period.
1920
+ * Signed URL valid for two hours. `PUT` the file bytes to it with `Content-Type` set to `mime_type`, then call `POST /knowledge/files/{file_id}/complete`.
1621
1921
  */
1622
- previous: {
1623
- /**
1624
- * Conversations with at least one customer message in the period.
1625
- */
1626
- customers: number;
1627
- /**
1628
- * Customers whose first message ever falls in the period.
1629
- */
1630
- new_customers: number;
1631
- /**
1632
- * Customers who had written before the period.
1633
- */
1634
- returning_customers: number;
1635
- /**
1636
- * Messages customers sent in the period.
1637
- */
1638
- messages: number;
1639
- };
1922
+ upload_url: string;
1923
+ };
1924
+ /**
1925
+ * A webhook subscription.
1926
+ */
1927
+ export type Webhook = {
1640
1928
  /**
1641
- * The period per channel, most customers first.
1929
+ * Webhook ID.
1642
1930
  */
1643
- by_channel: Array<{
1644
- /**
1645
- * Channel.
1646
- */
1647
- channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
1648
- /**
1649
- * Conversations with at least one customer message in the period.
1650
- */
1651
- customers: number;
1652
- /**
1653
- * Customers whose first message ever falls in the period.
1654
- */
1655
- new_customers: number;
1656
- /**
1657
- * Customers who had written before the period.
1658
- */
1659
- returning_customers: number;
1660
- /**
1661
- * Messages customers sent in the period.
1662
- */
1663
- messages: number;
1664
- }>;
1931
+ id: string;
1665
1932
  /**
1666
- * One entry per day of the period, or per hour of a one-day period.
1933
+ * HTTPS endpoint Ricky posts to.
1667
1934
  */
1668
- series: Array<{
1669
- /**
1670
- * America/Panama day `YYYY-MM-DD`, or hour `YYYY-MM-DDTHH` when the period is one day.
1671
- */
1672
- slot: string;
1673
- /**
1674
- * Customers whose first message ever falls in this slot.
1675
- */
1676
- new_customers: number;
1677
- /**
1678
- * Customers who wrote in this slot and had written before.
1679
- */
1680
- returning_customers: number;
1681
- previous_customers: number | null;
1682
- }>;
1935
+ url: string;
1936
+ event_types: Array<'message.received' | 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'conversation.opened' | 'conversation.closed' | 'conversation.assignment_changed' | 'conversation.agent_changed' | 'conversation.handoff_requested' | 'conversation.handoff_resolved' | 'contact.created' | 'contact.updated' | 'contact.tags_changed' | 'broadcast.completed' | 'broadcast.failed' | 'template.status_changed' | 'workflow.execution_failed' | 'knowledge_file.ready'>;
1937
+ status: 'active' | 'disabled';
1938
+ /**
1939
+ * When it was created.
1940
+ */
1941
+ created_at: string;
1942
+ /**
1943
+ * When it was disabled.
1944
+ */
1945
+ disabled_at: string | null;
1946
+ };
1947
+ /**
1948
+ * A new webhook subscription with its signing secret.
1949
+ */
1950
+ export type CreatedWebhook = {
1683
1951
  /**
1684
- * Customer messages of the period per weekday and hour; slots without any are left out.
1952
+ * Webhook ID.
1685
1953
  */
1686
- heatmap: Array<{
1687
- /**
1688
- * 0 is Sunday, 6 is Saturday.
1689
- */
1690
- day_of_week: number;
1691
- /**
1692
- * Hour of the day, 0–23.
1693
- */
1694
- hour: number;
1695
- /**
1696
- * Customer messages in that hour of that weekday.
1697
- */
1698
- messages: number;
1699
- }>;
1954
+ id: string;
1700
1955
  /**
1701
- * When Ricky computed the report.
1956
+ * HTTPS endpoint Ricky posts to.
1702
1957
  */
1703
- generated_at: string;
1958
+ url: string;
1959
+ event_types: Array<'message.received' | 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'conversation.opened' | 'conversation.closed' | 'conversation.assignment_changed' | 'conversation.agent_changed' | 'conversation.handoff_requested' | 'conversation.handoff_resolved' | 'contact.created' | 'contact.updated' | 'contact.tags_changed' | 'broadcast.completed' | 'broadcast.failed' | 'template.status_changed' | 'workflow.execution_failed' | 'knowledge_file.ready'>;
1960
+ status: 'active' | 'disabled';
1961
+ /**
1962
+ * When it was created.
1963
+ */
1964
+ created_at: string;
1965
+ /**
1966
+ * When it was disabled.
1967
+ */
1968
+ disabled_at: string | null;
1969
+ /**
1970
+ * HMAC key for `X-Ricky-Signature`. Returned only here, once.
1971
+ */
1972
+ signing_secret: string;
1704
1973
  };
1705
1974
  /**
1706
- * Messages received from customers and sent to them in the period, and who sent them, dated when each message was sent.
1975
+ * One webhook delivery.
1707
1976
  */
1708
- export type MessagesReport = {
1709
- period: ReportPeriod;
1977
+ export type WebhookDelivery = {
1710
1978
  /**
1711
- * The channel filter the report applied.
1979
+ * Delivery ID; equals the event `id` and `X-Ricky-Delivery-Id`.
1712
1980
  */
1713
- channel: 'all' | 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
1981
+ id: string;
1982
+ event_type: 'message.received' | 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'conversation.opened' | 'conversation.closed' | 'conversation.assignment_changed' | 'conversation.agent_changed' | 'conversation.handoff_requested' | 'conversation.handoff_resolved' | 'contact.created' | 'contact.updated' | 'contact.tags_changed' | 'broadcast.completed' | 'broadcast.failed' | 'template.status_changed' | 'workflow.execution_failed' | 'knowledge_file.ready';
1983
+ status: 'pending' | 'processing' | 'delivered' | 'failed';
1714
1984
  /**
1715
- * The period.
1985
+ * Delivery attempts so far; Ricky makes at most ten.
1716
1986
  */
1717
- totals: {
1718
- /**
1719
- * Messages customers sent.
1720
- */
1721
- received: number;
1722
- /**
1723
- * Messages sent to customers, by anyone; the sum of `sent_by`.
1724
- */
1725
- sent: number;
1726
- /**
1727
- * Sent messages by sender; each message counts in one of them.
1728
- */
1729
- sent_by: {
1730
- /**
1731
- * Sent by a person in Ricky.
1732
- */
1733
- human: number;
1734
- /**
1735
- * Sent by an AI agent.
1736
- */
1737
- ai: number;
1738
- /**
1739
- * Sent by an automation.
1740
- */
1741
- automation: number;
1742
- /**
1743
- * Templates not sent by an automation: broadcasts and templates sent by hand or through the API.
1744
- */
1745
- campaign: number;
1746
- /**
1747
- * Sent from the channel's own app, with no sender in Ricky: WhatsApp Business app coexistence and imported history.
1748
- */
1749
- external: number;
1750
- };
1751
- };
1987
+ attempts: number;
1752
1988
  /**
1753
- * The previous period.
1989
+ * HTTP status of the last attempt.
1754
1990
  */
1755
- previous: {
1756
- /**
1757
- * Messages customers sent.
1758
- */
1759
- received: number;
1760
- /**
1761
- * Messages sent to customers, by anyone; the sum of `sent_by`.
1762
- */
1763
- sent: number;
1764
- /**
1765
- * Sent messages by sender; each message counts in one of them.
1766
- */
1767
- sent_by: {
1768
- /**
1769
- * Sent by a person in Ricky.
1770
- */
1771
- human: number;
1772
- /**
1773
- * Sent by an AI agent.
1774
- */
1775
- ai: number;
1776
- /**
1777
- * Sent by an automation.
1778
- */
1779
- automation: number;
1780
- /**
1781
- * Templates not sent by an automation: broadcasts and templates sent by hand or through the API.
1782
- */
1783
- campaign: number;
1784
- /**
1785
- * Sent from the channel's own app, with no sender in Ricky: WhatsApp Business app coexistence and imported history.
1786
- */
1787
- external: number;
1788
- };
1789
- };
1991
+ last_response_status: number | null;
1790
1992
  /**
1791
- * The period per channel, most messages first.
1993
+ * Why the last attempt failed.
1792
1994
  */
1793
- by_channel: Array<{
1794
- /**
1795
- * Channel.
1796
- */
1797
- channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
1798
- /**
1799
- * Messages customers sent.
1800
- */
1801
- received: number;
1802
- /**
1803
- * Messages sent to customers, by anyone; the sum of `sent_by`.
1804
- */
1805
- sent: number;
1806
- /**
1807
- * Sent messages by sender; each message counts in one of them.
1808
- */
1809
- sent_by: {
1810
- /**
1811
- * Sent by a person in Ricky.
1812
- */
1813
- human: number;
1814
- /**
1815
- * Sent by an AI agent.
1816
- */
1817
- ai: number;
1818
- /**
1819
- * Sent by an automation.
1820
- */
1821
- automation: number;
1822
- /**
1823
- * Templates not sent by an automation: broadcasts and templates sent by hand or through the API.
1824
- */
1825
- campaign: number;
1826
- /**
1827
- * Sent from the channel's own app, with no sender in Ricky: WhatsApp Business app coexistence and imported history.
1828
- */
1829
- external: number;
1830
- };
1831
- }>;
1995
+ last_error: string | null;
1832
1996
  /**
1833
- * One entry per day of the period, or per hour of a one-day period.
1997
+ * When the event happened.
1834
1998
  */
1835
- series: Array<{
1999
+ created_at: string;
2000
+ /**
2001
+ * When Ricky tries next, while pending.
2002
+ */
2003
+ next_attempt_at: string;
2004
+ /**
2005
+ * When the endpoint answered 2xx.
2006
+ */
2007
+ delivered_at: string | null;
2008
+ };
2009
+ /**
2010
+ * The JSON body Ricky posts to a webhook endpoint.
2011
+ */
2012
+ export type WebhookEvent = {
2013
+ /**
2014
+ * Delivery ID. Deduplicate by it.
2015
+ */
2016
+ id: string;
2017
+ type: 'message.received' | 'message.sent' | 'message.delivered' | 'message.read' | 'message.failed' | 'conversation.opened' | 'conversation.closed' | 'conversation.assignment_changed' | 'conversation.agent_changed' | 'conversation.handoff_requested' | 'conversation.handoff_resolved' | 'contact.created' | 'contact.updated' | 'contact.tags_changed' | 'broadcast.completed' | 'broadcast.failed' | 'template.status_changed' | 'workflow.execution_failed' | 'knowledge_file.ready' | 'webhook.test';
2018
+ /**
2019
+ * When it happened.
2020
+ */
2021
+ occurred_at: string;
2022
+ /**
2023
+ * Organization.
2024
+ */
2025
+ organization_id: string;
2026
+ data: {
1836
2027
  /**
1837
- * America/Panama day `YYYY-MM-DD`, or hour `YYYY-MM-DDTHH` when the period is one day.
2028
+ * Conversation, for `message.*` and `conversation.*` events.
1838
2029
  */
1839
- slot: string;
2030
+ conversation_id?: string;
1840
2031
  /**
1841
- * Messages customers sent.
2032
+ * Message, for `message.*` events.
1842
2033
  */
1843
- received: number;
2034
+ message_id?: string;
1844
2035
  /**
1845
- * Messages sent to customers, by anyone; the sum of `sent_by`.
2036
+ * Meta's ID of the ad the customer came from, for a `message.received` whose message carries an ad referral. Read the message for the rest of the referral.
1846
2037
  */
1847
- sent: number;
2038
+ ad_id?: string;
1848
2039
  /**
1849
- * Sent messages by sender; each message counts in one of them.
2040
+ * Contact, for `contact.*` events.
1850
2041
  */
1851
- sent_by: {
1852
- /**
1853
- * Sent by a person in Ricky.
1854
- */
1855
- human: number;
1856
- /**
1857
- * Sent by an AI agent.
1858
- */
1859
- ai: number;
1860
- /**
1861
- * Sent by an automation.
1862
- */
1863
- automation: number;
1864
- /**
1865
- * Templates not sent by an automation: broadcasts and templates sent by hand or through the API.
1866
- */
1867
- campaign: number;
1868
- /**
1869
- * Sent from the channel's own app, with no sender in Ricky: WhatsApp Business app coexistence and imported history.
1870
- */
1871
- external: number;
1872
- };
1873
- previous_received: number | null;
1874
- previous_sent: number | null;
1875
- }>;
1876
- /**
1877
- * When Ricky computed the report.
1878
- */
1879
- generated_at: string;
1880
- };
1881
- /**
1882
- * What the inbox looks like right now; it has no period.
1883
- */
1884
- export type DashboardReport = {
1885
- /**
1886
- * Now.
1887
- */
1888
- totals: {
2042
+ contact_id?: string;
1889
2043
  /**
1890
- * Open conversations.
2044
+ * Broadcast, for `broadcast.*` events.
1891
2045
  */
1892
- open_now: number;
2046
+ broadcast_id?: string;
1893
2047
  /**
1894
- * Open conversations with no member or AI agent assigned.
2048
+ * Template ID at Meta, for `template.status_changed`.
1895
2049
  */
1896
- unassigned: number;
2050
+ template_id?: string;
1897
2051
  /**
1898
- * Open conversations whose last message, reactions aside, is from the customer.
2052
+ * Workflow, for `workflow.execution_failed`.
1899
2053
  */
1900
- awaiting_reply: number;
2054
+ workflow_id?: string;
1901
2055
  /**
1902
- * Handoffs from an AI agent to a person still waiting.
2056
+ * Execution, for `workflow.execution_failed`.
1903
2057
  */
1904
- pending_handoffs: number;
2058
+ workflow_execution_id?: string;
1905
2059
  /**
1906
- * Conversations opened or reopened today, America/Panama.
2060
+ * Knowledge file, for `knowledge_file.ready`.
1907
2061
  */
1908
- opened_today: number;
2062
+ knowledge_file_id?: string;
1909
2063
  /**
1910
- * Conversations closed today, America/Panama.
2064
+ * Webhook, for `webhook.test`.
1911
2065
  */
1912
- closed_today: number;
2066
+ webhook_id?: string;
1913
2067
  };
2068
+ };
2069
+ /**
2070
+ * What the endpoint answered to a `webhook.test` event.
2071
+ */
2072
+ export type WebhookTestResult = {
1914
2073
  /**
1915
- * Open conversations per channel, most first.
2074
+ * True when the endpoint answered 2xx.
1916
2075
  */
1917
- by_channel: Array<{
1918
- /**
1919
- * Channel.
1920
- */
1921
- channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
1922
- /**
1923
- * Open conversations.
1924
- */
1925
- open: number;
1926
- }>;
2076
+ delivered: boolean;
1927
2077
  /**
1928
- * Open conversations per assignee, most first.
2078
+ * HTTP status the endpoint answered; null if none.
1929
2079
  */
1930
- assignees: Array<{
1931
- /**
1932
- * `human` is a member, `ai` an AI agent, `unassigned` nobody.
1933
- */
1934
- type: 'human' | 'ai' | 'unassigned';
1935
- /**
1936
- * User ID or AI agent ID; null for `unassigned`.
1937
- */
1938
- id: string | null;
2080
+ response_status: number | null;
2081
+ /**
2082
+ * Why it failed: the HTTP status, a timeout or a refused destination.
2083
+ */
2084
+ error: string | null;
2085
+ /**
2086
+ * Time until the endpoint answered.
2087
+ */
2088
+ duration_ms: number;
2089
+ };
2090
+ /**
2091
+ * What a tag change did to one contact.
2092
+ */
2093
+ export type ContactTagChange = {
2094
+ /**
2095
+ * Contact ID.
2096
+ */
2097
+ contact_id: string;
2098
+ /**
2099
+ * `updated`; `not_found` when the organization has no such contact; `failed` when Ricky could not save it, so retry that contact.
2100
+ */
2101
+ status: 'updated' | 'not_found' | 'failed';
2102
+ /**
2103
+ * The contact's tags after the change; null unless `updated`.
2104
+ */
2105
+ tags: Array<Tag> | null;
2106
+ };
2107
+ /**
2108
+ * A message whose text matches the search.
2109
+ */
2110
+ export type MessageSearchResult = {
2111
+ /**
2112
+ * Message ID.
2113
+ */
2114
+ message_id: string;
2115
+ /**
2116
+ * Conversation ID.
2117
+ */
2118
+ conversation_id: string;
2119
+ direction: 'inbound' | 'outbound';
2120
+ /**
2121
+ * Message type: `text`, `image`, `audio`, `template`, …
2122
+ */
2123
+ type: string;
2124
+ /**
2125
+ * The matching text: the message, or what Ricky derived from a voice note or file.
2126
+ */
2127
+ text: string;
2128
+ contact: {
1939
2129
  /**
1940
- * Name; null when it has none and for `unassigned`.
2130
+ * Contact name, or the name on the channel.
1941
2131
  */
1942
2132
  name: string | null;
1943
2133
  /**
1944
- * Open conversations they hold.
1945
- */
1946
- open: number;
1947
- /**
1948
- * Of those, the ones whose last message is from the customer.
2134
+ * Address on the channel.
1949
2135
  */
1950
- awaiting_reply: number;
1951
- }>;
2136
+ external_id: string;
2137
+ };
1952
2138
  /**
1953
- * The 15 open conversations waiting longest for a reply, oldest first.
2139
+ * AI agent that wrote it; null otherwise.
1954
2140
  */
1955
- longest_waiting: Array<{
2141
+ agent_name: string | null;
2142
+ /**
2143
+ * When it was sent or received.
2144
+ */
2145
+ messaged_at: string;
2146
+ };
2147
+ /**
2148
+ * A saved answer operators insert into a message.
2149
+ */
2150
+ export type QuickReply = {
2151
+ /**
2152
+ * Quick reply ID.
2153
+ */
2154
+ id: string;
2155
+ /**
2156
+ * Name operators pick it by, unique in the organization regardless of case.
2157
+ */
2158
+ title: string;
2159
+ /**
2160
+ * Text inserted into the message.
2161
+ */
2162
+ body: string;
2163
+ };
2164
+ export type GoogleAdsAccountReport = {
2165
+ account: {
2166
+ id: string;
2167
+ name: string;
2168
+ currency_code: string;
1956
2169
  /**
1957
- * Conversation ID.
2170
+ * Time zone used for Google Ads campaign metrics.
1958
2171
  */
1959
- conversation_id: string;
2172
+ time_zone: string;
2173
+ };
2174
+ status: 'ready' | 'access_denied' | 'unavailable';
2175
+ campaigns: Array<{
2176
+ id: string;
2177
+ name: string;
2178
+ status: string;
1960
2179
  /**
1961
- * Channel.
2180
+ * Spend in the account currency.
1962
2181
  */
1963
- channel: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
2182
+ spend: number;
2183
+ clicks: number;
2184
+ impressions: number;
1964
2185
  /**
1965
- * Customer name as the inbox shows it: the contact’s saved name, else the channel profile name, else the contact’s phone.
2186
+ * Conversions as Google reports them.
1966
2187
  */
1967
- participant_name: string | null;
2188
+ conversions: number;
1968
2189
  /**
1969
- * When the customer message they wait on arrived.
2190
+ * Code that can be placed in this campaign’s prefilled WhatsApp message.
1970
2191
  */
1971
- waiting_since: string;
2192
+ conversation_code: string;
1972
2193
  /**
1973
- * `human` is a member, `ai` an AI agent, `unassigned` nobody.
2194
+ * Distinct WhatsApp conversations in Ricky whose inbound message contains the campaign code, in America/Panama days.
1974
2195
  */
1975
- assignee_type: 'human' | 'ai' | 'unassigned';
2196
+ conversation_count: number;
1976
2197
  /**
1977
- * Assignee name; null when there is none.
2198
+ * Up to ten recent matching Ricky conversations.
1978
2199
  */
1979
- assignee_name: string | null;
2200
+ recent_conversation_ids: Array<string>;
1980
2201
  }>;
2202
+ };
2203
+ /**
2204
+ * What a bulk assignment did to one conversation.
2205
+ */
2206
+ export type ConversationAssignmentResult = {
1981
2207
  /**
1982
- * When Ricky computed the report.
2208
+ * Conversation ID.
1983
2209
  */
1984
- generated_at: string;
2210
+ conversation_id: string;
2211
+ /**
2212
+ * Member it was to be assigned to.
2213
+ */
2214
+ assigned_user_id: string;
2215
+ /**
2216
+ * `assigned`; `not_found` when the organization has no such conversation; `failed` when Ricky could not save it, so retry that conversation.
2217
+ */
2218
+ status: 'assigned' | 'not_found' | 'failed';
1985
2219
  };
1986
2220
  /**
1987
2221
  * People and AI agents side by side: what they were assigned, what they sent, what they closed and how fast.
@@ -3447,118 +3681,54 @@ export type WhatsAppNumber = {
3447
3681
  */
3448
3682
  inbound_processing_enabled: boolean | null;
3449
3683
  /**
3450
- * Whether customers can call the number and reach the AI agent.
3451
- */
3452
- calls_enabled: boolean | null;
3453
- /**
3454
- * When it was connected.
3455
- */
3456
- connected_at: string | null;
3457
- /**
3458
- * When Ricky last read its details from Meta.
3459
- */
3460
- last_synced_at: string | null;
3461
- /**
3462
- * Review status of the display name at Meta, in lowercase: for example `approved`, `pending_review` or `declined`.
3463
- */
3464
- name_status: string | null;
3465
- /**
3466
- * The business profile customers see on WhatsApp, as Ricky last read it from Meta.
3467
- */
3468
- business_profile: {
3469
- /**
3470
- * Short text under the business name.
3471
- */
3472
- about: string | null;
3473
- /**
3474
- * Description of the business.
3475
- */
3476
- description: string | null;
3477
- /**
3478
- * Address of the business.
3479
- */
3480
- address: string | null;
3481
- /**
3482
- * Contact email.
3483
- */
3484
- email: string | null;
3485
- /**
3486
- * Industry as Meta names it.
3487
- */
3488
- vertical: string | null;
3489
- /**
3490
- * Website URLs.
3491
- */
3492
- websites: Array<string>;
3493
- /**
3494
- * Link to the profile photo at Meta; it expires.
3495
- */
3496
- profile_picture_url: string | null;
3497
- };
3498
- };
3499
- /**
3500
- * Only `name` is required; it does not connect the agent to any channel.
3501
- */
3502
- export type CreateAgent = {
3503
- /**
3504
- * Name the team sees.
3505
- */
3506
- name: string;
3507
- /**
3508
- * What the agent is for.
3509
- */
3510
- description?: string | null;
3511
- /**
3512
- * How the agent answers customers.
3513
- */
3514
- instructions?: string | null;
3515
- /**
3516
- * A voice of `GET /agent-options`. Without one, the default voice.
3517
- */
3518
- voice?: string;
3519
- /**
3520
- * The complete set of capability names. Replaces the current ones.
3521
- */
3522
- capabilities?: Array<string>;
3523
- /**
3524
- * The complete set of members who receive handed-off conversations. Required with `ricky.handoff.request`.
3525
- */
3526
- handoff_user_ids?: Array<string>;
3527
- };
3528
- /**
3529
- * Only the fields you send change. Send `null` to clear a text.
3530
- */
3531
- export type UpdateAgent = {
3532
- /**
3533
- * Name the team sees.
3534
- */
3535
- name?: string;
3536
- /**
3537
- * What the agent is for.
3538
- */
3539
- description?: string | null;
3540
- /**
3541
- * How the agent answers customers.
3684
+ * Whether customers can call the number and reach the AI agent.
3542
3685
  */
3543
- instructions?: string | null;
3686
+ calls_enabled: boolean | null;
3544
3687
  /**
3545
- * A voice of `GET /agent-options`. Without one, the default voice.
3688
+ * When it was connected.
3546
3689
  */
3547
- voice?: string;
3690
+ connected_at: string | null;
3548
3691
  /**
3549
- * The complete set of capability names. Replaces the current ones.
3692
+ * When Ricky last read its details from Meta.
3550
3693
  */
3551
- capabilities?: Array<string>;
3694
+ last_synced_at: string | null;
3552
3695
  /**
3553
- * The complete set of members who receive handed-off conversations. Required with `ricky.handoff.request`.
3696
+ * Review status of the display name at Meta, in lowercase: for example `approved`, `pending_review` or `declined`.
3554
3697
  */
3555
- handoff_user_ids?: Array<string>;
3556
- };
3557
- export type AssignConversationAgent = {
3698
+ name_status: string | null;
3558
3699
  /**
3559
- * Agent that answers from now on; null turns the AI off for the conversation.
3700
+ * The business profile customers see on WhatsApp, as Ricky last read it from Meta.
3560
3701
  */
3561
- agent_id: string | null;
3702
+ business_profile: {
3703
+ /**
3704
+ * Short text under the business name.
3705
+ */
3706
+ about: string | null;
3707
+ /**
3708
+ * Description of the business.
3709
+ */
3710
+ description: string | null;
3711
+ /**
3712
+ * Address of the business.
3713
+ */
3714
+ address: string | null;
3715
+ /**
3716
+ * Contact email.
3717
+ */
3718
+ email: string | null;
3719
+ /**
3720
+ * Industry as Meta names it.
3721
+ */
3722
+ vertical: string | null;
3723
+ /**
3724
+ * Website URLs.
3725
+ */
3726
+ websites: Array<string>;
3727
+ /**
3728
+ * Link to the profile photo at Meta; it expires.
3729
+ */
3730
+ profile_picture_url: string | null;
3731
+ };
3562
3732
  };
3563
3733
  /**
3564
3734
  * How the handoff ends.
@@ -3939,6 +4109,70 @@ export type RotateWebhookSecret = {
3939
4109
  */
3940
4110
  expire_previous_after_hours?: number;
3941
4111
  };
4112
+ /**
4113
+ * Only `name` is required; it does not connect the agent to any channel.
4114
+ */
4115
+ export type CreateAgent = {
4116
+ /**
4117
+ * Name the team sees.
4118
+ */
4119
+ name: string;
4120
+ /**
4121
+ * What the agent is for.
4122
+ */
4123
+ description?: string | null;
4124
+ /**
4125
+ * How the agent answers customers.
4126
+ */
4127
+ instructions?: string | null;
4128
+ /**
4129
+ * A voice of `GET /agent-options`. Without one, the default voice.
4130
+ */
4131
+ voice?: string;
4132
+ /**
4133
+ * The complete set of capability names. Replaces the current ones.
4134
+ */
4135
+ capabilities?: Array<string>;
4136
+ /**
4137
+ * The complete set of members who receive handed-off conversations. Required with `ricky.handoff.request`.
4138
+ */
4139
+ handoff_user_ids?: Array<string>;
4140
+ };
4141
+ /**
4142
+ * Only the fields you send change. Send `null` to clear a text.
4143
+ */
4144
+ export type UpdateAgent = {
4145
+ /**
4146
+ * Name the team sees.
4147
+ */
4148
+ name?: string;
4149
+ /**
4150
+ * What the agent is for.
4151
+ */
4152
+ description?: string | null;
4153
+ /**
4154
+ * How the agent answers customers.
4155
+ */
4156
+ instructions?: string | null;
4157
+ /**
4158
+ * A voice of `GET /agent-options`. Without one, the default voice.
4159
+ */
4160
+ voice?: string;
4161
+ /**
4162
+ * The complete set of capability names. Replaces the current ones.
4163
+ */
4164
+ capabilities?: Array<string>;
4165
+ /**
4166
+ * The complete set of members who receive handed-off conversations. Required with `ricky.handoff.request`.
4167
+ */
4168
+ handoff_user_ids?: Array<string>;
4169
+ };
4170
+ export type AssignConversationAgent = {
4171
+ /**
4172
+ * Agent that answers from now on; null turns the AI off for the conversation.
4173
+ */
4174
+ agent_id: string | null;
4175
+ };
3942
4176
  /**
3943
4177
  * Sends an approved template to many numbers, now or at a set time.
3944
4178
  */
@@ -5521,6 +5755,26 @@ export type ListContactsData = {
5521
5755
  * Only contacts reachable on this channel.
5522
5756
  */
5523
5757
  channel?: 'whatsapp' | 'instagram' | 'messenger' | 'webchat';
5758
+ /**
5759
+ * Only contacts with a customer message, in any of their conversations, from this Meta ad. Ad filters apply together to one customer message: from that ad, campaign or ad set, at that time.
5760
+ */
5761
+ ad_id?: string;
5762
+ /**
5763
+ * Only contacts with a customer message, in any of their conversations, from an ad of this Meta campaign. Matches the ads Ricky synced from a connected ad account.
5764
+ */
5765
+ campaign_id?: string;
5766
+ /**
5767
+ * Only contacts with a customer message, in any of their conversations, from an ad of this Meta ad set. Matches the ads Ricky synced from a connected ad account.
5768
+ */
5769
+ ad_set_id?: string;
5770
+ /**
5771
+ * Only contacts with a customer message, in any of their conversations, from a Meta ad sent at or after this time, ISO 8601.
5772
+ */
5773
+ referred_after?: string;
5774
+ /**
5775
+ * Only contacts with a customer message, in any of their conversations, from a Meta ad sent before this time, ISO 8601.
5776
+ */
5777
+ referred_before?: string;
5524
5778
  };
5525
5779
  url: '/contacts';
5526
5780
  };
@@ -5954,6 +6208,34 @@ export type ListConversationsData = {
5954
6208
  * `customer`: only conversations whose latest message came from the contact.
5955
6209
  */
5956
6210
  last_message_from?: 'customer';
6211
+ /**
6212
+ * Only conversations whose latest message is at or after this time, ISO 8601.
6213
+ */
6214
+ last_activity_after?: string;
6215
+ /**
6216
+ * Only conversations whose latest message is before this time, ISO 8601.
6217
+ */
6218
+ last_activity_before?: string;
6219
+ /**
6220
+ * Only conversations with a customer message from this Meta ad. Ad filters apply together to one customer message: from that ad, campaign or ad set, at that time.
6221
+ */
6222
+ ad_id?: string;
6223
+ /**
6224
+ * Only conversations with a customer message from an ad of this Meta campaign. Matches the ads Ricky synced from a connected ad account.
6225
+ */
6226
+ campaign_id?: string;
6227
+ /**
6228
+ * Only conversations with a customer message from an ad of this Meta ad set. Matches the ads Ricky synced from a connected ad account.
6229
+ */
6230
+ ad_set_id?: string;
6231
+ /**
6232
+ * Only conversations with a customer message from a Meta ad sent at or after this time, ISO 8601.
6233
+ */
6234
+ referred_after?: string;
6235
+ /**
6236
+ * Only conversations with a customer message from a Meta ad sent before this time, ISO 8601.
6237
+ */
6238
+ referred_before?: string;
5957
6239
  };
5958
6240
  url: '/conversations';
5959
6241
  };
@@ -8393,6 +8675,144 @@ export type GetMetaAdsInsightsResponses = {
8393
8675
  };
8394
8676
  };
8395
8677
  export type GetMetaAdsInsightsResponse = GetMetaAdsInsightsResponses[keyof GetMetaAdsInsightsResponses];
8678
+ export type ListAdConversationsData = {
8679
+ body?: never;
8680
+ path?: never;
8681
+ query?: {
8682
+ /**
8683
+ * First day, `YYYY-MM-DD`, America/Panama, inclusive. Send it with `to`; without both, the report covers the last 7 days including today.
8684
+ */
8685
+ from?: string;
8686
+ /**
8687
+ * Last day, `YYYY-MM-DD`, America/Panama, inclusive. A day after today counts as today. The period is at most 366 days.
8688
+ */
8689
+ to?: string;
8690
+ /**
8691
+ * Only this Meta ad.
8692
+ */
8693
+ ad_id?: string;
8694
+ /**
8695
+ * Only ads of this Meta campaign, among the ads Ricky synced from a connected ad account.
8696
+ */
8697
+ campaign_id?: string;
8698
+ /**
8699
+ * Only ads of this Meta ad set, among the ads Ricky synced from a connected ad account.
8700
+ */
8701
+ ad_set_id?: string;
8702
+ /**
8703
+ * Only conversations on this channel.
8704
+ */
8705
+ channel?: 'whatsapp' | 'instagram' | 'messenger';
8706
+ /**
8707
+ * Items per page.
8708
+ */
8709
+ page_size?: number;
8710
+ /**
8711
+ * `next_cursor` from the previous page. Use it unchanged.
8712
+ */
8713
+ cursor?: string;
8714
+ };
8715
+ url: '/ads/conversations';
8716
+ };
8717
+ export type ListAdConversationsErrors = {
8718
+ /**
8719
+ * `invalid_input`: A parameter or body field is invalid; `param` names it when known.
8720
+ */
8721
+ 400: Error;
8722
+ /**
8723
+ * `unauthorized`: The `Authorization` header is missing, malformed, expired or revoked.
8724
+ */
8725
+ 401: Error;
8726
+ /**
8727
+ * `insufficient_scope`: The key lacks the scope this operation requires.
8728
+ */
8729
+ 403: Error;
8730
+ /**
8731
+ * `rate_limited`: More than 120 requests this minute with this key; see `Retry-After`.
8732
+ */
8733
+ 429: Error;
8734
+ /**
8735
+ * `internal_error`: Ricky failed. Retry a read. Before retrying a write, read the resource: the same `Idempotency-Key` answers `request_processing`.
8736
+ */
8737
+ 500: Error;
8738
+ };
8739
+ export type ListAdConversationsError = ListAdConversationsErrors[keyof ListAdConversationsErrors];
8740
+ export type ListAdConversationsResponses = {
8741
+ /**
8742
+ * Success.
8743
+ */
8744
+ 200: {
8745
+ data: Array<AdConversation>;
8746
+ /**
8747
+ * Pass as `cursor` for the next page; null on the last page.
8748
+ */
8749
+ next_cursor: string | null;
8750
+ };
8751
+ };
8752
+ export type ListAdConversationsResponse = ListAdConversationsResponses[keyof ListAdConversationsResponses];
8753
+ export type GetGoogleAdsCampaignReportData = {
8754
+ body?: never;
8755
+ path?: never;
8756
+ query: {
8757
+ /**
8758
+ * A Google Ads account selected in Integrations.
8759
+ */
8760
+ account_id?: string;
8761
+ /**
8762
+ * Only this Google Ads campaign.
8763
+ */
8764
+ campaign_id?: string;
8765
+ /**
8766
+ * First day, inclusive.
8767
+ */
8768
+ from: string;
8769
+ /**
8770
+ * Last day, inclusive. A period can contain up to 366 days.
8771
+ */
8772
+ to: string;
8773
+ };
8774
+ url: '/ads/google/campaigns';
8775
+ };
8776
+ export type GetGoogleAdsCampaignReportErrors = {
8777
+ /**
8778
+ * `invalid_input`: A parameter or body field is invalid; `param` names it when known.
8779
+ */
8780
+ 400: Error;
8781
+ /**
8782
+ * `unauthorized`: The `Authorization` header is missing, malformed, expired or revoked.
8783
+ */
8784
+ 401: Error;
8785
+ /**
8786
+ * `insufficient_scope`: The key lacks the scope this operation requires.
8787
+ */
8788
+ 403: Error;
8789
+ /**
8790
+ * `not_found`: The resource does not exist in this organization.
8791
+ */
8792
+ 404: Error;
8793
+ /**
8794
+ * `rate_limited`: More than 120 requests this minute with this key; see `Retry-After`.
8795
+ */
8796
+ 429: Error;
8797
+ /**
8798
+ * `internal_error`: Ricky failed. Retry a read. Before retrying a write, read the resource: the same `Idempotency-Key` answers `request_processing`.
8799
+ */
8800
+ 500: Error;
8801
+ };
8802
+ export type GetGoogleAdsCampaignReportError = GetGoogleAdsCampaignReportErrors[keyof GetGoogleAdsCampaignReportErrors];
8803
+ export type GetGoogleAdsCampaignReportResponses = {
8804
+ /**
8805
+ * Success.
8806
+ */
8807
+ 200: {
8808
+ data: Array<GoogleAdsAccountReport>;
8809
+ /**
8810
+ * Pass as `cursor` for the next page; null on the last page.
8811
+ */
8812
+ next_cursor: string | null;
8813
+ };
8814
+ };
8815
+ export type GetGoogleAdsCampaignReportResponse = GetGoogleAdsCampaignReportResponses[keyof GetGoogleAdsCampaignReportResponses];
8396
8816
  export type ListAgentsData = {
8397
8817
  body?: never;
8398
8818
  path?: never;