@periskope/types 0.6.278 → 0.6.280

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/src/types.ts CHANGED
@@ -1,1261 +1,1262 @@
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, TablesInsert, 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
- additional_user_limit?: number;
37
- additional_phone_limit?: number;
38
- };
39
-
40
- export type OrgPlanNonEnterprise = {
41
- subscription_id: string;
42
- plan_id: AllPlans;
43
- interval: number;
44
- frequency: Frequency;
45
- user_limit: number;
46
- phone_limit: number;
47
- current_period_end: number;
48
- current_period_start: number;
49
- additional_user_limit?: number;
50
- additional_phone_limit?: number;
51
- };
52
-
53
- export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
54
- ? OrgPlanEnterprise
55
- : T extends AllPlans
56
- ? OrgPlanNonEnterprise
57
- : never;
58
-
59
- export type MicrosurveyData = {
60
- key: string;
61
- text: string;
62
- checked: boolean;
63
- }[];
64
-
65
- export type OrgPreferences = {
66
- disable_ai_flagging?: boolean;
67
- disable_ai_responder?: boolean;
68
- disable_allow_exports?: boolean;
69
- sync_phone_contacts?: boolean;
70
- mask_phone_numbers?: boolean;
71
- show_sender_names?: boolean;
72
- closed_chats?: Record<string, number>;
73
- auto_read_muted_chats?: boolean;
74
- member_permissions?: Record<string, boolean>;
75
- };
76
-
77
- type OrgPreferenceKey = keyof OrgPreferences;
78
-
79
- export type OrgPreferencesValue = {
80
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
81
- }[OrgPreferenceKey];
82
-
83
- export type CustomPropertySectionType = {
84
- id: string;
85
- name: string;
86
- order: number;
87
- type: 'chat' | 'ticket';
88
- properties_order?: {
89
- [id: string]: number;
90
- };
91
- };
92
-
93
- export enum CustomPropertyValueType {
94
- DROPDOWN = 'dropdown',
95
- TEXT = 'text',
96
- DATE = 'date',
97
- FILE = 'file',
98
- PICKLIST = 'picklist',
99
- DEPENDENT_DROPDOWN = 'dependent_dropdown',
100
- }
101
-
102
- export type CustomPropertyMetadataType = {
103
- section_id?: string;
104
- };
105
-
106
- export type CustomPropertyTextPropertiesType = {
107
- property_value_type: CustomPropertyValueType.TEXT;
108
- property_value: null;
109
- property_metadata: CustomPropertyMetadataType;
110
- };
111
-
112
- export type CustomPropertyDropdownPropertiesType = {
113
- property_value_type: CustomPropertyValueType.DROPDOWN;
114
- property_value: {
115
- [key: string]: string;
116
- };
117
- property_metadata: CustomPropertyMetadataType;
118
- };
119
-
120
- export type CustomPropertyPicklistPropertiesType = {
121
- property_value_type: CustomPropertyValueType.PICKLIST;
122
- property_value: {
123
- [key: string]: string;
124
- };
125
- property_metadata: CustomPropertyMetadataType;
126
- };
127
-
128
- export type CustomPropertyDependentDropdownPropertiesType = {
129
- property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
130
- property_value: {
131
- level_1: {
132
- value: string;
133
- label: string;
134
- level_2: {
135
- value: string;
136
- label: string;
137
- level_3: {
138
- value: string;
139
- label: string;
140
- }[];
141
- }[];
142
- }[];
143
- };
144
- property_metadata: Merge<
145
- CustomPropertyMetadataType,
146
- {
147
- level_names: {
148
- level_1: string;
149
- level_2: string;
150
- level_3: string;
151
- };
152
- }
153
- >;
154
- };
155
-
156
- export type CustomPropertyFilePropertiesType = {
157
- property_value_type: CustomPropertyValueType.FILE;
158
- property_value: null;
159
- property_metadata: CustomPropertyMetadataType;
160
- };
161
-
162
- export type CustomPropertyDatePropertiesType = {
163
- property_value_type: CustomPropertyValueType.DATE;
164
- property_value: null;
165
- property_metadata: CustomPropertyMetadataType;
166
- };
167
-
168
- export type CustomPropertyType = OverrideProperties<
169
- Tables<'tbl_custom_properties'>,
170
- | CustomPropertyDependentDropdownPropertiesType
171
- | CustomPropertyTextPropertiesType
172
- | CustomPropertyDropdownPropertiesType
173
- | CustomPropertyPicklistPropertiesType
174
- | CustomPropertyFilePropertiesType
175
- | CustomPropertyDatePropertiesType
176
- >;
177
-
178
- export type OrgMetadata = {
179
- phone_number: string;
180
- ticket_prefix: string;
181
- referralSource?: string;
182
- surveyData?: MicrosurveyData;
183
- preferences?: OrgPreferences;
184
- hubspot: {
185
- hubspot_pipelines?: {
186
- id: string;
187
- label: string;
188
- default_stage: { id: string; label: string };
189
- }[];
190
- hubspot_hidden_fields?: string[];
191
- };
192
- partition?: boolean;
193
- tickets: {
194
- prefix?: string;
195
- emoji_ticketing: {
196
- is_enabled?: boolean;
197
- is_message_enabled?: boolean;
198
- message_template?: string;
199
- };
200
- };
201
- attribution?: Object;
202
- affiliate_id?: string;
203
- custom_properties?: {
204
- sections?: CustomPropertySectionType[];
205
- };
206
- rules?: {
207
- limit?: number;
208
- };
209
- ai?: {
210
- flag_prompt?: string;
211
- };
212
- display_language?: string;
213
- };
214
-
215
- export type GroupTemplateType = OverrideProperties<
216
- Tables<'tbl_group_templates'>,
217
- {
218
- group_metadata: {
219
- messagesAdminsOnly?: boolean;
220
- infoAdminsOnly?: boolean;
221
- addMembersAdminsOnly?: boolean;
222
- description?: string;
223
- admins?: string[];
224
- };
225
- }
226
- >;
227
-
228
- type AccessScopes = {
229
- feature_flags: Record<string, boolean>;
230
- integrations: boolean;
231
- rules: boolean;
232
- exports: boolean;
233
- };
234
-
235
- export type OrgMembersType = OverrideProperties<
236
- Tables<'tbl_org_members'>,
237
- {
238
- member_metadata: {
239
- shift_times: {
240
- [day in
241
- | 'monday'
242
- | 'tuesday'
243
- | 'wednesday'
244
- | 'thursday'
245
- | 'friday'
246
- | 'saturday'
247
- | 'sunday']?: [[string, string]];
248
- };
249
- override_status: boolean;
250
- [key: string]: any;
251
- };
252
- }
253
- >;
254
-
255
- export type OrgType = OverrideProperties<
256
- Merge<
257
- Tables<'tbl_org'>,
258
- {
259
- user: OrgMembersType;
260
- members: OrgMembersType[];
261
- phones: Tables<'tbl_org_phones'>[];
262
- labels: Tables<'tbl_org_labels'>[];
263
- quick_replies: Tables<'tbl_quick_replies'>[];
264
- custom_properties: CustomPropertyType[];
265
- subscription_status: 'active' | 'inactive' | 'unpaid';
266
- is_enterprise: boolean;
267
- is_free_trial: boolean;
268
- is_hubspot_connected: boolean;
269
- is_freshdesk_connected: boolean;
270
- is_zohodesk_connected: boolean;
271
- access_scopes: AccessScopes;
272
- rules: Rule[];
273
- phone_limit: number;
274
- user_limit: number;
275
- }
276
- >,
277
- {
278
- org_plan: OrgPlan<AllPlans | Enterprise>;
279
- stripe_customer_details: _Stripe.Customer | null;
280
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
281
- stripe_customer_id: _Stripe.Customer['id'] | null;
282
- org_metadata: OrgMetadata;
283
- }
284
- >;
285
-
286
- export type ChatMemberType = Merge<
287
- Tables<'tbl_chat_participants'>,
288
- Tables<'tbl_contacts'>
289
- >;
290
-
291
- export type ChatType = Merge<
292
- Tables<'view_chats'>,
293
- {
294
- chat_id: string;
295
- latest_message: MessageType | null;
296
- latest_message_timestamp: number | null;
297
- members: { [key: string]: ChatMemberType } | null;
298
- chat_type: 'user' | 'group' | 'business' | 'unknown';
299
- chat_access: { [key: string]: boolean };
300
- label_ids: { [key: string]: boolean };
301
- chat_org_phones?: string[];
302
- message_unread_count: number | null;
303
- hubspot_metadata: {
304
- id: string;
305
- type: string;
306
- hubId: string;
307
- object_data: HubspotObjectDataType;
308
- } | null;
309
- info_admins_only: boolean;
310
- messages_admins_only: boolean;
311
- unread_count?: { [key: string]: number };
312
- active_phone: string | null;
313
- flag_count_map?: { [key: string]: number };
314
- is_archived?: boolean;
315
- is_pinned?: boolean;
316
- closed_at?: number | null;
317
- common_chats?: string[];
318
- freshdesk_metadata?: Record<string, any>;
319
- zohodesk_metadata?: Record<string, any>;
320
- pinned_messages?: {
321
- message_id: string;
322
- pinned_at: number;
323
- expires_at: number;
324
- }[];
325
- group_metadata?: Record<string, any>;
326
- snooze_metadata?: {
327
- snooze_until: number;
328
- snooze_message?: string;
329
- snooze_by?: string;
330
- };
331
- member_unread_count?: {
332
- [key: string]: number;
333
- };
334
- }
335
- >;
336
-
337
- /* -------------------------------------------------------------------------- */
338
- /* MESSAGE */
339
- /* -------------------------------------------------------------------------- */
340
-
341
- export type MediaType = {
342
- path?: string;
343
- mimetype?: string;
344
- filename?: string;
345
- dimensions?: { width: number; height: number; ar: number };
346
- size?: number;
347
- thumbnail?: string;
348
- filedata?: string;
349
- compress?: boolean;
350
- };
351
-
352
- export type MessageType = Merge<
353
- OverrideProperties<
354
- TablesInsert<'tbl_chat_messages'>,
355
- {
356
- message_id: string;
357
- org_id: string;
358
- org_phone: string;
359
- chat_id: string;
360
- message_type: (typeof SUPPORTED_TYPES)[number];
361
- media: MediaType | null;
362
- flag_metadata?: MessageFlagType | null;
363
- poll_info?: PollSendType | null;
364
- poll_results?: PollResultType | null;
365
- delivery_info?: DeliveryInfoType | null;
366
- raw_data?: {
367
- translations?: Record<string, string>;
368
- [key: string]: unknown;
369
- } | null;
370
- }
371
- >,
372
- {
373
- reactions?: ReactionType[];
374
- message_payload?: SingleMessagePayload;
375
- highlight?: number;
376
- is_private_note?: boolean;
377
- }
378
- >;
379
-
380
- export type MessageFlagType = {
381
- status: boolean;
382
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
383
- response_id?: string;
384
- response_timestamp?: string;
385
- response_email?: string;
386
- flagged_by?: string;
387
- flagged_at?: string;
388
- };
389
-
390
- export type MessageSendType = {
391
- queue_id: string;
392
- queue_position: string;
393
- };
394
-
395
- export type MessageBroadcastType = {
396
- broadcast_id: string;
397
- };
398
-
399
- /* -------------------------------------------------------------------------- */
400
-
401
- export type TicketType = OverrideProperties<
402
- Tables<'tbl_chat_tickets'>,
403
- {
404
- label_ids: { [key: string]: boolean };
405
- hubspot_metadata: {
406
- id?: string;
407
- type?: string;
408
- hubId?: string;
409
- pipeline: {
410
- id: string;
411
- label: string;
412
- };
413
- object_data?: HubspotObjectDataType;
414
- } | null;
415
- freshdesk_metadata: Record<string, string>;
416
- close_ticket_metadata?:
417
- | {
418
- closed_by: string;
419
- closed_at: string;
420
- closed_message?: string | null;
421
- send_reply_message_id?: string | null;
422
- }
423
- | any;
424
- }
425
- >;
426
-
427
- export type ContactType = Merge<
428
- Tables<'tbl_contacts'>,
429
- {
430
- chats: ChatType[] | null;
431
- chat_ids?: string[];
432
- }
433
- >;
434
- export type ReactionType = Tables<'tbl_chat_reactions'>;
435
-
436
- export type NotificationType = Tables<'tbl_chat_notifications'>;
437
-
438
- export type ChatAccessType = Merge<
439
- TablesUpdate<'tbl_org_members'>,
440
- {
441
- has_access?: boolean;
442
- email: string | null;
443
- }
444
- >;
445
-
446
- export type QueueJobTypes = {
447
- addedTimestamp: number;
448
- attemptsMade: number;
449
- attemptsStarted: number;
450
- data: {
451
- body: string;
452
- chat_id: string;
453
- };
454
- finishedTimestamp: number;
455
- id: string;
456
- message_id: string;
457
- processedTimestamp: number;
458
- stacktrace: string[];
459
- status: string;
460
- };
461
-
462
- export type PhoneQueueStatusType = {
463
- active: number;
464
- failed: number;
465
- completed: number;
466
- is_running: boolean;
467
- pending: number;
468
- };
469
-
470
- export type PhoneType = OverrideProperties<
471
- Tables<'tbl_org_phones'>,
472
- {
473
- queue_status: {
474
- [key: string]: PhoneQueueStatusType;
475
- };
476
- }
477
- >;
478
-
479
- export type PhoneInfoType = Merge<
480
- Pick<
481
- PhoneType,
482
- | 'created_at'
483
- | 'first_connected_at'
484
- | 'is_ready'
485
- | 'label_ids'
486
- | 'org_id'
487
- | 'org_phone'
488
- | 'phone_id'
489
- | 'phone_image'
490
- | 'phone_name'
491
- | 'qr_code'
492
- | 'updated_at'
493
- | 'wa_state'
494
- >,
495
- {
496
- labels: string[];
497
- }
498
- >;
499
-
500
- /* -------------------------------- CONSTANTS ------------------------------- */
501
-
502
- export const labelColors = [
503
- '#9333EA',
504
- '#0D9488',
505
- '#DB2777',
506
- '#2563EB',
507
- '#F97316',
508
- ];
509
-
510
- export const enumChatColors = [
511
- '#B4876E',
512
- '#A5B337',
513
- '#06CF9C',
514
- '#25D366',
515
- '#02A698',
516
- '#7D9EF1',
517
- '#007BFC',
518
- '#5E47DE',
519
- '#7F66FF',
520
- '#9333EA',
521
- '#FA6533',
522
- '#C4532D',
523
- '#DC2626',
524
- '#FF2E74',
525
- '#DB2777',
526
- ] as const;
527
-
528
- export type RepeatDaysType =
529
- | 'monday'
530
- | 'tuesday'
531
- | 'wednesday'
532
- | 'thursday'
533
- | 'friday'
534
- | 'saturday'
535
- | 'sunday';
536
- export type RepeatIntervalType = 'day' | 'week' | 'month';
537
-
538
- export enum WhatsappGroupActionEnum {
539
- ADD = 'add',
540
- REMOVE = 'remove',
541
- PROMOTE = 'promote',
542
- DEMOTE = 'demote',
543
- INVITE = 'invite',
544
- LEAVE = 'leave',
545
- ANNOUNCE_TRUE = 'announce_true',
546
- ANNOUNCE_FALSE = 'announce_false',
547
- RESTRICT_TRUE = 'restrict_true',
548
- RESTRICT_FALSE = 'restrict_false',
549
- MEMBERADDMODE_TRUE = 'memberaddmode_true',
550
- MEMBERADDMODE_FALSE = 'memberaddmode_false',
551
- SUBJECT = 'subject',
552
- DESC = 'desc',
553
- CALL = 'call',
554
- }
555
-
556
-
557
- /* -------------------------- LISTING ENDPOINT -------------------------- */
558
-
559
- type ListingType = {
560
- from?: number;
561
- to?: number;
562
- count?: number;
563
- };
564
-
565
- export type ListNotificationsType = Merge<
566
- ListingType,
567
- {
568
- notifictions?: NotificationType[];
569
- }
570
- >;
571
-
572
- export type ListChatMessagesType = Merge<
573
- ListingType,
574
- {
575
- messages?: MessageType[];
576
- }
577
- >;
578
-
579
- export type ListContactsType = Merge<
580
- ListingType,
581
- {
582
- contacts?: ContactType[];
583
- }
584
- >;
585
-
586
- export type ListTicketsType = Merge<
587
- ListingType,
588
- {
589
- tickets?: TicketType[];
590
- }
591
- >;
592
-
593
- export type ListChatsType = Merge<
594
- ListingType,
595
- {
596
- chats?: ChatType[];
597
- }
598
- >;
599
-
600
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
601
-
602
- export const SUPPORTED_TYPES = [
603
- 'chat',
604
- 'sticker',
605
- 'image',
606
- 'video',
607
- 'document',
608
- 'vcard',
609
- 'multi_vcard',
610
- 'audio',
611
- 'ptt',
612
- 'poll_creation',
613
- 'location',
614
- 'ciphertext',
615
- ] as const;
616
-
617
- export type SendMessageContent = {
618
- message_type?: (typeof SUPPORTED_TYPES)[number];
619
- body?: string;
620
- media?: MediaType;
621
- contact_ids?: string[];
622
- location?: {
623
- latitude: string;
624
- longitude: string;
625
- options?: { name?: string; address?: string; url?: string };
626
- };
627
- poll?: PollSendType;
628
- quoted_message_id?: string;
629
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
630
- broadcast_id?: string;
631
- performed_by?: string;
632
- options?: Record<string, any>;
633
- };
634
-
635
- export type QuickReplyContent = Omit<
636
- SendMessageContent,
637
- 'broadcast_id' | 'variables'
638
- >;
639
-
640
- export type ScheduleMessagePayload = {
641
- scheduled_id?: string;
642
- is_repeat?: boolean | null;
643
- scheduled_at: string;
644
- repeat_config?: {
645
- timezone?: string;
646
- repeat_ends?: string;
647
- repeat_interval?: RepeatIntervalType;
648
- repeat_value?: number;
649
- repeat_days?: RepeatDaysType[];
650
- };
651
- };
652
-
653
- export type BroadcastVariableType = {
654
- chat_id: string;
655
- values: { [key: string]: string };
656
- };
657
-
658
- export type BroadcastMessagePayload = SendMessageContent & {
659
- chat_ids: string[];
660
- broadcast_id?: string;
661
- variables?: BroadcastVariableType[];
662
- delay?: number;
663
- };
664
-
665
- export type SingleMessagePayload = SendMessageContent & {
666
- chat_id: string;
667
- job_id?: string;
668
- priority?: number;
669
- };
670
-
671
- export type MessageAttachmentFileTypes =
672
- | 'image'
673
- | 'audio'
674
- | 'document'
675
- | 'video';
676
-
677
- export type AttachmentFileType = {
678
- result: string;
679
- file: File | null;
680
- type: MessageAttachmentFileTypes;
681
- localFileURL?: string;
682
- };
683
-
684
- export type AttachmentLinkType = {
685
- link: {
686
- url: string;
687
- type: MessageAttachmentFileTypes;
688
- name: string;
689
- mimetype?: string;
690
- };
691
- };
692
-
693
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
694
-
695
- /* -------------------------------- BROADCAST ------------------------------- */
696
-
697
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
698
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
699
- } & {
700
- chats: ChatType[];
701
- };
702
-
703
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
704
-
705
- export type ChatLogType = {
706
- log: Tables<'view_chat_logs'>;
707
- operations: Tables<'tbl_chat_logs'>[];
708
- };
709
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
710
-
711
- export type ChatParticipantOperationPayload = {
712
- participant_ids: string[];
713
- chat_ids: string[];
714
- performed_by: string;
715
- };
716
-
717
- export type ChatOperationReturn = {
718
- [participant_id: string]: {
719
- is_success: boolean;
720
- message?: string;
721
- code?: number;
722
- isInviteV4Sent?: boolean;
723
- };
724
- };
725
-
726
- /* ----------------------- BILLING - STRIPE ----------------------- */
727
-
728
- export type StripeSubscription = _Stripe.Subscription;
729
- export type StripeCustomer = _Stripe.Customer;
730
- export type StripeCoupon = _Stripe.Coupon;
731
- export type StripePrice = _Stripe.Price;
732
- export type Stripe = _Stripe;
733
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
734
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
735
-
736
- /* -------------------------------- REALTIME -------------------------------- */
737
-
738
- export type PhoneStateType = {
739
- loading: boolean;
740
- state: string;
741
- sync: number;
742
- percent: number | null;
743
- message?: string;
744
- error?: string;
745
- };
746
-
747
- /* ------------------------------- INTEGRATIONS ----------------------------- */
748
-
749
- export type ChatInfoType = Merge<
750
- ChatType,
751
- {
752
- members: {
753
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
754
- } | null;
755
- chat_labels: string | null;
756
- custom_properties: { [key: string]: string } | null;
757
- }
758
- >;
759
-
760
- export type TicketInfoType = {
761
- chat: ChatInfoType;
762
- message: {
763
- body: string;
764
- chat_id: string;
765
- org_phone: string;
766
- timestamp: string;
767
- media_path: string;
768
- message_id: string;
769
- sender_name: string;
770
- performed_by: string;
771
- sender_phone: string;
772
- };
773
- ticket: {
774
- org_id: string;
775
- status: string;
776
- subject: string;
777
- assignee: string;
778
- due_date: string;
779
- priority: 0 | 1 | 2 | 3 | 4;
780
- raised_by: string;
781
- ticket_id: string;
782
- created_at: string;
783
- assigned_by: string;
784
- ticket_labels: string;
785
- quoted_message_id: string;
786
- ticket_custom_properties: { [key: string]: string } | null;
787
- };
788
- attached_messages: {
789
- body: string;
790
- chat_id: string;
791
- org_phone: string;
792
- timestamp: string;
793
- media_path: string;
794
- message_id: string;
795
- sender_name: string;
796
- performed_by: string;
797
- sender_phone: string;
798
- }[];
799
- };
800
-
801
- export type IntegrationLogObjectType =
802
- | 'chat'
803
- | 'message'
804
- | 'reaction'
805
- | 'ticket'
806
- | 'phone';
807
- export enum IntegrationLogType {
808
- NEW_CHAT = 'chat.created',
809
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
810
- NEW_MESSAGE = 'message.created',
811
- MESSAGE_UPDATED = 'message.updated',
812
- MESSAGE_DELETED = 'message.deleted',
813
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
814
- REACTION_CREATED = 'reaction.created',
815
- REACTION_UPDATED = 'reaction.updated',
816
- NEW_TICKET = 'ticket.created',
817
- TICKET_UPDATED = 'ticket.updated',
818
- TICKET_DELETED = 'ticket.deleted',
819
- MESSAGE_FLAGGED = 'message.flagged',
820
- MESSAGE_UNFLAGGED = 'message.unflagged',
821
- PHONE_DISCONNECTED = 'org.phone.disconnected',
822
- PHONE_CONNECTED = 'org.phone.connected',
823
- PHONE_UPDATED = 'org.phone.updated',
824
- PHONE_QR_UPDATED = 'org.phone.qr',
825
- }
826
-
827
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
828
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
829
- ? TicketInfoType
830
- : T extends IntegrationLogType.NEW_CHAT
831
- ? Tables<'tbl_chats'>
832
- : T extends
833
- | IntegrationLogType.NEW_MESSAGE
834
- | IntegrationLogType.MESSAGE_UPDATED
835
- | IntegrationLogType.MESSAGE_DELETED
836
- | IntegrationLogType.MESSAGE_ACK_UPDATED
837
- | IntegrationLogType.MESSAGE_FLAGGED
838
- | IntegrationLogType.MESSAGE_UNFLAGGED
839
- ? Tables<'tbl_chat_messages'>
840
- : T extends
841
- | IntegrationLogType.REACTION_CREATED
842
- | IntegrationLogType.REACTION_UPDATED
843
- ? Tables<'tbl_chat_reactions'>
844
- : T extends
845
- | IntegrationLogType.PHONE_DISCONNECTED
846
- | IntegrationLogType.PHONE_CONNECTED
847
- | IntegrationLogType.PHONE_UPDATED
848
- | IntegrationLogType.PHONE_QR_UPDATED
849
- ? Tables<'tbl_org_phones'>
850
- : {
851
- [key: string]: unknown;
852
- };
853
-
854
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
855
- OverrideProperties<
856
- Tables<'tbl_integration_logs'>,
857
- {
858
- integration_name: T;
859
- metadata: {
860
- event: IntegrationLogMetadataType<T> & {
861
- event_type: string;
862
- org_id: string;
863
- previous_attributes: {
864
- [key: string]: unknown;
865
- };
866
- };
867
- hook_id: string;
868
- name: string;
869
- };
870
- }
871
- >;
872
-
873
- export type APIAuthDetails = {
874
- org_details: Tables<'view_org'> | null;
875
- phone_details: Tables<'tbl_org_phones'> | null;
876
- token_details: Tables<'tbl_integration_tokens'> | null;
877
- };
878
-
879
- export type WebhookDataType = OverrideProperties<
880
- Tables<'tbl_integration_hooks'>,
881
- {
882
- integration_name: string[];
883
- }
884
- >;
885
-
886
- export type HubspotObjectDataType = {
887
- createdAt: string;
888
- archived: boolean;
889
- id: string;
890
- type: 'contacts' | 'tickets' | 'companies';
891
- properties: Record<
892
- string,
893
- {
894
- groupLabel: string;
895
- groupName: string;
896
- propertyKeyName: string;
897
- propertyKey: string;
898
- propertyInternalValue: string;
899
- propertyValue: string;
900
- propertyType: string;
901
- propertyFieldType: string;
902
- }[]
903
- >;
904
- };
905
-
906
- /* ---------------------------- USER PREFERENCES ---------------------------- */
907
-
908
- export type UserPreferences = {
909
- theme: 'light' | 'dark';
910
- language: 'en' | 'es';
911
- left_sidebar_open: boolean;
912
- right_sidepanel_open: boolean;
913
- sync_wa_unread_count: boolean;
914
- pinned_chats: string[];
915
- archived_chats: string[];
916
- closed_chats: Record<string, number>;
917
- periskope_chat_limit: number;
918
- notifications: Record<string, boolean>;
919
- };
920
-
921
- /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
922
-
923
- export interface MostActiveMember {
924
- sender_phone: string;
925
- total_messages: number;
926
- }
927
-
928
- export interface GroupAnalyticsResult {
929
- total_messages: number;
930
- total_joins: number;
931
- total_leaves: number;
932
- total_removes: number;
933
- total_reactions: number;
934
- most_active_members: MostActiveMember[];
935
- }
936
-
937
- export interface TimeRange {
938
- startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
939
- endDateTime: string;
940
- }
941
-
942
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
943
-
944
- export type PollSendType = {
945
- pollName: string;
946
- pollOptions: string[];
947
- options?: {
948
- allowMultipleAnswers?: boolean;
949
- messageSecret?: number[] | null;
950
- pollId?: string;
951
- };
952
- };
953
-
954
- export type PollResultType = {
955
- [name: string]: Record<string, string>;
956
- };
957
-
958
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
959
-
960
- export type CreateGroupOptions = {
961
- messagesAdminsOnly?: boolean;
962
- infoAdminsOnly?: boolean;
963
- addMembersAdminsOnly?: boolean;
964
- image?: string;
965
- name?: string;
966
- description?: string;
967
- initiated_by?: string;
968
- admins?: string[];
969
- };
970
-
971
- /* ------------------------------ DELIVERY INFO ----------------------------- */
972
-
973
- export type DeliveryInfoType = {
974
- delivered: Record<string, number | undefined>;
975
- read: Record<string, number | undefined>;
976
- pending: string[];
977
- read_count: number;
978
- delivered_count: number;
979
- };
980
-
981
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
982
-
983
- export type OrgCreditsType = {
984
- org_id: string;
985
- recurring_allowance: number; // recurring credits replenished every cycle
986
- recurring_balance: number; // recurring credits remaining in current cycle
987
- topup_balance: number; // topup credits remaining
988
- total_credits_used: number; // total credits used in current cycle
989
- next_renewal_date: string;
990
- topup_credits_used: number; // topup credits used in current cycle
991
- recurring_credits_used: number; // recurring credits used in current cycle
992
- };
993
-
994
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
995
-
996
- export type ChatRuleInfoType = Merge<
997
- Pick<
998
- Tables<'view_chats'>,
999
- | 'assigned_to'
1000
- | 'chat_id'
1001
- | 'chat_name'
1002
- | 'chat_type'
1003
- | 'created_at'
1004
- | 'group_description'
1005
- | 'info_admins_only'
1006
- | 'org_id'
1007
- | 'org_phone'
1008
- | 'chat_org_phones'
1009
- | 'messages_admins_only'
1010
- | 'custom_properties'
1011
- | 'initiated_by'
1012
- >,
1013
- {
1014
- has_flagged_messages: boolean;
1015
- labels: string[];
1016
- members: string[];
1017
- custom_properties: { [key: string]: string } | null;
1018
- }
1019
- >;
1020
-
1021
- export type SenderRuleInfoType = Merge<
1022
- Omit<
1023
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1024
- | 'verified_name'
1025
- | 'verified_level'
1026
- | 'updated_at'
1027
- | 'short_name'
1028
- | 'pushname'
1029
- | 'periskope_name'
1030
- | 'org_phone'
1031
- | 'number'
1032
- | 'name'
1033
- | 'label_ids'
1034
- | 'is_wa_contact'
1035
- | 'is_user'
1036
- | 'is_my_contact'
1037
- | 'is_me'
1038
- | 'is_imported'
1039
- | 'is_group'
1040
- | 'is_blocked'
1041
- | 'contact_color'
1042
- | 'business_profile'
1043
- | 'id'
1044
- | 'contact_image'
1045
- | 'contact_type'
1046
- | 'chat_id'
1047
- | 'is_business'
1048
- | 'is_enterprise'
1049
- | 'is_super_admin'
1050
- >,
1051
- {
1052
- is_internal: boolean;
1053
- labels: string[] | null;
1054
- }
1055
- >;
1056
-
1057
- export type MessageRuleInfoType = {
1058
- chat: ChatRuleInfoType;
1059
- sender: SenderRuleInfoType;
1060
- message: OverrideProperties<
1061
- Omit<
1062
- Tables<'tbl_chat_messages'>,
1063
- | 'vcards'
1064
- | 'updated_at'
1065
- | 'unique_id'
1066
- | 'token'
1067
- | 'to'
1068
- | 'sent_message_id'
1069
- | 'raw_data'
1070
- | 'delivery_info'
1071
- | 'poll_results'
1072
- | 'poll_info'
1073
- | 'order_id'
1074
- | 'mentioned_ids'
1075
- | 'media_key'
1076
- | 'location'
1077
- | 'links'
1078
- | 'is_status'
1079
- | 'is_starred'
1080
- | 'is_gif'
1081
- | 'is_forwarded'
1082
- | 'is_ephemeral'
1083
- | 'is_deleted'
1084
- | 'fts'
1085
- | 'quoted_message_id'
1086
- | 'invite_v4'
1087
- | 'id'
1088
- | 'has_reaction'
1089
- | 'has_media'
1090
- | 'duration'
1091
- | 'broadcast'
1092
- | 'broadcast_id'
1093
- | 'device_type'
1094
- | 'forwarding_score'
1095
- | 'from'
1096
- | 'from_me'
1097
- | 'prev_body'
1098
- | 'flag_response_time'
1099
- | 'flag_metadata'
1100
- | 'ack'
1101
- >,
1102
- {
1103
- media: MediaType | null;
1104
- }
1105
- >;
1106
- };
1107
-
1108
- export type ReactionRuleInfoType = {
1109
- chat: ChatRuleInfoType;
1110
- sender: SenderRuleInfoType;
1111
- message: MessageRuleInfoType['message'];
1112
- reaction: Pick<
1113
- Tables<'tbl_chat_reactions'>,
1114
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1115
- >;
1116
- };
1117
-
1118
- export type TicketRuleInfoType = {
1119
- chat: ChatRuleInfoType;
1120
- sender: SenderRuleInfoType;
1121
- ticket: Merge<
1122
- Pick<
1123
- Tables<'tbl_chat_tickets'>,
1124
- | 'org_id'
1125
- | 'status'
1126
- | 'chat_id'
1127
- | 'subject'
1128
- | 'assignee'
1129
- | 'due_date'
1130
- | 'priority'
1131
- | 'raised_by'
1132
- | 'ticket_id'
1133
- | 'created_at'
1134
- | 'is_deleted'
1135
- >,
1136
- {
1137
- labels: string[] | null;
1138
- custom_properties: { [key: string]: string } | null;
1139
- }
1140
- >;
1141
- message: MessageRuleInfoType['message'];
1142
- };
1143
- export type FeatureFlagReturnType = Record<string, boolean>;
1144
-
1145
- export type RuleLogsType = OverrideProperties<
1146
- Tables<'tbl_rules_logs'>,
1147
- {
1148
- actions_progress: {
1149
- action_id: string;
1150
- action_type: Rule['actions'][number]['type'];
1151
- action_delay: Rule['actions'][number]['delay'];
1152
- ran_at: string | null;
1153
- action_status: 'success' | 'failed' | 'pending';
1154
- action_response: {
1155
- success: boolean;
1156
- data: Record<string, unknown> | null;
1157
- error: {
1158
- message: string;
1159
- name: string;
1160
- stack?: string;
1161
- _error?: Error | Record<string, unknown>;
1162
- } | null;
1163
- };
1164
- }[];
1165
- metadata: {
1166
- conditions: Rule['conditions'];
1167
- actions: Rule['actions'];
1168
- rule_metadata: Pick<
1169
- Rule,
1170
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1171
- >;
1172
- data: Record<string, unknown>;
1173
- };
1174
- conditions_progress: {
1175
- is_valid: boolean;
1176
- validation_progress: Record<
1177
- string,
1178
- {
1179
- res: boolean;
1180
- filter: Filter;
1181
- value: unknown;
1182
- }
1183
- >;
1184
- checked_at: string | null;
1185
- };
1186
- }
1187
- >;
1188
-
1189
- /************************** TASKS ***************************/
1190
-
1191
- export type TaskType = OverrideProperties<
1192
- Tables<'tbl_org_tasks'>,
1193
- {
1194
- reminder_setting: {
1195
- remind_in:
1196
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1197
- | string
1198
- | null;
1199
- repeat?: {
1200
- frequency: number;
1201
- interval: 'days' | 'weeks' | 'months' | 'years';
1202
- end: 'never' | 'after' | 'on';
1203
- on?: string;
1204
- };
1205
- } | null;
1206
- associated_object_metadata:
1207
- | {
1208
- type: 'chat';
1209
- index: 'chat_id';
1210
- id: string;
1211
- object: ChatType;
1212
- }
1213
- | {
1214
- type: 'message';
1215
- index: 'message_id';
1216
- id: string;
1217
- object: MessageType;
1218
- }
1219
- | {
1220
- type: 'ticket';
1221
- index: 'ticket_id';
1222
- id: string;
1223
- object: TicketType;
1224
- }
1225
- | null;
1226
- status: 'open' | 'inprogress' | 'closed';
1227
- priority: 1 | 2 | 3;
1228
- completed_metadata?: {
1229
- completed_at: string;
1230
- completed_by: string;
1231
- } | null;
1232
- type: 'todo' | 'chat' | 'message' | 'ticket';
1233
- }
1234
- >;
1235
-
1236
- type Choice = {
1237
- id: number;
1238
- label: string;
1239
- value: string;
1240
- position: number;
1241
- };
1242
-
1243
- export type FreshdeskCustomFieldType = {
1244
- id: number;
1245
- name: string;
1246
- label: string;
1247
- position: number;
1248
- required_for_agents: boolean;
1249
- archived: boolean;
1250
- customers_can_edit: boolean;
1251
- label_for_customers: string;
1252
- required_for_customers: boolean;
1253
- customers_can_filter: boolean;
1254
- required_for_closure: boolean;
1255
- displayed_to_customers: boolean;
1256
- type: string;
1257
- default: boolean;
1258
- created_at: string;
1259
- updated_at: string;
1260
- choices?: Choice[];
1261
- };
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, TablesInsert, 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
+ additional_user_limit?: number;
37
+ additional_phone_limit?: number;
38
+ };
39
+
40
+ export type OrgPlanNonEnterprise = {
41
+ subscription_id: string;
42
+ plan_id: AllPlans;
43
+ interval: number;
44
+ frequency: Frequency;
45
+ user_limit: number;
46
+ phone_limit: number;
47
+ current_period_end: number;
48
+ current_period_start: number;
49
+ additional_user_limit?: number;
50
+ additional_phone_limit?: number;
51
+ };
52
+
53
+ export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
54
+ ? OrgPlanEnterprise
55
+ : T extends AllPlans
56
+ ? OrgPlanNonEnterprise
57
+ : never;
58
+
59
+ export type MicrosurveyData = {
60
+ key: string;
61
+ text: string;
62
+ checked: boolean;
63
+ }[];
64
+
65
+ export type OrgPreferences = {
66
+ disable_ai_flagging?: boolean;
67
+ disable_ai_responder?: boolean;
68
+ ai_responder_default_on?: boolean;
69
+ disable_allow_exports?: boolean;
70
+ sync_phone_contacts?: boolean;
71
+ mask_phone_numbers?: boolean;
72
+ show_sender_names?: boolean;
73
+ closed_chats?: Record<string, number>;
74
+ auto_read_muted_chats?: boolean;
75
+ member_permissions?: Record<string, boolean>;
76
+ };
77
+
78
+ type OrgPreferenceKey = keyof OrgPreferences;
79
+
80
+ export type OrgPreferencesValue = {
81
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
82
+ }[OrgPreferenceKey];
83
+
84
+ export type CustomPropertySectionType = {
85
+ id: string;
86
+ name: string;
87
+ order: number;
88
+ type: 'chat' | 'ticket';
89
+ properties_order?: {
90
+ [id: string]: number;
91
+ };
92
+ };
93
+
94
+ export enum CustomPropertyValueType {
95
+ DROPDOWN = 'dropdown',
96
+ TEXT = 'text',
97
+ DATE = 'date',
98
+ FILE = 'file',
99
+ PICKLIST = 'picklist',
100
+ DEPENDENT_DROPDOWN = 'dependent_dropdown',
101
+ }
102
+
103
+ export type CustomPropertyMetadataType = {
104
+ section_id?: string;
105
+ };
106
+
107
+ export type CustomPropertyTextPropertiesType = {
108
+ property_value_type: CustomPropertyValueType.TEXT;
109
+ property_value: null;
110
+ property_metadata: CustomPropertyMetadataType;
111
+ };
112
+
113
+ export type CustomPropertyDropdownPropertiesType = {
114
+ property_value_type: CustomPropertyValueType.DROPDOWN;
115
+ property_value: {
116
+ [key: string]: string;
117
+ };
118
+ property_metadata: CustomPropertyMetadataType;
119
+ };
120
+
121
+ export type CustomPropertyPicklistPropertiesType = {
122
+ property_value_type: CustomPropertyValueType.PICKLIST;
123
+ property_value: {
124
+ [key: string]: string;
125
+ };
126
+ property_metadata: CustomPropertyMetadataType;
127
+ };
128
+
129
+ export type CustomPropertyDependentDropdownPropertiesType = {
130
+ property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
131
+ property_value: {
132
+ level_1: {
133
+ value: string;
134
+ label: string;
135
+ level_2: {
136
+ value: string;
137
+ label: string;
138
+ level_3: {
139
+ value: string;
140
+ label: string;
141
+ }[];
142
+ }[];
143
+ }[];
144
+ };
145
+ property_metadata: Merge<
146
+ CustomPropertyMetadataType,
147
+ {
148
+ level_names: {
149
+ level_1: string;
150
+ level_2: string;
151
+ level_3: string;
152
+ };
153
+ }
154
+ >;
155
+ };
156
+
157
+ export type CustomPropertyFilePropertiesType = {
158
+ property_value_type: CustomPropertyValueType.FILE;
159
+ property_value: null;
160
+ property_metadata: CustomPropertyMetadataType;
161
+ };
162
+
163
+ export type CustomPropertyDatePropertiesType = {
164
+ property_value_type: CustomPropertyValueType.DATE;
165
+ property_value: null;
166
+ property_metadata: CustomPropertyMetadataType;
167
+ };
168
+
169
+ export type CustomPropertyType = OverrideProperties<
170
+ Tables<'tbl_custom_properties'>,
171
+ | CustomPropertyDependentDropdownPropertiesType
172
+ | CustomPropertyTextPropertiesType
173
+ | CustomPropertyDropdownPropertiesType
174
+ | CustomPropertyPicklistPropertiesType
175
+ | CustomPropertyFilePropertiesType
176
+ | CustomPropertyDatePropertiesType
177
+ >;
178
+
179
+ export type OrgMetadata = {
180
+ phone_number: string;
181
+ ticket_prefix: string;
182
+ referralSource?: string;
183
+ surveyData?: MicrosurveyData;
184
+ preferences?: OrgPreferences;
185
+ hubspot: {
186
+ hubspot_pipelines?: {
187
+ id: string;
188
+ label: string;
189
+ default_stage: { id: string; label: string };
190
+ }[];
191
+ hubspot_hidden_fields?: string[];
192
+ };
193
+ partition?: boolean;
194
+ tickets: {
195
+ prefix?: string;
196
+ emoji_ticketing: {
197
+ is_enabled?: boolean;
198
+ is_message_enabled?: boolean;
199
+ message_template?: string;
200
+ };
201
+ };
202
+ attribution?: Object;
203
+ affiliate_id?: string;
204
+ custom_properties?: {
205
+ sections?: CustomPropertySectionType[];
206
+ };
207
+ rules?: {
208
+ limit?: number;
209
+ };
210
+ ai?: {
211
+ flag_prompt?: string;
212
+ };
213
+ display_language?: string;
214
+ };
215
+
216
+ export type GroupTemplateType = OverrideProperties<
217
+ Tables<'tbl_group_templates'>,
218
+ {
219
+ group_metadata: {
220
+ messagesAdminsOnly?: boolean;
221
+ infoAdminsOnly?: boolean;
222
+ addMembersAdminsOnly?: boolean;
223
+ description?: string;
224
+ admins?: string[];
225
+ };
226
+ }
227
+ >;
228
+
229
+ type AccessScopes = {
230
+ feature_flags: Record<string, boolean>;
231
+ integrations: boolean;
232
+ rules: boolean;
233
+ exports: boolean;
234
+ };
235
+
236
+ export type OrgMembersType = OverrideProperties<
237
+ Tables<'tbl_org_members'>,
238
+ {
239
+ member_metadata: {
240
+ shift_times: {
241
+ [day in
242
+ | 'monday'
243
+ | 'tuesday'
244
+ | 'wednesday'
245
+ | 'thursday'
246
+ | 'friday'
247
+ | 'saturday'
248
+ | 'sunday']?: [[string, string]];
249
+ };
250
+ override_status: boolean;
251
+ [key: string]: any;
252
+ };
253
+ }
254
+ >;
255
+
256
+ export type OrgType = OverrideProperties<
257
+ Merge<
258
+ Tables<'tbl_org'>,
259
+ {
260
+ user: OrgMembersType;
261
+ members: OrgMembersType[];
262
+ phones: Tables<'tbl_org_phones'>[];
263
+ labels: Tables<'tbl_org_labels'>[];
264
+ quick_replies: Tables<'tbl_quick_replies'>[];
265
+ custom_properties: CustomPropertyType[];
266
+ subscription_status: 'active' | 'inactive' | 'unpaid';
267
+ is_enterprise: boolean;
268
+ is_free_trial: boolean;
269
+ is_hubspot_connected: boolean;
270
+ is_freshdesk_connected: boolean;
271
+ is_zohodesk_connected: boolean;
272
+ access_scopes: AccessScopes;
273
+ rules: Rule[];
274
+ phone_limit: number;
275
+ user_limit: number;
276
+ }
277
+ >,
278
+ {
279
+ org_plan: OrgPlan<AllPlans | Enterprise>;
280
+ stripe_customer_details: _Stripe.Customer | null;
281
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
282
+ stripe_customer_id: _Stripe.Customer['id'] | null;
283
+ org_metadata: OrgMetadata;
284
+ }
285
+ >;
286
+
287
+ export type ChatMemberType = Merge<
288
+ Tables<'tbl_chat_participants'>,
289
+ Tables<'tbl_contacts'>
290
+ >;
291
+
292
+ export type ChatType = Merge<
293
+ Tables<'view_chats'>,
294
+ {
295
+ chat_id: string;
296
+ latest_message: MessageType | null;
297
+ latest_message_timestamp: number | null;
298
+ members: { [key: string]: ChatMemberType } | null;
299
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
300
+ chat_access: { [key: string]: boolean };
301
+ label_ids: { [key: string]: boolean };
302
+ chat_org_phones?: string[];
303
+ message_unread_count: number | null;
304
+ hubspot_metadata: {
305
+ id: string;
306
+ type: string;
307
+ hubId: string;
308
+ object_data: HubspotObjectDataType;
309
+ } | null;
310
+ info_admins_only: boolean;
311
+ messages_admins_only: boolean;
312
+ unread_count?: { [key: string]: number };
313
+ active_phone: string | null;
314
+ flag_count_map?: { [key: string]: number };
315
+ is_archived?: boolean;
316
+ is_pinned?: boolean;
317
+ closed_at?: number | null;
318
+ common_chats?: string[];
319
+ freshdesk_metadata?: Record<string, any>;
320
+ zohodesk_metadata?: Record<string, any>;
321
+ pinned_messages?: {
322
+ message_id: string;
323
+ pinned_at: number;
324
+ expires_at: number;
325
+ }[];
326
+ group_metadata?: Record<string, any>;
327
+ snooze_metadata?: {
328
+ snooze_until: number;
329
+ snooze_message?: string;
330
+ snooze_by?: string;
331
+ };
332
+ member_unread_count?: {
333
+ [key: string]: number;
334
+ };
335
+ }
336
+ >;
337
+
338
+ /* -------------------------------------------------------------------------- */
339
+ /* MESSAGE */
340
+ /* -------------------------------------------------------------------------- */
341
+
342
+ export type MediaType = {
343
+ path?: string;
344
+ mimetype?: string;
345
+ filename?: string;
346
+ dimensions?: { width: number; height: number; ar: number };
347
+ size?: number;
348
+ thumbnail?: string;
349
+ filedata?: string;
350
+ compress?: boolean;
351
+ };
352
+
353
+ export type MessageType = Merge<
354
+ OverrideProperties<
355
+ TablesInsert<'tbl_chat_messages'>,
356
+ {
357
+ message_id: string;
358
+ org_id: string;
359
+ org_phone: string;
360
+ chat_id: string;
361
+ message_type: (typeof SUPPORTED_TYPES)[number];
362
+ media: MediaType | null;
363
+ flag_metadata?: MessageFlagType | null;
364
+ poll_info?: PollSendType | null;
365
+ poll_results?: PollResultType | null;
366
+ delivery_info?: DeliveryInfoType | null;
367
+ raw_data?: {
368
+ translations?: Record<string, string>;
369
+ [key: string]: unknown;
370
+ } | null;
371
+ }
372
+ >,
373
+ {
374
+ reactions?: ReactionType[];
375
+ message_payload?: SingleMessagePayload;
376
+ highlight?: number;
377
+ is_private_note?: boolean;
378
+ }
379
+ >;
380
+
381
+ export type MessageFlagType = {
382
+ status: boolean;
383
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
384
+ response_id?: string;
385
+ response_timestamp?: string;
386
+ response_email?: string;
387
+ flagged_by?: string;
388
+ flagged_at?: string;
389
+ };
390
+
391
+ export type MessageSendType = {
392
+ queue_id: string;
393
+ queue_position: string;
394
+ };
395
+
396
+ export type MessageBroadcastType = {
397
+ broadcast_id: string;
398
+ };
399
+
400
+ /* -------------------------------------------------------------------------- */
401
+
402
+ export type TicketType = OverrideProperties<
403
+ Tables<'tbl_chat_tickets'>,
404
+ {
405
+ label_ids: { [key: string]: boolean };
406
+ hubspot_metadata: {
407
+ id?: string;
408
+ type?: string;
409
+ hubId?: string;
410
+ pipeline: {
411
+ id: string;
412
+ label: string;
413
+ };
414
+ object_data?: HubspotObjectDataType;
415
+ } | null;
416
+ freshdesk_metadata: Record<string, string>;
417
+ close_ticket_metadata?:
418
+ | {
419
+ closed_by: string;
420
+ closed_at: string;
421
+ closed_message?: string | null;
422
+ send_reply_message_id?: string | null;
423
+ }
424
+ | any;
425
+ }
426
+ >;
427
+
428
+ export type ContactType = Merge<
429
+ Tables<'tbl_contacts'>,
430
+ {
431
+ chats: ChatType[] | null;
432
+ chat_ids?: string[];
433
+ }
434
+ >;
435
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
436
+
437
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
438
+
439
+ export type ChatAccessType = Merge<
440
+ TablesUpdate<'tbl_org_members'>,
441
+ {
442
+ has_access?: boolean;
443
+ email: string | null;
444
+ }
445
+ >;
446
+
447
+ export type QueueJobTypes = {
448
+ addedTimestamp: number;
449
+ attemptsMade: number;
450
+ attemptsStarted: number;
451
+ data: {
452
+ body: string;
453
+ chat_id: string;
454
+ };
455
+ finishedTimestamp: number;
456
+ id: string;
457
+ message_id: string;
458
+ processedTimestamp: number;
459
+ stacktrace: string[];
460
+ status: string;
461
+ };
462
+
463
+ export type PhoneQueueStatusType = {
464
+ active: number;
465
+ failed: number;
466
+ completed: number;
467
+ is_running: boolean;
468
+ pending: number;
469
+ };
470
+
471
+ export type PhoneType = OverrideProperties<
472
+ Tables<'tbl_org_phones'>,
473
+ {
474
+ queue_status: {
475
+ [key: string]: PhoneQueueStatusType;
476
+ };
477
+ }
478
+ >;
479
+
480
+ export type PhoneInfoType = Merge<
481
+ Pick<
482
+ PhoneType,
483
+ | 'created_at'
484
+ | 'first_connected_at'
485
+ | 'is_ready'
486
+ | 'label_ids'
487
+ | 'org_id'
488
+ | 'org_phone'
489
+ | 'phone_id'
490
+ | 'phone_image'
491
+ | 'phone_name'
492
+ | 'qr_code'
493
+ | 'updated_at'
494
+ | 'wa_state'
495
+ >,
496
+ {
497
+ labels: string[];
498
+ }
499
+ >;
500
+
501
+ /* -------------------------------- CONSTANTS ------------------------------- */
502
+
503
+ export const labelColors = [
504
+ '#9333EA',
505
+ '#0D9488',
506
+ '#DB2777',
507
+ '#2563EB',
508
+ '#F97316',
509
+ ];
510
+
511
+ export const enumChatColors = [
512
+ '#B4876E',
513
+ '#A5B337',
514
+ '#06CF9C',
515
+ '#25D366',
516
+ '#02A698',
517
+ '#7D9EF1',
518
+ '#007BFC',
519
+ '#5E47DE',
520
+ '#7F66FF',
521
+ '#9333EA',
522
+ '#FA6533',
523
+ '#C4532D',
524
+ '#DC2626',
525
+ '#FF2E74',
526
+ '#DB2777',
527
+ ] as const;
528
+
529
+ export type RepeatDaysType =
530
+ | 'monday'
531
+ | 'tuesday'
532
+ | 'wednesday'
533
+ | 'thursday'
534
+ | 'friday'
535
+ | 'saturday'
536
+ | 'sunday';
537
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
538
+
539
+ export enum WhatsappGroupActionEnum {
540
+ ADD = 'add',
541
+ REMOVE = 'remove',
542
+ PROMOTE = 'promote',
543
+ DEMOTE = 'demote',
544
+ INVITE = 'invite',
545
+ LEAVE = 'leave',
546
+ ANNOUNCE_TRUE = 'announce_true',
547
+ ANNOUNCE_FALSE = 'announce_false',
548
+ RESTRICT_TRUE = 'restrict_true',
549
+ RESTRICT_FALSE = 'restrict_false',
550
+ MEMBERADDMODE_TRUE = 'memberaddmode_true',
551
+ MEMBERADDMODE_FALSE = 'memberaddmode_false',
552
+ SUBJECT = 'subject',
553
+ DESC = 'desc',
554
+ CALL = 'call',
555
+ }
556
+
557
+
558
+ /* -------------------------- LISTING ENDPOINT -------------------------- */
559
+
560
+ type ListingType = {
561
+ from?: number;
562
+ to?: number;
563
+ count?: number;
564
+ };
565
+
566
+ export type ListNotificationsType = Merge<
567
+ ListingType,
568
+ {
569
+ notifictions?: NotificationType[];
570
+ }
571
+ >;
572
+
573
+ export type ListChatMessagesType = Merge<
574
+ ListingType,
575
+ {
576
+ messages?: MessageType[];
577
+ }
578
+ >;
579
+
580
+ export type ListContactsType = Merge<
581
+ ListingType,
582
+ {
583
+ contacts?: ContactType[];
584
+ }
585
+ >;
586
+
587
+ export type ListTicketsType = Merge<
588
+ ListingType,
589
+ {
590
+ tickets?: TicketType[];
591
+ }
592
+ >;
593
+
594
+ export type ListChatsType = Merge<
595
+ ListingType,
596
+ {
597
+ chats?: ChatType[];
598
+ }
599
+ >;
600
+
601
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
602
+
603
+ export const SUPPORTED_TYPES = [
604
+ 'chat',
605
+ 'sticker',
606
+ 'image',
607
+ 'video',
608
+ 'document',
609
+ 'vcard',
610
+ 'multi_vcard',
611
+ 'audio',
612
+ 'ptt',
613
+ 'poll_creation',
614
+ 'location',
615
+ 'ciphertext',
616
+ ] as const;
617
+
618
+ export type SendMessageContent = {
619
+ message_type?: (typeof SUPPORTED_TYPES)[number];
620
+ body?: string;
621
+ media?: MediaType;
622
+ contact_ids?: string[];
623
+ location?: {
624
+ latitude: string;
625
+ longitude: string;
626
+ options?: { name?: string; address?: string; url?: string };
627
+ };
628
+ poll?: PollSendType;
629
+ quoted_message_id?: string;
630
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
631
+ broadcast_id?: string;
632
+ performed_by?: string;
633
+ options?: Record<string, any>;
634
+ };
635
+
636
+ export type QuickReplyContent = Omit<
637
+ SendMessageContent,
638
+ 'broadcast_id' | 'variables'
639
+ >;
640
+
641
+ export type ScheduleMessagePayload = {
642
+ scheduled_id?: string;
643
+ is_repeat?: boolean | null;
644
+ scheduled_at: string;
645
+ repeat_config?: {
646
+ timezone?: string;
647
+ repeat_ends?: string;
648
+ repeat_interval?: RepeatIntervalType;
649
+ repeat_value?: number;
650
+ repeat_days?: RepeatDaysType[];
651
+ };
652
+ };
653
+
654
+ export type BroadcastVariableType = {
655
+ chat_id: string;
656
+ values: { [key: string]: string };
657
+ };
658
+
659
+ export type BroadcastMessagePayload = SendMessageContent & {
660
+ chat_ids: string[];
661
+ broadcast_id?: string;
662
+ variables?: BroadcastVariableType[];
663
+ delay?: number;
664
+ };
665
+
666
+ export type SingleMessagePayload = SendMessageContent & {
667
+ chat_id: string;
668
+ job_id?: string;
669
+ priority?: number;
670
+ };
671
+
672
+ export type MessageAttachmentFileTypes =
673
+ | 'image'
674
+ | 'audio'
675
+ | 'document'
676
+ | 'video';
677
+
678
+ export type AttachmentFileType = {
679
+ result: string;
680
+ file: File | null;
681
+ type: MessageAttachmentFileTypes;
682
+ localFileURL?: string;
683
+ };
684
+
685
+ export type AttachmentLinkType = {
686
+ link: {
687
+ url: string;
688
+ type: MessageAttachmentFileTypes;
689
+ name: string;
690
+ mimetype?: string;
691
+ };
692
+ };
693
+
694
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
695
+
696
+ /* -------------------------------- BROADCAST ------------------------------- */
697
+
698
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
699
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
700
+ } & {
701
+ chats: ChatType[];
702
+ };
703
+
704
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
705
+
706
+ export type ChatLogType = {
707
+ log: Tables<'view_chat_logs'>;
708
+ operations: Tables<'tbl_chat_logs'>[];
709
+ };
710
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
711
+
712
+ export type ChatParticipantOperationPayload = {
713
+ participant_ids: string[];
714
+ chat_ids: string[];
715
+ performed_by: string;
716
+ };
717
+
718
+ export type ChatOperationReturn = {
719
+ [participant_id: string]: {
720
+ is_success: boolean;
721
+ message?: string;
722
+ code?: number;
723
+ isInviteV4Sent?: boolean;
724
+ };
725
+ };
726
+
727
+ /* ----------------------- BILLING - STRIPE ----------------------- */
728
+
729
+ export type StripeSubscription = _Stripe.Subscription;
730
+ export type StripeCustomer = _Stripe.Customer;
731
+ export type StripeCoupon = _Stripe.Coupon;
732
+ export type StripePrice = _Stripe.Price;
733
+ export type Stripe = _Stripe;
734
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
735
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
736
+
737
+ /* -------------------------------- REALTIME -------------------------------- */
738
+
739
+ export type PhoneStateType = {
740
+ loading: boolean;
741
+ state: string;
742
+ sync: number;
743
+ percent: number | null;
744
+ message?: string;
745
+ error?: string;
746
+ };
747
+
748
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
749
+
750
+ export type ChatInfoType = Merge<
751
+ ChatType,
752
+ {
753
+ members: {
754
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
755
+ } | null;
756
+ chat_labels: string | null;
757
+ custom_properties: { [key: string]: string } | null;
758
+ }
759
+ >;
760
+
761
+ export type TicketInfoType = {
762
+ chat: ChatInfoType;
763
+ message: {
764
+ body: string;
765
+ chat_id: string;
766
+ org_phone: string;
767
+ timestamp: string;
768
+ media_path: string;
769
+ message_id: string;
770
+ sender_name: string;
771
+ performed_by: string;
772
+ sender_phone: string;
773
+ };
774
+ ticket: {
775
+ org_id: string;
776
+ status: string;
777
+ subject: string;
778
+ assignee: string;
779
+ due_date: string;
780
+ priority: 0 | 1 | 2 | 3 | 4;
781
+ raised_by: string;
782
+ ticket_id: string;
783
+ created_at: string;
784
+ assigned_by: string;
785
+ ticket_labels: string;
786
+ quoted_message_id: string;
787
+ ticket_custom_properties: { [key: string]: string } | null;
788
+ };
789
+ attached_messages: {
790
+ body: string;
791
+ chat_id: string;
792
+ org_phone: string;
793
+ timestamp: string;
794
+ media_path: string;
795
+ message_id: string;
796
+ sender_name: string;
797
+ performed_by: string;
798
+ sender_phone: string;
799
+ }[];
800
+ };
801
+
802
+ export type IntegrationLogObjectType =
803
+ | 'chat'
804
+ | 'message'
805
+ | 'reaction'
806
+ | 'ticket'
807
+ | 'phone';
808
+ export enum IntegrationLogType {
809
+ NEW_CHAT = 'chat.created',
810
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
811
+ NEW_MESSAGE = 'message.created',
812
+ MESSAGE_UPDATED = 'message.updated',
813
+ MESSAGE_DELETED = 'message.deleted',
814
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
815
+ REACTION_CREATED = 'reaction.created',
816
+ REACTION_UPDATED = 'reaction.updated',
817
+ NEW_TICKET = 'ticket.created',
818
+ TICKET_UPDATED = 'ticket.updated',
819
+ TICKET_DELETED = 'ticket.deleted',
820
+ MESSAGE_FLAGGED = 'message.flagged',
821
+ MESSAGE_UNFLAGGED = 'message.unflagged',
822
+ PHONE_DISCONNECTED = 'org.phone.disconnected',
823
+ PHONE_CONNECTED = 'org.phone.connected',
824
+ PHONE_UPDATED = 'org.phone.updated',
825
+ PHONE_QR_UPDATED = 'org.phone.qr',
826
+ }
827
+
828
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
829
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
830
+ ? TicketInfoType
831
+ : T extends IntegrationLogType.NEW_CHAT
832
+ ? Tables<'tbl_chats'>
833
+ : T extends
834
+ | IntegrationLogType.NEW_MESSAGE
835
+ | IntegrationLogType.MESSAGE_UPDATED
836
+ | IntegrationLogType.MESSAGE_DELETED
837
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
838
+ | IntegrationLogType.MESSAGE_FLAGGED
839
+ | IntegrationLogType.MESSAGE_UNFLAGGED
840
+ ? Tables<'tbl_chat_messages'>
841
+ : T extends
842
+ | IntegrationLogType.REACTION_CREATED
843
+ | IntegrationLogType.REACTION_UPDATED
844
+ ? Tables<'tbl_chat_reactions'>
845
+ : T extends
846
+ | IntegrationLogType.PHONE_DISCONNECTED
847
+ | IntegrationLogType.PHONE_CONNECTED
848
+ | IntegrationLogType.PHONE_UPDATED
849
+ | IntegrationLogType.PHONE_QR_UPDATED
850
+ ? Tables<'tbl_org_phones'>
851
+ : {
852
+ [key: string]: unknown;
853
+ };
854
+
855
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
856
+ OverrideProperties<
857
+ Tables<'tbl_integration_logs'>,
858
+ {
859
+ integration_name: T;
860
+ metadata: {
861
+ event: IntegrationLogMetadataType<T> & {
862
+ event_type: string;
863
+ org_id: string;
864
+ previous_attributes: {
865
+ [key: string]: unknown;
866
+ };
867
+ };
868
+ hook_id: string;
869
+ name: string;
870
+ };
871
+ }
872
+ >;
873
+
874
+ export type APIAuthDetails = {
875
+ org_details: Tables<'view_org'> | null;
876
+ phone_details: Tables<'tbl_org_phones'> | null;
877
+ token_details: Tables<'tbl_integration_tokens'> | null;
878
+ };
879
+
880
+ export type WebhookDataType = OverrideProperties<
881
+ Tables<'tbl_integration_hooks'>,
882
+ {
883
+ integration_name: string[];
884
+ }
885
+ >;
886
+
887
+ export type HubspotObjectDataType = {
888
+ createdAt: string;
889
+ archived: boolean;
890
+ id: string;
891
+ type: 'contacts' | 'tickets' | 'companies';
892
+ properties: Record<
893
+ string,
894
+ {
895
+ groupLabel: string;
896
+ groupName: string;
897
+ propertyKeyName: string;
898
+ propertyKey: string;
899
+ propertyInternalValue: string;
900
+ propertyValue: string;
901
+ propertyType: string;
902
+ propertyFieldType: string;
903
+ }[]
904
+ >;
905
+ };
906
+
907
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
908
+
909
+ export type UserPreferences = {
910
+ theme: 'light' | 'dark';
911
+ language: 'en' | 'es';
912
+ left_sidebar_open: boolean;
913
+ right_sidepanel_open: boolean;
914
+ sync_wa_unread_count: boolean;
915
+ pinned_chats: string[];
916
+ archived_chats: string[];
917
+ closed_chats: Record<string, number>;
918
+ periskope_chat_limit: number;
919
+ notifications: Record<string, boolean>;
920
+ };
921
+
922
+ /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
923
+
924
+ export interface MostActiveMember {
925
+ sender_phone: string;
926
+ total_messages: number;
927
+ }
928
+
929
+ export interface GroupAnalyticsResult {
930
+ total_messages: number;
931
+ total_joins: number;
932
+ total_leaves: number;
933
+ total_removes: number;
934
+ total_reactions: number;
935
+ most_active_members: MostActiveMember[];
936
+ }
937
+
938
+ export interface TimeRange {
939
+ startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
940
+ endDateTime: string;
941
+ }
942
+
943
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
944
+
945
+ export type PollSendType = {
946
+ pollName: string;
947
+ pollOptions: string[];
948
+ options?: {
949
+ allowMultipleAnswers?: boolean;
950
+ messageSecret?: number[] | null;
951
+ pollId?: string;
952
+ };
953
+ };
954
+
955
+ export type PollResultType = {
956
+ [name: string]: Record<string, string>;
957
+ };
958
+
959
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
960
+
961
+ export type CreateGroupOptions = {
962
+ messagesAdminsOnly?: boolean;
963
+ infoAdminsOnly?: boolean;
964
+ addMembersAdminsOnly?: boolean;
965
+ image?: string;
966
+ name?: string;
967
+ description?: string;
968
+ initiated_by?: string;
969
+ admins?: string[];
970
+ };
971
+
972
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
973
+
974
+ export type DeliveryInfoType = {
975
+ delivered: Record<string, number | undefined>;
976
+ read: Record<string, number | undefined>;
977
+ pending: string[];
978
+ read_count: number;
979
+ delivered_count: number;
980
+ };
981
+
982
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
983
+
984
+ export type OrgCreditsType = {
985
+ org_id: string;
986
+ recurring_allowance: number; // recurring credits replenished every cycle
987
+ recurring_balance: number; // recurring credits remaining in current cycle
988
+ topup_balance: number; // topup credits remaining
989
+ total_credits_used: number; // total credits used in current cycle
990
+ next_renewal_date: string;
991
+ topup_credits_used: number; // topup credits used in current cycle
992
+ recurring_credits_used: number; // recurring credits used in current cycle
993
+ };
994
+
995
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
996
+
997
+ export type ChatRuleInfoType = Merge<
998
+ Pick<
999
+ Tables<'view_chats'>,
1000
+ | 'assigned_to'
1001
+ | 'chat_id'
1002
+ | 'chat_name'
1003
+ | 'chat_type'
1004
+ | 'created_at'
1005
+ | 'group_description'
1006
+ | 'info_admins_only'
1007
+ | 'org_id'
1008
+ | 'org_phone'
1009
+ | 'chat_org_phones'
1010
+ | 'messages_admins_only'
1011
+ | 'custom_properties'
1012
+ | 'initiated_by'
1013
+ >,
1014
+ {
1015
+ has_flagged_messages: boolean;
1016
+ labels: string[];
1017
+ members: string[];
1018
+ custom_properties: { [key: string]: string } | null;
1019
+ }
1020
+ >;
1021
+
1022
+ export type SenderRuleInfoType = Merge<
1023
+ Omit<
1024
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1025
+ | 'verified_name'
1026
+ | 'verified_level'
1027
+ | 'updated_at'
1028
+ | 'short_name'
1029
+ | 'pushname'
1030
+ | 'periskope_name'
1031
+ | 'org_phone'
1032
+ | 'number'
1033
+ | 'name'
1034
+ | 'label_ids'
1035
+ | 'is_wa_contact'
1036
+ | 'is_user'
1037
+ | 'is_my_contact'
1038
+ | 'is_me'
1039
+ | 'is_imported'
1040
+ | 'is_group'
1041
+ | 'is_blocked'
1042
+ | 'contact_color'
1043
+ | 'business_profile'
1044
+ | 'id'
1045
+ | 'contact_image'
1046
+ | 'contact_type'
1047
+ | 'chat_id'
1048
+ | 'is_business'
1049
+ | 'is_enterprise'
1050
+ | 'is_super_admin'
1051
+ >,
1052
+ {
1053
+ is_internal: boolean;
1054
+ labels: string[] | null;
1055
+ }
1056
+ >;
1057
+
1058
+ export type MessageRuleInfoType = {
1059
+ chat: ChatRuleInfoType;
1060
+ sender: SenderRuleInfoType;
1061
+ message: OverrideProperties<
1062
+ Omit<
1063
+ Tables<'tbl_chat_messages'>,
1064
+ | 'vcards'
1065
+ | 'updated_at'
1066
+ | 'unique_id'
1067
+ | 'token'
1068
+ | 'to'
1069
+ | 'sent_message_id'
1070
+ | 'raw_data'
1071
+ | 'delivery_info'
1072
+ | 'poll_results'
1073
+ | 'poll_info'
1074
+ | 'order_id'
1075
+ | 'mentioned_ids'
1076
+ | 'media_key'
1077
+ | 'location'
1078
+ | 'links'
1079
+ | 'is_status'
1080
+ | 'is_starred'
1081
+ | 'is_gif'
1082
+ | 'is_forwarded'
1083
+ | 'is_ephemeral'
1084
+ | 'is_deleted'
1085
+ | 'fts'
1086
+ | 'quoted_message_id'
1087
+ | 'invite_v4'
1088
+ | 'id'
1089
+ | 'has_reaction'
1090
+ | 'has_media'
1091
+ | 'duration'
1092
+ | 'broadcast'
1093
+ | 'broadcast_id'
1094
+ | 'device_type'
1095
+ | 'forwarding_score'
1096
+ | 'from'
1097
+ | 'from_me'
1098
+ | 'prev_body'
1099
+ | 'flag_response_time'
1100
+ | 'flag_metadata'
1101
+ | 'ack'
1102
+ >,
1103
+ {
1104
+ media: MediaType | null;
1105
+ }
1106
+ >;
1107
+ };
1108
+
1109
+ export type ReactionRuleInfoType = {
1110
+ chat: ChatRuleInfoType;
1111
+ sender: SenderRuleInfoType;
1112
+ message: MessageRuleInfoType['message'];
1113
+ reaction: Pick<
1114
+ Tables<'tbl_chat_reactions'>,
1115
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1116
+ >;
1117
+ };
1118
+
1119
+ export type TicketRuleInfoType = {
1120
+ chat: ChatRuleInfoType;
1121
+ sender: SenderRuleInfoType;
1122
+ ticket: Merge<
1123
+ Pick<
1124
+ Tables<'tbl_chat_tickets'>,
1125
+ | 'org_id'
1126
+ | 'status'
1127
+ | 'chat_id'
1128
+ | 'subject'
1129
+ | 'assignee'
1130
+ | 'due_date'
1131
+ | 'priority'
1132
+ | 'raised_by'
1133
+ | 'ticket_id'
1134
+ | 'created_at'
1135
+ | 'is_deleted'
1136
+ >,
1137
+ {
1138
+ labels: string[] | null;
1139
+ custom_properties: { [key: string]: string } | null;
1140
+ }
1141
+ >;
1142
+ message: MessageRuleInfoType['message'];
1143
+ };
1144
+ export type FeatureFlagReturnType = Record<string, boolean>;
1145
+
1146
+ export type RuleLogsType = OverrideProperties<
1147
+ Tables<'tbl_rules_logs'>,
1148
+ {
1149
+ actions_progress: {
1150
+ action_id: string;
1151
+ action_type: Rule['actions'][number]['type'];
1152
+ action_delay: Rule['actions'][number]['delay'];
1153
+ ran_at: string | null;
1154
+ action_status: 'success' | 'failed' | 'pending';
1155
+ action_response: {
1156
+ success: boolean;
1157
+ data: Record<string, unknown> | null;
1158
+ error: {
1159
+ message: string;
1160
+ name: string;
1161
+ stack?: string;
1162
+ _error?: Error | Record<string, unknown>;
1163
+ } | null;
1164
+ };
1165
+ }[];
1166
+ metadata: {
1167
+ conditions: Rule['conditions'];
1168
+ actions: Rule['actions'];
1169
+ rule_metadata: Pick<
1170
+ Rule,
1171
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
1172
+ >;
1173
+ data: Record<string, unknown>;
1174
+ };
1175
+ conditions_progress: {
1176
+ is_valid: boolean;
1177
+ validation_progress: Record<
1178
+ string,
1179
+ {
1180
+ res: boolean;
1181
+ filter: Filter;
1182
+ value: unknown;
1183
+ }
1184
+ >;
1185
+ checked_at: string | null;
1186
+ };
1187
+ }
1188
+ >;
1189
+
1190
+ /************************** TASKS ***************************/
1191
+
1192
+ export type TaskType = OverrideProperties<
1193
+ Tables<'tbl_org_tasks'>,
1194
+ {
1195
+ reminder_setting: {
1196
+ remind_in:
1197
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1198
+ | string
1199
+ | null;
1200
+ repeat?: {
1201
+ frequency: number;
1202
+ interval: 'days' | 'weeks' | 'months' | 'years';
1203
+ end: 'never' | 'after' | 'on';
1204
+ on?: string;
1205
+ };
1206
+ } | null;
1207
+ associated_object_metadata:
1208
+ | {
1209
+ type: 'chat';
1210
+ index: 'chat_id';
1211
+ id: string;
1212
+ object: ChatType;
1213
+ }
1214
+ | {
1215
+ type: 'message';
1216
+ index: 'message_id';
1217
+ id: string;
1218
+ object: MessageType;
1219
+ }
1220
+ | {
1221
+ type: 'ticket';
1222
+ index: 'ticket_id';
1223
+ id: string;
1224
+ object: TicketType;
1225
+ }
1226
+ | null;
1227
+ status: 'open' | 'inprogress' | 'closed';
1228
+ priority: 1 | 2 | 3;
1229
+ completed_metadata?: {
1230
+ completed_at: string;
1231
+ completed_by: string;
1232
+ } | null;
1233
+ type: 'todo' | 'chat' | 'message' | 'ticket';
1234
+ }
1235
+ >;
1236
+
1237
+ type Choice = {
1238
+ id: number;
1239
+ label: string;
1240
+ value: string;
1241
+ position: number;
1242
+ };
1243
+
1244
+ export type FreshdeskCustomFieldType = {
1245
+ id: number;
1246
+ name: string;
1247
+ label: string;
1248
+ position: number;
1249
+ required_for_agents: boolean;
1250
+ archived: boolean;
1251
+ customers_can_edit: boolean;
1252
+ label_for_customers: string;
1253
+ required_for_customers: boolean;
1254
+ customers_can_filter: boolean;
1255
+ required_for_closure: boolean;
1256
+ displayed_to_customers: boolean;
1257
+ type: string;
1258
+ default: boolean;
1259
+ created_at: string;
1260
+ updated_at: string;
1261
+ choices?: Choice[];
1262
+ };