@periskope/types 0.6.174 → 0.6.175

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