@periskope/types 0.6.176 → 0.6.177

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/types.ts CHANGED
@@ -1,852 +1,856 @@
1
- import type { default as _Stripe } from 'stripe';
2
- import { Merge, OverrideProperties } from 'type-fest';
3
- import { Filter, Rule } from './rules.types';
4
- import { Tables, TablesUpdate } from './supabase.types';
5
-
6
- /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
7
-
8
- /* ------------------------------ PERISKOPE TYPES ------------------------------ */
9
-
10
- export enum AllPlans {
11
- FREE_TRIAL = 'free-trial',
12
- // MONTHLY_STARTER = 'monthly-starter',
13
- // YEARLY_STARTER = 'yearly-starter',
14
- // MONTHLY_PRO = 'monthly-pro',
15
- // YEARLY_PRO = 'yearly-pro',
16
- ENTERPRISE = 'enterprise',
17
- MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
18
- YEARLY_STARTER_SINGLE = 'yearly-starter-single',
19
- MONTHLY_PRO_SINGLE = 'monthly-pro-single',
20
- YEARLY_PRO_SINGLE = 'yearly-pro-single',
21
- }
22
-
23
- export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
24
-
25
- export type Enterprise = `${string}-enterprise`;
26
-
27
- export type OrgPlanEnterprise = {
28
- subscription_id: string;
29
- plan_id: Enterprise;
30
- interval: number;
31
- frequency: Frequency;
32
- user_limit: number;
33
- phone_limit: number;
34
- current_period_start: number;
35
- current_period_end: number | null;
36
- };
37
-
38
- export type OrgPlanNonEnterprise = {
39
- subscription_id: string;
40
- plan_id: AllPlans;
41
- interval: number;
42
- frequency: Frequency;
43
- user_limit: number;
44
- phone_limit: number;
45
- current_period_end: number;
46
- current_period_start: number;
47
- };
48
-
49
- export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
50
- ? OrgPlanEnterprise
51
- : T extends AllPlans
52
- ? OrgPlanNonEnterprise
53
- : never;
54
-
55
- export type MicrosurveyData = {
56
- key: string;
57
- text: string;
58
- checked: boolean;
59
- }[];
60
-
61
- export type OrgPreferences = {
62
- disable_ai_flagging?: boolean;
63
- disable_allow_exports?: boolean;
64
- sync_phone_contacts?: boolean;
65
- mask_phone_numbers?: boolean;
66
- show_sender_names?: boolean;
67
- closed_chats?: Record<string, number>;
68
- auto_read_muted_chats?: boolean;
69
- };
70
-
71
- type OrgPreferenceKey = keyof OrgPreferences;
72
-
73
- export type OrgPreferencesValue = {
74
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
75
- }[OrgPreferenceKey];
76
-
77
- export type OrgMetadata = {
78
- phone_number: string;
79
- ticket_prefix: string;
80
- referralSource?: string;
81
- surveyData?: MicrosurveyData;
82
- preferences?: OrgPreferences;
83
- hubspot: {
84
- hubspot_pipelines?: {
85
- id: string;
86
- label: string;
87
- default_stage: { id: string; label: string };
88
- }[];
89
- hubspot_hidden_fields?: string[];
90
- };
91
- partition?: boolean;
92
- tickets: {
93
- prefix?: string;
94
- emoji_ticketing: {
95
- is_enabled?: boolean;
96
- is_message_enabled?: boolean;
97
- message_template?: string;
98
- };
99
- };
100
- attribution?: Object;
101
- custom_properties?: {
102
- chats_order?: {
103
- [id: string]: number;
104
- };
105
- tickets_order?: {
106
- [id: string]: number;
107
- };
108
- };
109
- };
110
-
111
- type AccessScopes = {
112
- feature_flags: Record<string, boolean>;
113
- integrations: boolean;
114
- exports: boolean;
115
- };
116
-
117
- export type OrgType = OverrideProperties<
118
- Merge<
119
- Tables<'tbl_org'>,
120
- {
121
- user: Tables<'tbl_org_members'>;
122
- members: Tables<'tbl_org_members'>[];
123
- phones: Tables<'tbl_org_phones'>[];
124
- labels: Tables<'tbl_org_labels'>[];
125
- quick_replies: Tables<'tbl_quick_replies'>[];
126
- custom_properties: Tables<'tbl_custom_properties'>[];
127
- subscription_status: 'active' | 'inactive' | 'unpaid';
128
- is_enterprise: boolean;
129
- is_free_trial: boolean;
130
- is_hubspot_connected: boolean;
131
- is_freshdesk_connected: boolean;
132
- is_zohodesk_connected: boolean;
133
- access_scopes: AccessScopes;
134
- rules: Rule[];
135
- }
136
- >,
137
- {
138
- org_plan: OrgPlan<AllPlans | Enterprise>;
139
- stripe_customer_details: _Stripe.Customer | null;
140
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
141
- stripe_customer_id: _Stripe.Customer['id'] | null;
142
- org_metadata: OrgMetadata;
143
- }
144
- >;
145
-
146
- export type ChatMemberType = Merge<
147
- Tables<'tbl_chat_participants'>,
148
- Tables<'tbl_contacts'>
149
- >;
150
-
151
- export type ChatType = Merge<
152
- Tables<'view_chats'>,
153
- {
154
- chat_id: string;
155
- latest_message: MessageType | null;
156
- latest_message_timestamp: number | null;
157
- members: { [key: string]: ChatMemberType } | null;
158
- chat_type: 'user' | 'group' | 'business' | 'unknown';
159
- chat_access: { [key: string]: boolean };
160
- label_ids: { [key: string]: boolean };
161
- chat_org_phones?: string[];
162
- message_unread_count: number | null;
163
- hubspot_metadata: {
164
- id: string;
165
- type: string;
166
- hubId: string;
167
- object_data: HubspotObjectDataType;
168
- } | null;
169
- info_admins_only: boolean;
170
- messages_admins_only: boolean;
171
- unread_count?: { [key: string]: number };
172
- active_phone: string | null;
173
- flag_count_map?: { [key: string]: number };
174
- is_archived?: boolean;
175
- is_pinned?: boolean;
176
- closed_at?: number | null;
177
- common_chats?: string[];
178
- }
179
- >;
180
-
181
- /* -------------------------------------------------------------------------- */
182
- /* MESSAGE */
183
- /* -------------------------------------------------------------------------- */
184
-
185
- export type MediaType = {
186
- path?: string;
187
- mimetype?: string;
188
- filename?: string;
189
- dimensions?: { width: number; height: number; ar: number };
190
- size?: number;
191
- thumbnail?: string;
192
- filedata?: string;
193
- compress?: boolean;
194
- };
195
-
196
- export type MessageType = Merge<
197
- OverrideProperties<
198
- Tables<'tbl_chat_messages'>,
199
- {
200
- message_id: string;
201
- org_id: string;
202
- org_phone: string;
203
- chat_id: string;
204
- message_type: (typeof SUPPORTED_TYPES)[number];
205
- media: MediaType | null;
206
- flag_metadata: MessageFlagType | null;
207
- poll_info?: PollSendType | null;
208
- poll_results?: PollResultType | null;
209
- delivery_info?: DeliveryInfoType | null;
210
- }
211
- >,
212
- {
213
- reactions?: ReactionType[];
214
- message_payload?: SingleMessagePayload;
215
- highlight?: number;
216
- }
217
- >;
218
-
219
- export type MessageFlagType = {
220
- status: boolean;
221
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
222
- response_id?: string;
223
- response_timestamp?: string;
224
- response_email?: string;
225
- };
226
-
227
- /* -------------------------------------------------------------------------- */
228
-
229
- export type TicketType = OverrideProperties<
230
- Tables<'tbl_chat_tickets'>,
231
- {
232
- label_ids: { [key: string]: boolean };
233
- hubspot_metadata: {
234
- id?: string;
235
- type?: string;
236
- hubId?: string;
237
- pipeline: {
238
- id: string;
239
- label: string;
240
- };
241
- object_data?: HubspotObjectDataType;
242
- } | null;
243
- freshdesk_metadata: Record<string, string>;
244
- close_ticket_metadata?:
245
- | {
246
- closed_by: string;
247
- closed_at: string;
248
- closed_message?: string | null;
249
- send_reply_message_id?: string | null;
250
- }
251
- | any;
252
- }
253
- >;
254
-
255
- export type ContactType = Merge<
256
- Tables<'tbl_contacts'>,
257
- {
258
- chats: ChatType[] | null;
259
- chat_ids?: string[];
260
- }
261
- >;
262
- export type ReactionType = Tables<'tbl_chat_reactions'>;
263
-
264
- export type NotificationType = Tables<'tbl_chat_notifications'>;
265
-
266
- export type ChatAccessType = Merge<
267
- TablesUpdate<'tbl_org_members'>,
268
- {
269
- has_access?: boolean;
270
- email: string | null;
271
- }
272
- >;
273
-
274
- export type PhoneQueueStatusType = {
275
- active: number;
276
- failed: number;
277
- completed: number;
278
- is_running: boolean;
279
- pending: number;
280
- };
281
-
282
- export type PhoneType = OverrideProperties<
283
- Tables<'tbl_org_phones'>,
284
- {
285
- queue_status: {
286
- [key: string]: PhoneQueueStatusType;
287
- };
288
- }
289
- >;
290
-
291
- /* -------------------------------- CONSTANTS ------------------------------- */
292
-
293
- export const labelColors = [
294
- '#9333EA',
295
- '#0D9488',
296
- '#DB2777',
297
- '#2563EB',
298
- '#F97316',
299
- ];
300
-
301
- export const enumChatColors = [
302
- '#B4876E',
303
- '#A5B337',
304
- '#06CF9C',
305
- '#25D366',
306
- '#02A698',
307
- '#7D9EF1',
308
- '#007BFC',
309
- '#5E47DE',
310
- '#7F66FF',
311
- '#9333EA',
312
- '#FA6533',
313
- '#C4532D',
314
- '#DC2626',
315
- '#FF2E74',
316
- '#DB2777',
317
- ] as const;
318
-
319
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
320
-
321
- export const SUPPORTED_TYPES = [
322
- 'chat',
323
- 'sticker',
324
- 'image',
325
- 'video',
326
- 'document',
327
- 'vcard',
328
- 'multi_vcard',
329
- 'audio',
330
- 'ptt',
331
- 'poll_creation',
332
- 'location',
333
- 'ciphertext',
334
- ] as const;
335
-
336
- export type SendMessageContent = {
337
- message_type?: (typeof SUPPORTED_TYPES)[number];
338
- body?: string;
339
- media?: MediaType;
340
- contact_ids?: string[];
341
- location?: {
342
- latitude: string;
343
- longitude: string;
344
- options?: { name?: string; address?: string; url?: string };
345
- };
346
- poll?: PollSendType;
347
- quoted_message_id?: string;
348
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
349
- broadcast_id?: string;
350
- performed_by?: string;
351
- };
352
-
353
- export type QuickReplyContent = Omit<
354
- SendMessageContent,
355
- 'broadcast_id' | 'variables'
356
- >;
357
-
358
- export type BroadcastVariableType = {
359
- chat_id: string;
360
- values: { [key: string]: string };
361
- };
362
-
363
- export type BroadcastMessagePayload = SendMessageContent & {
364
- chat_ids: string[];
365
- broadcast_id?: string;
366
- variables?: BroadcastVariableType[];
367
- delay?: number;
368
- };
369
-
370
- export type SingleMessagePayload = SendMessageContent & {
371
- chat_id: string;
372
- job_id?: string;
373
- priority?: number;
374
- };
375
-
376
- export type MessageAttachmentFileTypes =
377
- | 'image'
378
- | 'audio'
379
- | 'document'
380
- | 'video';
381
-
382
- export type AttachmentFileType = {
383
- result: string;
384
- file: File | null;
385
- type: MessageAttachmentFileTypes;
386
- localFileURL?: string;
387
- };
388
-
389
- export type AttachmentLinkType = {
390
- link: {
391
- url: string;
392
- type: MessageAttachmentFileTypes;
393
- name: string;
394
- mimetype?: string;
395
- };
396
- };
397
-
398
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
399
-
400
- /* -------------------------------- BROADCAST ------------------------------- */
401
-
402
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
403
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
404
- } & {
405
- chats: ChatType[];
406
- };
407
-
408
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
409
-
410
- export type ChatLogType = {
411
- log: Tables<'view_chat_logs'>;
412
- operations: Tables<'tbl_chat_logs'>[];
413
- };
414
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
415
-
416
- export type ChatParticipantOperationPayload = {
417
- participant_ids: string[];
418
- chat_ids: string[];
419
- performed_by: string;
420
- };
421
-
422
- export type ChatOperationReturn = {
423
- [participant_id: string]: {
424
- is_success: boolean;
425
- message?: string;
426
- code?: number;
427
- isInviteV4Sent?: boolean;
428
- };
429
- };
430
-
431
- /* ----------------------- BILLING - STRIPE ----------------------- */
432
-
433
- export type StripeSubscription = _Stripe.Subscription;
434
- export type StripeCustomer = _Stripe.Customer;
435
- export type StripeCoupon = _Stripe.Coupon;
436
- export type StripePrice = _Stripe.Price;
437
- export type Stripe = _Stripe;
438
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
439
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
440
-
441
- /* -------------------------------- REALTIME -------------------------------- */
442
-
443
- export type PhoneStateType = {
444
- loading: boolean;
445
- state: string;
446
- sync: number;
447
- percent: number | null;
448
- message?: string;
449
- error?: string;
450
- };
451
-
452
- /* ------------------------------- INTEGRATIONS ----------------------------- */
453
-
454
- export type ChatInfoType = Merge<
455
- ChatType,
456
- {
457
- members: {
458
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
459
- } | null;
460
- chat_labels: string | null;
461
- custom_properties: { [key: string]: string } | null;
462
- }
463
- >;
464
-
465
- export type TicketInfoType = {
466
- chat: ChatInfoType;
467
- message: {
468
- body: string;
469
- chat_id: string;
470
- org_phone: string;
471
- timestamp: string;
472
- media_path: string;
473
- message_id: string;
474
- sender_name: string;
475
- performed_by: string;
476
- sender_phone: string;
477
- };
478
- ticket: {
479
- org_id: string;
480
- status: string;
481
- subject: string;
482
- assignee: string;
483
- due_date: string;
484
- priority: 0 | 1 | 2 | 3 | 4;
485
- raised_by: string;
486
- ticket_id: string;
487
- created_at: string;
488
- assigned_by: string;
489
- ticket_labels: string;
490
- quoted_message_id: string;
491
- ticket_custom_properties: { [key: string]: string } | null;
492
- };
493
- attached_messages: {
494
- body: string;
495
- chat_id: string;
496
- org_phone: string;
497
- timestamp: string;
498
- media_path: string;
499
- message_id: string;
500
- sender_name: string;
501
- performed_by: string;
502
- sender_phone: string;
503
- }[];
504
- };
505
-
506
- export type IntegrationLogObjectType =
507
- | 'chat'
508
- | 'message'
509
- | 'reaction'
510
- | 'ticket';
511
-
512
- export enum IntegrationLogType {
513
- NEW_CHAT = 'chat.created',
514
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
515
- NEW_MESSAGE = 'message.created',
516
- MESSAGE_UPDATED = 'message.updated',
517
- MESSAGE_DELETED = 'message.deleted',
518
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
519
- REACTION_CREATED = 'reaction.created',
520
- REACTION_UPDATED = 'reaction.updated',
521
- NEW_TICKET = 'ticket.created',
522
- TICKET_UPDATED = 'ticket.updated',
523
- TICKET_DELETED = 'ticket.deleted',
524
- MESSAGE_FLAGGED = 'message.flagged',
525
- MESSAGE_UNFLAGGED = 'message.unflagged',
526
- }
527
-
528
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
529
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
530
- ? TicketInfoType
531
- : T extends IntegrationLogType.NEW_CHAT
532
- ? Tables<'tbl_chats'>
533
- : T extends
534
- | IntegrationLogType.NEW_MESSAGE
535
- | IntegrationLogType.MESSAGE_UPDATED
536
- | IntegrationLogType.MESSAGE_DELETED
537
- | IntegrationLogType.MESSAGE_ACK_UPDATED
538
- | IntegrationLogType.MESSAGE_FLAGGED
539
- | IntegrationLogType.MESSAGE_UNFLAGGED
540
- ? Tables<'tbl_chat_messages'>
541
- : T extends
542
- | IntegrationLogType.REACTION_CREATED
543
- | IntegrationLogType.REACTION_UPDATED
544
- ? Tables<'tbl_chat_reactions'>
545
- : {
546
- [key: string]: unknown;
547
- };
548
-
549
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
550
- OverrideProperties<
551
- Tables<'tbl_integration_logs'>,
552
- {
553
- integration_name: T;
554
- metadata: {
555
- event: IntegrationLogMetadataType<T> & {
556
- event_type: string;
557
- org_id: string;
558
- previous_attributes: {
559
- [key: string]: unknown;
560
- };
561
- };
562
- hook_id: string;
563
- name: string;
564
- };
565
- }
566
- >;
567
-
568
- export type APIAuthDetails = {
569
- org_details: Tables<'view_org'> | null;
570
- phone_details: Tables<'tbl_org_phones'> | null;
571
- token_details: Tables<'tbl_integration_tokens'> | null;
572
- };
573
-
574
- export type WebhookDataType = OverrideProperties<
575
- Tables<'tbl_integration_hooks'>,
576
- {
577
- integration_name: string[];
578
- }
579
- >;
580
-
581
- export type HubspotObjectDataType = {
582
- createdAt: string;
583
- archived: boolean;
584
- id: string;
585
- type: 'contacts' | 'tickets' | 'companies';
586
- properties: Record<
587
- string,
588
- {
589
- groupLabel: string;
590
- groupName: string;
591
- propertyKeyName: string;
592
- propertyKey: string;
593
- propertyInternalValue: string;
594
- propertyValue: string;
595
- propertyType: string;
596
- propertyFieldType: string;
597
- }[]
598
- >;
599
- };
600
-
601
- /* ---------------------------- USER PREFERENCES ---------------------------- */
602
-
603
- export type UserPreferences = {
604
- theme: 'light' | 'dark';
605
- language: 'en' | 'es';
606
- left_sidebar_open: boolean;
607
- right_sidepanel_open: boolean;
608
- sync_wa_unread_count: boolean;
609
- pinned_chats: string[];
610
- archived_chats: string[];
611
- closed_chats: Record<string, number>;
612
- periskope_chat_limit: number;
613
- };
614
-
615
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
616
-
617
- export type PollSendType = {
618
- pollName: string;
619
- pollOptions: string[];
620
- options?: {
621
- allowMultipleAnswers?: boolean;
622
- messageSecret?: number[] | null;
623
- pollId?: string;
624
- };
625
- };
626
-
627
- export type PollResultType = {
628
- [name: string]: Record<string, string>;
629
- };
630
-
631
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
632
-
633
- export type CreateGroupOptions = {
634
- messagesAdminsOnly?: boolean;
635
- infoAdminsOnly?: boolean;
636
- memberAddMode?: boolean;
637
- image?: string;
638
- name?: string;
639
- description?: string;
640
- };
641
-
642
- /* ------------------------------ DELIVERY INFO ----------------------------- */
643
-
644
- export type DeliveryInfoType = {
645
- delivered: Record<string, number | undefined>;
646
- read: Record<string, number | undefined>;
647
- pending: string[];
648
- read_count: number;
649
- delivered_count: number;
650
- };
651
-
652
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
653
-
654
- export type OrgCreditsType = {
655
- org_id: string;
656
- recurring_allowance: number; // recurring credits replenished every month
657
- recurring_balance: number; // recurring credits remaining in current month
658
- topup_balance: number; // topup credits remaining
659
- total_credits_used: number; // total credits used in current month
660
- next_renewal_date: string;
661
- };
662
-
663
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
664
-
665
- export type ChatRuleInfoType = Merge<
666
- Pick<
667
- Tables<'view_chats'>,
668
- | 'assigned_to'
669
- | 'chat_id'
670
- | 'chat_name'
671
- | 'chat_type'
672
- | 'created_at'
673
- | 'group_description'
674
- | 'info_admins_only'
675
- | 'org_id'
676
- | 'org_phone'
677
- | 'chat_org_phones'
678
- | 'messages_admins_only'
679
- | 'custom_properties'
680
- >,
681
- {
682
- has_flagged_messages: boolean;
683
- labels: string[];
684
- members: string[];
685
- custom_properties: { [key: string]: string } | null;
686
- }
687
- >;
688
-
689
- export type SenderRuleInfoType = Merge<
690
- Omit<
691
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
692
- | 'verified_name'
693
- | 'verified_level'
694
- | 'updated_at'
695
- | 'short_name'
696
- | 'pushname'
697
- | 'periskope_name'
698
- | 'org_phone'
699
- | 'number'
700
- | 'name'
701
- | 'label_ids'
702
- | 'is_wa_contact'
703
- | 'is_user'
704
- | 'is_my_contact'
705
- | 'is_me'
706
- | 'is_imported'
707
- | 'is_group'
708
- | 'is_blocked'
709
- | 'contact_color'
710
- | 'business_profile'
711
- | 'id'
712
- | 'contact_image'
713
- | 'contact_type'
714
- | 'chat_id'
715
- | 'is_business'
716
- | 'is_enterprise'
717
- | 'is_super_admin'
718
- >,
719
- {
720
- is_internal: boolean;
721
- labels: string[] | null;
722
- }
723
- >;
724
-
725
- export type MessageRuleInfoType = {
726
- chat: ChatRuleInfoType;
727
- sender: SenderRuleInfoType;
728
- message: OverrideProperties<
729
- Omit<
730
- Tables<'tbl_chat_messages'>,
731
- | 'vcards'
732
- | 'updated_at'
733
- | 'unique_id'
734
- | 'token'
735
- | 'to'
736
- | 'sent_message_id'
737
- | 'raw_data'
738
- | 'delivery_info'
739
- | 'poll_results'
740
- | 'poll_info'
741
- | 'order_id'
742
- | 'mentioned_ids'
743
- | 'media_key'
744
- | 'location'
745
- | 'links'
746
- | 'is_status'
747
- | 'is_starred'
748
- | 'is_gif'
749
- | 'is_forwarded'
750
- | 'is_ephemeral'
751
- | 'is_deleted'
752
- | 'fts'
753
- | 'quoted_message_id'
754
- | 'invite_v4'
755
- | 'id'
756
- | 'has_reaction'
757
- | 'has_media'
758
- | 'duration'
759
- | 'broadcast'
760
- | 'broadcast_id'
761
- | 'device_type'
762
- | 'forwarding_score'
763
- | 'from'
764
- | 'from_me'
765
- | 'message_ticket_id'
766
- | 'prev_body'
767
- | 'flag_response_time'
768
- | 'flag_metadata'
769
- | 'ack'
770
- >,
771
- {
772
- media: MediaType | null;
773
- }
774
- >;
775
- };
776
-
777
- export type ReactionRuleInfoType = {
778
- chat: ChatRuleInfoType;
779
- sender: SenderRuleInfoType;
780
- message: MessageRuleInfoType['message'];
781
- reaction: Pick<
782
- Tables<'tbl_chat_reactions'>,
783
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
784
- >;
785
- };
786
-
787
- export type TicketRuleInfoType = {
788
- chat: ChatRuleInfoType;
789
- sender: SenderRuleInfoType;
790
- ticket: Merge<
791
- Pick<
792
- Tables<'tbl_chat_tickets'>,
793
- | 'org_id'
794
- | 'status'
795
- | 'chat_id'
796
- | 'subject'
797
- | 'assignee'
798
- | 'due_date'
799
- | 'priority'
800
- | 'raised_by'
801
- | 'ticket_id'
802
- | 'created_at'
803
- | 'is_deleted'
804
- >,
805
- {
806
- labels: string[] | null;
807
- custom_properties: { [key: string]: string } | null;
808
- }
809
- >;
810
- message: MessageRuleInfoType['message'];
811
- };
812
- export type FeatureFlagReturnType = Record<string, boolean>;
813
-
814
- export type RuleLogsType = OverrideProperties<
815
- Tables<'tbl_rules_logs'>,
816
- {
817
- actions_progress: {
818
- action_id: string;
819
- action_type: Rule['actions'][number]['type'];
820
- action_delay: Rule['actions'][number]['delay'];
821
- ran_at: string | null;
822
- action_status: 'success' | 'failed' | 'pending';
823
- action_response: {
824
- success: boolean;
825
- data: Record<string, unknown> | null;
826
- error: {
827
- message: string;
828
- name: string;
829
- stack?: string;
830
- _error?: Error | Record<string, unknown>;
831
- } | null;
832
- };
833
- }[];
834
- metadata: {
835
- conditions: Rule['conditions'];
836
- actions: Rule['actions'];
837
- data: Record<string, unknown>;
838
- };
839
- conditions_progress: {
840
- is_valid: boolean;
841
- validation_progress: Record<
842
- string,
843
- {
844
- res: boolean;
845
- filter: Filter;
846
- value: unknown;
847
- }
848
- >;
849
- checked_at: string | null;
850
- };
851
- }
852
- >;
1
+ import type { default as _Stripe } from 'stripe';
2
+ import { Merge, OverrideProperties } from 'type-fest';
3
+ import { Filter, Rule } from './rules.types';
4
+ import { Tables, TablesUpdate } from './supabase.types';
5
+
6
+ /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
7
+
8
+ /* ------------------------------ PERISKOPE TYPES ------------------------------ */
9
+
10
+ export enum AllPlans {
11
+ FREE_TRIAL = 'free-trial',
12
+ // MONTHLY_STARTER = 'monthly-starter',
13
+ // YEARLY_STARTER = 'yearly-starter',
14
+ // MONTHLY_PRO = 'monthly-pro',
15
+ // YEARLY_PRO = 'yearly-pro',
16
+ ENTERPRISE = 'enterprise',
17
+ MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
18
+ YEARLY_STARTER_SINGLE = 'yearly-starter-single',
19
+ MONTHLY_PRO_SINGLE = 'monthly-pro-single',
20
+ YEARLY_PRO_SINGLE = 'yearly-pro-single',
21
+ }
22
+
23
+ export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
24
+
25
+ export type Enterprise = `${string}-enterprise`;
26
+
27
+ export type OrgPlanEnterprise = {
28
+ subscription_id: string;
29
+ plan_id: Enterprise;
30
+ interval: number;
31
+ frequency: Frequency;
32
+ user_limit: number;
33
+ phone_limit: number;
34
+ current_period_start: number;
35
+ current_period_end: number | null;
36
+ };
37
+
38
+ export type OrgPlanNonEnterprise = {
39
+ subscription_id: string;
40
+ plan_id: AllPlans;
41
+ interval: number;
42
+ frequency: Frequency;
43
+ user_limit: number;
44
+ phone_limit: number;
45
+ current_period_end: number;
46
+ current_period_start: number;
47
+ };
48
+
49
+ export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
50
+ ? OrgPlanEnterprise
51
+ : T extends AllPlans
52
+ ? OrgPlanNonEnterprise
53
+ : never;
54
+
55
+ export type MicrosurveyData = {
56
+ key: string;
57
+ text: string;
58
+ checked: boolean;
59
+ }[];
60
+
61
+ export type OrgPreferences = {
62
+ disable_ai_flagging?: boolean;
63
+ disable_allow_exports?: boolean;
64
+ sync_phone_contacts?: boolean;
65
+ mask_phone_numbers?: boolean;
66
+ show_sender_names?: boolean;
67
+ closed_chats?: Record<string, number>;
68
+ auto_read_muted_chats?: boolean;
69
+ };
70
+
71
+ type OrgPreferenceKey = keyof OrgPreferences;
72
+
73
+ export type OrgPreferencesValue = {
74
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
75
+ }[OrgPreferenceKey];
76
+
77
+ export type OrgMetadata = {
78
+ phone_number: string;
79
+ ticket_prefix: string;
80
+ referralSource?: string;
81
+ surveyData?: MicrosurveyData;
82
+ preferences?: OrgPreferences;
83
+ hubspot: {
84
+ hubspot_pipelines?: {
85
+ id: string;
86
+ label: string;
87
+ default_stage: { id: string; label: string };
88
+ }[];
89
+ hubspot_hidden_fields?: string[];
90
+ };
91
+ partition?: boolean;
92
+ tickets: {
93
+ prefix?: string;
94
+ emoji_ticketing: {
95
+ is_enabled?: boolean;
96
+ is_message_enabled?: boolean;
97
+ message_template?: string;
98
+ };
99
+ };
100
+ attribution?: Object;
101
+ custom_properties?: {
102
+ chats_order?: {
103
+ [id: string]: number;
104
+ };
105
+ tickets_order?: {
106
+ [id: string]: number;
107
+ };
108
+ };
109
+ rules?: {
110
+ limit?: number;
111
+ }
112
+ };
113
+
114
+ type AccessScopes = {
115
+ feature_flags: Record<string, boolean>;
116
+ integrations: boolean;
117
+ rules: boolean;
118
+ exports: boolean;
119
+ };
120
+
121
+ export type OrgType = OverrideProperties<
122
+ Merge<
123
+ Tables<'tbl_org'>,
124
+ {
125
+ user: Tables<'tbl_org_members'>;
126
+ members: Tables<'tbl_org_members'>[];
127
+ phones: Tables<'tbl_org_phones'>[];
128
+ labels: Tables<'tbl_org_labels'>[];
129
+ quick_replies: Tables<'tbl_quick_replies'>[];
130
+ custom_properties: Tables<'tbl_custom_properties'>[];
131
+ subscription_status: 'active' | 'inactive' | 'unpaid';
132
+ is_enterprise: boolean;
133
+ is_free_trial: boolean;
134
+ is_hubspot_connected: boolean;
135
+ is_freshdesk_connected: boolean;
136
+ is_zohodesk_connected: boolean;
137
+ access_scopes: AccessScopes;
138
+ rules: Rule[];
139
+ }
140
+ >,
141
+ {
142
+ org_plan: OrgPlan<AllPlans | Enterprise>;
143
+ stripe_customer_details: _Stripe.Customer | null;
144
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
145
+ stripe_customer_id: _Stripe.Customer['id'] | null;
146
+ org_metadata: OrgMetadata;
147
+ }
148
+ >;
149
+
150
+ export type ChatMemberType = Merge<
151
+ Tables<'tbl_chat_participants'>,
152
+ Tables<'tbl_contacts'>
153
+ >;
154
+
155
+ export type ChatType = Merge<
156
+ Tables<'view_chats'>,
157
+ {
158
+ chat_id: string;
159
+ latest_message: MessageType | null;
160
+ latest_message_timestamp: number | null;
161
+ members: { [key: string]: ChatMemberType } | null;
162
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
163
+ chat_access: { [key: string]: boolean };
164
+ label_ids: { [key: string]: boolean };
165
+ chat_org_phones?: string[];
166
+ message_unread_count: number | null;
167
+ hubspot_metadata: {
168
+ id: string;
169
+ type: string;
170
+ hubId: string;
171
+ object_data: HubspotObjectDataType;
172
+ } | null;
173
+ info_admins_only: boolean;
174
+ messages_admins_only: boolean;
175
+ unread_count?: { [key: string]: number };
176
+ active_phone: string | null;
177
+ flag_count_map?: { [key: string]: number };
178
+ is_archived?: boolean;
179
+ is_pinned?: boolean;
180
+ closed_at?: number | null;
181
+ common_chats?: string[];
182
+ }
183
+ >;
184
+
185
+ /* -------------------------------------------------------------------------- */
186
+ /* MESSAGE */
187
+ /* -------------------------------------------------------------------------- */
188
+
189
+ export type MediaType = {
190
+ path?: string;
191
+ mimetype?: string;
192
+ filename?: string;
193
+ dimensions?: { width: number; height: number; ar: number };
194
+ size?: number;
195
+ thumbnail?: string;
196
+ filedata?: string;
197
+ compress?: boolean;
198
+ };
199
+
200
+ export type MessageType = Merge<
201
+ OverrideProperties<
202
+ Tables<'tbl_chat_messages'>,
203
+ {
204
+ message_id: string;
205
+ org_id: string;
206
+ org_phone: string;
207
+ chat_id: string;
208
+ message_type: (typeof SUPPORTED_TYPES)[number];
209
+ media: MediaType | null;
210
+ flag_metadata: MessageFlagType | null;
211
+ poll_info?: PollSendType | null;
212
+ poll_results?: PollResultType | null;
213
+ delivery_info?: DeliveryInfoType | null;
214
+ }
215
+ >,
216
+ {
217
+ reactions?: ReactionType[];
218
+ message_payload?: SingleMessagePayload;
219
+ highlight?: number;
220
+ }
221
+ >;
222
+
223
+ export type MessageFlagType = {
224
+ status: boolean;
225
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
226
+ response_id?: string;
227
+ response_timestamp?: string;
228
+ response_email?: string;
229
+ };
230
+
231
+ /* -------------------------------------------------------------------------- */
232
+
233
+ export type TicketType = OverrideProperties<
234
+ Tables<'tbl_chat_tickets'>,
235
+ {
236
+ label_ids: { [key: string]: boolean };
237
+ hubspot_metadata: {
238
+ id?: string;
239
+ type?: string;
240
+ hubId?: string;
241
+ pipeline: {
242
+ id: string;
243
+ label: string;
244
+ };
245
+ object_data?: HubspotObjectDataType;
246
+ } | null;
247
+ freshdesk_metadata: Record<string, string>;
248
+ close_ticket_metadata?:
249
+ | {
250
+ closed_by: string;
251
+ closed_at: string;
252
+ closed_message?: string | null;
253
+ send_reply_message_id?: string | null;
254
+ }
255
+ | any;
256
+ }
257
+ >;
258
+
259
+ export type ContactType = Merge<
260
+ Tables<'tbl_contacts'>,
261
+ {
262
+ chats: ChatType[] | null;
263
+ chat_ids?: string[];
264
+ }
265
+ >;
266
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
267
+
268
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
269
+
270
+ export type ChatAccessType = Merge<
271
+ TablesUpdate<'tbl_org_members'>,
272
+ {
273
+ has_access?: boolean;
274
+ email: string | null;
275
+ }
276
+ >;
277
+
278
+ export type PhoneQueueStatusType = {
279
+ active: number;
280
+ failed: number;
281
+ completed: number;
282
+ is_running: boolean;
283
+ pending: number;
284
+ };
285
+
286
+ export type PhoneType = OverrideProperties<
287
+ Tables<'tbl_org_phones'>,
288
+ {
289
+ queue_status: {
290
+ [key: string]: PhoneQueueStatusType;
291
+ };
292
+ }
293
+ >;
294
+
295
+ /* -------------------------------- CONSTANTS ------------------------------- */
296
+
297
+ export const labelColors = [
298
+ '#9333EA',
299
+ '#0D9488',
300
+ '#DB2777',
301
+ '#2563EB',
302
+ '#F97316',
303
+ ];
304
+
305
+ export const enumChatColors = [
306
+ '#B4876E',
307
+ '#A5B337',
308
+ '#06CF9C',
309
+ '#25D366',
310
+ '#02A698',
311
+ '#7D9EF1',
312
+ '#007BFC',
313
+ '#5E47DE',
314
+ '#7F66FF',
315
+ '#9333EA',
316
+ '#FA6533',
317
+ '#C4532D',
318
+ '#DC2626',
319
+ '#FF2E74',
320
+ '#DB2777',
321
+ ] as const;
322
+
323
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
324
+
325
+ export const SUPPORTED_TYPES = [
326
+ 'chat',
327
+ 'sticker',
328
+ 'image',
329
+ 'video',
330
+ 'document',
331
+ 'vcard',
332
+ 'multi_vcard',
333
+ 'audio',
334
+ 'ptt',
335
+ 'poll_creation',
336
+ 'location',
337
+ 'ciphertext',
338
+ ] as const;
339
+
340
+ export type SendMessageContent = {
341
+ message_type?: (typeof SUPPORTED_TYPES)[number];
342
+ body?: string;
343
+ media?: MediaType;
344
+ contact_ids?: string[];
345
+ location?: {
346
+ latitude: string;
347
+ longitude: string;
348
+ options?: { name?: string; address?: string; url?: string };
349
+ };
350
+ poll?: PollSendType;
351
+ quoted_message_id?: string;
352
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
353
+ broadcast_id?: string;
354
+ performed_by?: string;
355
+ };
356
+
357
+ export type QuickReplyContent = Omit<
358
+ SendMessageContent,
359
+ 'broadcast_id' | 'variables'
360
+ >;
361
+
362
+ export type BroadcastVariableType = {
363
+ chat_id: string;
364
+ values: { [key: string]: string };
365
+ };
366
+
367
+ export type BroadcastMessagePayload = SendMessageContent & {
368
+ chat_ids: string[];
369
+ broadcast_id?: string;
370
+ variables?: BroadcastVariableType[];
371
+ delay?: number;
372
+ };
373
+
374
+ export type SingleMessagePayload = SendMessageContent & {
375
+ chat_id: string;
376
+ job_id?: string;
377
+ priority?: number;
378
+ };
379
+
380
+ export type MessageAttachmentFileTypes =
381
+ | 'image'
382
+ | 'audio'
383
+ | 'document'
384
+ | 'video';
385
+
386
+ export type AttachmentFileType = {
387
+ result: string;
388
+ file: File | null;
389
+ type: MessageAttachmentFileTypes;
390
+ localFileURL?: string;
391
+ };
392
+
393
+ export type AttachmentLinkType = {
394
+ link: {
395
+ url: string;
396
+ type: MessageAttachmentFileTypes;
397
+ name: string;
398
+ mimetype?: string;
399
+ };
400
+ };
401
+
402
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
403
+
404
+ /* -------------------------------- BROADCAST ------------------------------- */
405
+
406
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
407
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
408
+ } & {
409
+ chats: ChatType[];
410
+ };
411
+
412
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
413
+
414
+ export type ChatLogType = {
415
+ log: Tables<'view_chat_logs'>;
416
+ operations: Tables<'tbl_chat_logs'>[];
417
+ };
418
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
419
+
420
+ export type ChatParticipantOperationPayload = {
421
+ participant_ids: string[];
422
+ chat_ids: string[];
423
+ performed_by: string;
424
+ };
425
+
426
+ export type ChatOperationReturn = {
427
+ [participant_id: string]: {
428
+ is_success: boolean;
429
+ message?: string;
430
+ code?: number;
431
+ isInviteV4Sent?: boolean;
432
+ };
433
+ };
434
+
435
+ /* ----------------------- BILLING - STRIPE ----------------------- */
436
+
437
+ export type StripeSubscription = _Stripe.Subscription;
438
+ export type StripeCustomer = _Stripe.Customer;
439
+ export type StripeCoupon = _Stripe.Coupon;
440
+ export type StripePrice = _Stripe.Price;
441
+ export type Stripe = _Stripe;
442
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
443
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
444
+
445
+ /* -------------------------------- REALTIME -------------------------------- */
446
+
447
+ export type PhoneStateType = {
448
+ loading: boolean;
449
+ state: string;
450
+ sync: number;
451
+ percent: number | null;
452
+ message?: string;
453
+ error?: string;
454
+ };
455
+
456
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
457
+
458
+ export type ChatInfoType = Merge<
459
+ ChatType,
460
+ {
461
+ members: {
462
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
463
+ } | null;
464
+ chat_labels: string | null;
465
+ custom_properties: { [key: string]: string } | null;
466
+ }
467
+ >;
468
+
469
+ export type TicketInfoType = {
470
+ chat: ChatInfoType;
471
+ message: {
472
+ body: string;
473
+ chat_id: string;
474
+ org_phone: string;
475
+ timestamp: string;
476
+ media_path: string;
477
+ message_id: string;
478
+ sender_name: string;
479
+ performed_by: string;
480
+ sender_phone: string;
481
+ };
482
+ ticket: {
483
+ org_id: string;
484
+ status: string;
485
+ subject: string;
486
+ assignee: string;
487
+ due_date: string;
488
+ priority: 0 | 1 | 2 | 3 | 4;
489
+ raised_by: string;
490
+ ticket_id: string;
491
+ created_at: string;
492
+ assigned_by: string;
493
+ ticket_labels: string;
494
+ quoted_message_id: string;
495
+ ticket_custom_properties: { [key: string]: string } | null;
496
+ };
497
+ attached_messages: {
498
+ body: string;
499
+ chat_id: string;
500
+ org_phone: string;
501
+ timestamp: string;
502
+ media_path: string;
503
+ message_id: string;
504
+ sender_name: string;
505
+ performed_by: string;
506
+ sender_phone: string;
507
+ }[];
508
+ };
509
+
510
+ export type IntegrationLogObjectType =
511
+ | 'chat'
512
+ | 'message'
513
+ | 'reaction'
514
+ | 'ticket';
515
+
516
+ export enum IntegrationLogType {
517
+ NEW_CHAT = 'chat.created',
518
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
519
+ NEW_MESSAGE = 'message.created',
520
+ MESSAGE_UPDATED = 'message.updated',
521
+ MESSAGE_DELETED = 'message.deleted',
522
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
523
+ REACTION_CREATED = 'reaction.created',
524
+ REACTION_UPDATED = 'reaction.updated',
525
+ NEW_TICKET = 'ticket.created',
526
+ TICKET_UPDATED = 'ticket.updated',
527
+ TICKET_DELETED = 'ticket.deleted',
528
+ MESSAGE_FLAGGED = 'message.flagged',
529
+ MESSAGE_UNFLAGGED = 'message.unflagged',
530
+ }
531
+
532
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
533
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
534
+ ? TicketInfoType
535
+ : T extends IntegrationLogType.NEW_CHAT
536
+ ? Tables<'tbl_chats'>
537
+ : T extends
538
+ | IntegrationLogType.NEW_MESSAGE
539
+ | IntegrationLogType.MESSAGE_UPDATED
540
+ | IntegrationLogType.MESSAGE_DELETED
541
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
542
+ | IntegrationLogType.MESSAGE_FLAGGED
543
+ | IntegrationLogType.MESSAGE_UNFLAGGED
544
+ ? Tables<'tbl_chat_messages'>
545
+ : T extends
546
+ | IntegrationLogType.REACTION_CREATED
547
+ | IntegrationLogType.REACTION_UPDATED
548
+ ? Tables<'tbl_chat_reactions'>
549
+ : {
550
+ [key: string]: unknown;
551
+ };
552
+
553
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
554
+ OverrideProperties<
555
+ Tables<'tbl_integration_logs'>,
556
+ {
557
+ integration_name: T;
558
+ metadata: {
559
+ event: IntegrationLogMetadataType<T> & {
560
+ event_type: string;
561
+ org_id: string;
562
+ previous_attributes: {
563
+ [key: string]: unknown;
564
+ };
565
+ };
566
+ hook_id: string;
567
+ name: string;
568
+ };
569
+ }
570
+ >;
571
+
572
+ export type APIAuthDetails = {
573
+ org_details: Tables<'view_org'> | null;
574
+ phone_details: Tables<'tbl_org_phones'> | null;
575
+ token_details: Tables<'tbl_integration_tokens'> | null;
576
+ };
577
+
578
+ export type WebhookDataType = OverrideProperties<
579
+ Tables<'tbl_integration_hooks'>,
580
+ {
581
+ integration_name: string[];
582
+ }
583
+ >;
584
+
585
+ export type HubspotObjectDataType = {
586
+ createdAt: string;
587
+ archived: boolean;
588
+ id: string;
589
+ type: 'contacts' | 'tickets' | 'companies';
590
+ properties: Record<
591
+ string,
592
+ {
593
+ groupLabel: string;
594
+ groupName: string;
595
+ propertyKeyName: string;
596
+ propertyKey: string;
597
+ propertyInternalValue: string;
598
+ propertyValue: string;
599
+ propertyType: string;
600
+ propertyFieldType: string;
601
+ }[]
602
+ >;
603
+ };
604
+
605
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
606
+
607
+ export type UserPreferences = {
608
+ theme: 'light' | 'dark';
609
+ language: 'en' | 'es';
610
+ left_sidebar_open: boolean;
611
+ right_sidepanel_open: boolean;
612
+ sync_wa_unread_count: boolean;
613
+ pinned_chats: string[];
614
+ archived_chats: string[];
615
+ closed_chats: Record<string, number>;
616
+ periskope_chat_limit: number;
617
+ };
618
+
619
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
620
+
621
+ export type PollSendType = {
622
+ pollName: string;
623
+ pollOptions: string[];
624
+ options?: {
625
+ allowMultipleAnswers?: boolean;
626
+ messageSecret?: number[] | null;
627
+ pollId?: string;
628
+ };
629
+ };
630
+
631
+ export type PollResultType = {
632
+ [name: string]: Record<string, string>;
633
+ };
634
+
635
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
636
+
637
+ export type CreateGroupOptions = {
638
+ messagesAdminsOnly?: boolean;
639
+ infoAdminsOnly?: boolean;
640
+ memberAddMode?: boolean;
641
+ image?: string;
642
+ name?: string;
643
+ description?: string;
644
+ };
645
+
646
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
647
+
648
+ export type DeliveryInfoType = {
649
+ delivered: Record<string, number | undefined>;
650
+ read: Record<string, number | undefined>;
651
+ pending: string[];
652
+ read_count: number;
653
+ delivered_count: number;
654
+ };
655
+
656
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
657
+
658
+ export type OrgCreditsType = {
659
+ org_id: string;
660
+ recurring_allowance: number; // recurring credits replenished every month
661
+ recurring_balance: number; // recurring credits remaining in current month
662
+ topup_balance: number; // topup credits remaining
663
+ total_credits_used: number; // total credits used in current month
664
+ next_renewal_date: string;
665
+ };
666
+
667
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
668
+
669
+ export type ChatRuleInfoType = Merge<
670
+ Pick<
671
+ Tables<'view_chats'>,
672
+ | 'assigned_to'
673
+ | 'chat_id'
674
+ | 'chat_name'
675
+ | 'chat_type'
676
+ | 'created_at'
677
+ | 'group_description'
678
+ | 'info_admins_only'
679
+ | 'org_id'
680
+ | 'org_phone'
681
+ | 'chat_org_phones'
682
+ | 'messages_admins_only'
683
+ | 'custom_properties'
684
+ >,
685
+ {
686
+ has_flagged_messages: boolean;
687
+ labels: string[];
688
+ members: string[];
689
+ custom_properties: { [key: string]: string } | null;
690
+ }
691
+ >;
692
+
693
+ export type SenderRuleInfoType = Merge<
694
+ Omit<
695
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
696
+ | 'verified_name'
697
+ | 'verified_level'
698
+ | 'updated_at'
699
+ | 'short_name'
700
+ | 'pushname'
701
+ | 'periskope_name'
702
+ | 'org_phone'
703
+ | 'number'
704
+ | 'name'
705
+ | 'label_ids'
706
+ | 'is_wa_contact'
707
+ | 'is_user'
708
+ | 'is_my_contact'
709
+ | 'is_me'
710
+ | 'is_imported'
711
+ | 'is_group'
712
+ | 'is_blocked'
713
+ | 'contact_color'
714
+ | 'business_profile'
715
+ | 'id'
716
+ | 'contact_image'
717
+ | 'contact_type'
718
+ | 'chat_id'
719
+ | 'is_business'
720
+ | 'is_enterprise'
721
+ | 'is_super_admin'
722
+ >,
723
+ {
724
+ is_internal: boolean;
725
+ labels: string[] | null;
726
+ }
727
+ >;
728
+
729
+ export type MessageRuleInfoType = {
730
+ chat: ChatRuleInfoType;
731
+ sender: SenderRuleInfoType;
732
+ message: OverrideProperties<
733
+ Omit<
734
+ Tables<'tbl_chat_messages'>,
735
+ | 'vcards'
736
+ | 'updated_at'
737
+ | 'unique_id'
738
+ | 'token'
739
+ | 'to'
740
+ | 'sent_message_id'
741
+ | 'raw_data'
742
+ | 'delivery_info'
743
+ | 'poll_results'
744
+ | 'poll_info'
745
+ | 'order_id'
746
+ | 'mentioned_ids'
747
+ | 'media_key'
748
+ | 'location'
749
+ | 'links'
750
+ | 'is_status'
751
+ | 'is_starred'
752
+ | 'is_gif'
753
+ | 'is_forwarded'
754
+ | 'is_ephemeral'
755
+ | 'is_deleted'
756
+ | 'fts'
757
+ | 'quoted_message_id'
758
+ | 'invite_v4'
759
+ | 'id'
760
+ | 'has_reaction'
761
+ | 'has_media'
762
+ | 'duration'
763
+ | 'broadcast'
764
+ | 'broadcast_id'
765
+ | 'device_type'
766
+ | 'forwarding_score'
767
+ | 'from'
768
+ | 'from_me'
769
+ | 'message_ticket_id'
770
+ | 'prev_body'
771
+ | 'flag_response_time'
772
+ | 'flag_metadata'
773
+ | 'ack'
774
+ >,
775
+ {
776
+ media: MediaType | null;
777
+ }
778
+ >;
779
+ };
780
+
781
+ export type ReactionRuleInfoType = {
782
+ chat: ChatRuleInfoType;
783
+ sender: SenderRuleInfoType;
784
+ message: MessageRuleInfoType['message'];
785
+ reaction: Pick<
786
+ Tables<'tbl_chat_reactions'>,
787
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
788
+ >;
789
+ };
790
+
791
+ export type TicketRuleInfoType = {
792
+ chat: ChatRuleInfoType;
793
+ sender: SenderRuleInfoType;
794
+ ticket: Merge<
795
+ Pick<
796
+ Tables<'tbl_chat_tickets'>,
797
+ | 'org_id'
798
+ | 'status'
799
+ | 'chat_id'
800
+ | 'subject'
801
+ | 'assignee'
802
+ | 'due_date'
803
+ | 'priority'
804
+ | 'raised_by'
805
+ | 'ticket_id'
806
+ | 'created_at'
807
+ | 'is_deleted'
808
+ >,
809
+ {
810
+ labels: string[] | null;
811
+ custom_properties: { [key: string]: string } | null;
812
+ }
813
+ >;
814
+ message: MessageRuleInfoType['message'];
815
+ };
816
+ export type FeatureFlagReturnType = Record<string, boolean>;
817
+
818
+ export type RuleLogsType = OverrideProperties<
819
+ Tables<'tbl_rules_logs'>,
820
+ {
821
+ actions_progress: {
822
+ action_id: string;
823
+ action_type: Rule['actions'][number]['type'];
824
+ action_delay: Rule['actions'][number]['delay'];
825
+ ran_at: string | null;
826
+ action_status: 'success' | 'failed' | 'pending';
827
+ action_response: {
828
+ success: boolean;
829
+ data: Record<string, unknown> | null;
830
+ error: {
831
+ message: string;
832
+ name: string;
833
+ stack?: string;
834
+ _error?: Error | Record<string, unknown>;
835
+ } | null;
836
+ };
837
+ }[];
838
+ metadata: {
839
+ conditions: Rule['conditions'];
840
+ actions: Rule['actions'];
841
+ data: Record<string, unknown>;
842
+ };
843
+ conditions_progress: {
844
+ is_valid: boolean;
845
+ validation_progress: Record<
846
+ string,
847
+ {
848
+ res: boolean;
849
+ filter: Filter;
850
+ value: unknown;
851
+ }
852
+ >;
853
+ checked_at: string | null;
854
+ };
855
+ }
856
+ >;