@periskope/types 0.6.387 → 0.6.389

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,1722 +1,1723 @@
1
- import {
2
- Coupon,
3
- Customer,
4
- Estimate,
5
- HostedPage,
6
- ItemPrice,
7
- Subscription,
8
- } from 'chargebee';
9
-
10
- import { Merge, OverrideProperties } from 'type-fest';
11
- import { Filter, Rule } from './rules.types';
12
- import { Tables, TablesInsert, TablesUpdate } from './supabase.types';
13
-
14
- /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
15
-
16
- /* ------------------------------ PERISKOPE TYPES ------------------------------ */
17
-
18
- export enum AllPlans {
19
- FREE_TRIAL = 'free-trial',
20
- // MONTHLY_STARTER = 'monthly-starter',
21
- // YEARLY_STARTER = 'yearly-starter',
22
- // MONTHLY_PRO = 'monthly-pro',
23
- // YEARLY_PRO = 'yearly-pro',
24
- ENTERPRISE = 'enterprise',
25
- MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
26
- YEARLY_STARTER_SINGLE = 'yearly-starter-single',
27
- MONTHLY_PRO_SINGLE = 'monthly-pro-single',
28
- YEARLY_PRO_SINGLE = 'yearly-pro-single',
29
- }
30
-
31
- export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
32
-
33
- export type Enterprise = `${string}-enterprise`;
34
-
35
- export type OrgPlanEnterprise = {
36
- subscription_id: string;
37
- plan_id: Enterprise;
38
- interval: number;
39
- frequency: Frequency;
40
- user_limit: number;
41
- phone_limit: number;
42
- current_period_start: number;
43
- current_period_end: number | null;
44
- additional_user_limit?: number;
45
- additional_phone_limit?: number;
46
- allocated_user_limit?: number;
47
- allocated_phone_limit?: number;
48
- currency: string;
49
- cancelled_at?: number;
50
- cancel_schedule_created_at?: number;
51
- subscription_status?: string;
52
- discount?: number;
53
- };
54
-
55
- export type OrgPlanNonEnterprise = {
56
- subscription_id: string;
57
- plan_id: AllPlans;
58
- interval: number;
59
- frequency: Frequency;
60
- user_limit: number;
61
- phone_limit: number;
62
- current_period_end: number;
63
- current_period_start: number;
64
- additional_user_limit?: number;
65
- additional_phone_limit?: number;
66
- allocated_user_limit?: number;
67
- allocated_phone_limit?: number;
68
- currency: string;
69
- cancelled_at?: number;
70
- cancel_schedule_created_at?: number;
71
- subscription_status?: string;
72
- discount?: number;
73
- };
74
-
75
- export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
76
- ? OrgPlanEnterprise
77
- : T extends AllPlans
78
- ? OrgPlanNonEnterprise
79
- : never;
80
-
81
- export type MicrosurveyData = {
82
- key: string;
83
- text: string;
84
- checked: boolean;
85
- }[];
86
-
87
- export type OrgPreferences = {
88
- disable_allow_exports?: boolean;
89
- disable_view_deleted_messages?: boolean;
90
- sync_phone_contacts?: boolean;
91
- mask_phone_numbers?: boolean;
92
- show_sender_names?: boolean;
93
- closed_chats?: Record<string, number>;
94
- auto_read_muted_chats?: boolean;
95
- member_permissions?: Record<string, boolean>;
96
- show_active_phone_only_messages_right?: boolean;
97
- };
98
-
99
- type OrgPreferenceKey = keyof OrgPreferences;
100
-
101
- export type OrgPreferencesValue = {
102
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
103
- }[OrgPreferenceKey];
104
-
105
- export type OrgAISettings = {
106
- is_ai_agent_enabled?: boolean;
107
- is_ai_flagging_enabled?: boolean;
108
- is_ai_agent_default_on?: boolean;
109
- ai_agent_activation_prompt?: string;
110
- ai_flag_prompt?: string;
111
- ai_nickname?: string;
112
- confidence_score?: string;
113
- company_overview?: string;
114
- ai_responder_roles?: string;
115
- human_agent_roles?: string;
116
- ticket_creation_rules?: string;
117
- private_note_creation_rules?: string;
118
- response_delay_value?: string;
119
- snooze_delay_value?: string;
120
- temperature?: string;
121
- top_p?: string;
122
- top_k?: string;
123
- ai_maintain_flag_status?: boolean;
124
- enable_shift_timing?: boolean;
125
- shift_start_time?: string;
126
- shift_end_time?: string;
127
- };
128
-
129
- type OrgAISettingsKey = keyof OrgAISettings;
130
-
131
- export type OrgAISettingsValue = {
132
- [K in OrgAISettingsKey]: { key: K; value: OrgAISettings[K] };
133
- }[OrgAISettingsKey];
134
-
135
- export type CustomPropertySectionType = {
136
- id: string;
137
- name: string;
138
- order: number;
139
- type: 'chat' | 'ticket';
140
- properties_order?: {
141
- [id: string]: number;
142
- };
143
- };
144
-
145
- export enum CustomPropertyValueType {
146
- DROPDOWN = 'dropdown',
147
- TEXT = 'text',
148
- DATE = 'date',
149
- FILE = 'file',
150
- PICKLIST = 'picklist',
151
- DEPENDENT_DROPDOWN = 'dependent_dropdown',
152
- }
153
-
154
- export type CustomPropertyMetadataType = {
155
- section_id?: string;
156
- };
157
-
158
- export type CustomPropertyTextPropertiesType = {
159
- property_value_type: CustomPropertyValueType.TEXT;
160
- property_value: null;
161
- property_metadata: CustomPropertyMetadataType;
162
- };
163
-
164
- export type CustomPropertyDropdownPropertiesType = {
165
- property_value_type: CustomPropertyValueType.DROPDOWN;
166
- property_value: {
167
- [key: string]: string;
168
- };
169
- property_metadata: CustomPropertyMetadataType;
170
- };
171
-
172
- export type CustomPropertyPicklistPropertiesType = {
173
- property_value_type: CustomPropertyValueType.PICKLIST;
174
- property_value: {
175
- [key: string]: string;
176
- };
177
- property_metadata: CustomPropertyMetadataType;
178
- };
179
-
180
- export type CustomPropertyDependentDropdownPropertiesType = {
181
- property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
182
- property_value: {
183
- level_1: {
184
- value: string;
185
- label: string;
186
- level_2: {
187
- value: string;
188
- label: string;
189
- level_3: {
190
- value: string;
191
- label: string;
192
- }[];
193
- }[];
194
- }[];
195
- };
196
- property_metadata: Merge<
197
- CustomPropertyMetadataType,
198
- {
199
- level_names: {
200
- level_1: string;
201
- level_2: string;
202
- level_3: string;
203
- };
204
- }
205
- >;
206
- };
207
-
208
- export type CustomPropertyFilePropertiesType = {
209
- property_value_type: CustomPropertyValueType.FILE;
210
- property_value: null;
211
- property_metadata: CustomPropertyMetadataType;
212
- };
213
-
214
- export type CustomPropertyDatePropertiesType = {
215
- property_value_type: CustomPropertyValueType.DATE;
216
- property_value: null;
217
- property_metadata: CustomPropertyMetadataType;
218
- };
219
-
220
- export type CustomPropertyType = OverrideProperties<
221
- Tables<'tbl_custom_properties'>,
222
- | CustomPropertyDependentDropdownPropertiesType
223
- | CustomPropertyTextPropertiesType
224
- | CustomPropertyDropdownPropertiesType
225
- | CustomPropertyPicklistPropertiesType
226
- | CustomPropertyFilePropertiesType
227
- | CustomPropertyDatePropertiesType
228
- >;
229
-
230
- export type OrgMetadata = {
231
- phone_number: string;
232
- ticket_prefix: string;
233
- referralSource?: string;
234
- contact_name?: string;
235
- surveyData?: MicrosurveyData;
236
- preferences?: OrgPreferences;
237
- partition?: boolean;
238
- tickets: {
239
- prefix?: string;
240
- emoji_ticketing: {
241
- is_enabled?: boolean;
242
- is_message_enabled?: boolean;
243
- message_template?: string;
244
- };
245
- disable_auto_attach_message_to_ticket?: boolean;
246
- };
247
- attribution?: Object;
248
- affiliate_id?: string;
249
- custom_properties?: {
250
- sections?: CustomPropertySectionType[];
251
- };
252
- rules?: {
253
- limit?: number;
254
- };
255
- display_language?: string;
256
- custom_invite?: {
257
- is_enabled: boolean;
258
- template: string;
259
- };
260
- };
261
-
262
- export type GroupTemplateType = OverrideProperties<
263
- Tables<'tbl_group_templates'>,
264
- {
265
- group_metadata: {
266
- messagesAdminsOnly?: boolean;
267
- infoAdminsOnly?: boolean;
268
- addMembersAdminsOnly?: boolean;
269
- description?: string;
270
- admins?: string[];
271
- };
272
- }
273
- >;
274
-
275
- type AccessScopes = {
276
- feature_flags: Record<string, boolean>;
277
- integrations: boolean;
278
- rules: boolean;
279
- exports: boolean;
280
- };
281
-
282
- export type OrgMembersType = OverrideProperties<
283
- Tables<'tbl_org_members'>,
284
- {
285
- member_metadata: {
286
- shift_times: {
287
- [day in
288
- | 'monday'
289
- | 'tuesday'
290
- | 'wednesday'
291
- | 'thursday'
292
- | 'friday'
293
- | 'saturday'
294
- | 'sunday']?: [[string, string]];
295
- };
296
- override_status: boolean;
297
- [key: string]: any;
298
- };
299
- }
300
- >;
301
-
302
- export type OrgType = OverrideProperties<
303
- Merge<
304
- Tables<'tbl_org'>,
305
- {
306
- user: OrgMembersType;
307
- members: OrgMembersType[];
308
- phones: Tables<'tbl_org_phones'>[];
309
- labels: Tables<'tbl_org_labels'>[];
310
- quick_replies: Tables<'tbl_quick_replies'>[];
311
- custom_properties: CustomPropertyType[];
312
- subscription_status: 'active' | 'inactive' | 'unpaid';
313
- is_enterprise: boolean;
314
- is_free_trial: boolean;
315
- is_hubspot_connected: boolean;
316
- is_freshdesk_connected: boolean;
317
- is_zohodesk_connected: boolean;
318
- is_zohocrm_connected: boolean;
319
- access_scopes: AccessScopes;
320
- rules: Rule[];
321
- phone_limit: number;
322
- user_limit: number;
323
- allocated_user_limit: number;
324
- allocated_phone_limit: number;
325
- additional_user_limit: number;
326
- additional_phone_limit: number;
327
- }
328
- >,
329
- {
330
- org_plan: OrgPlan<AllPlans | Enterprise>;
331
- stripe_customer_details: Customer | null;
332
- stripe_subscription_details: Array<Subscription> | null;
333
- stripe_customer_id: Customer['id'] | null;
334
- org_metadata: OrgMetadata;
335
- ai_settings: OrgAISettings;
336
- }
337
- >;
338
-
339
- export type ChatMemberType = Merge<
340
- Tables<'tbl_chat_participants'>,
341
- Tables<'tbl_contacts'>
342
- >;
343
-
344
- export type ChatType = Merge<
345
- Tables<'view_chats'>,
346
- {
347
- chat_id: string;
348
- latest_message: MessageType | null;
349
- latest_message_timestamp: number | null;
350
- latest_message_timestamp_map?: Record<string, number | null>;
351
- members: { [key: string]: ChatMemberType } | null;
352
- chat_type: 'user' | 'group' | 'business' | 'unknown';
353
- chat_access: { [key: string]: boolean };
354
- label_ids: { [key: string]: boolean };
355
- chat_org_phones?: string[];
356
- message_unread_count: number | null;
357
- hubspot_metadata: {
358
- id: string;
359
- type: string;
360
- hubId: string;
361
- object_data: HubspotObjectDataType;
362
- } | null;
363
- info_admins_only: boolean;
364
- messages_admins_only: boolean;
365
- unread_count?: { [key: string]: number };
366
- active_phone: string | null;
367
- flag_count_map?: { [key: string]: number };
368
- is_archived?: boolean;
369
- is_pinned?: boolean;
370
- closed_at?: number | null;
371
- common_chats?: string[];
372
- freshdesk_metadata?: Record<string, any>;
373
- zohodesk_metadata?: Record<string, any>;
374
- zohocrm_metadata?: Record<string,any>;
375
- pinned_messages?: {
376
- message_id: string;
377
- pinned_at: number;
378
- expires_at: number;
379
- }[];
380
- group_metadata?: Record<string, any>;
381
- snooze_metadata?: {
382
- snooze_until: number;
383
- snooze_message?: string;
384
- snooze_by?: string;
385
- };
386
- member_unread_count?: {
387
- [key: string]: number;
388
- };
389
- member_closed_at?: {
390
- [key: string]: number;
391
- };
392
- ai_metadata: ChatAIMetadataType;
393
- }
394
- >;
395
-
396
- export type ChatPropertiesType = Merge<Tables<'tbl_chat_properties'>, { ai_metadata: ChatAIMetadataType }>;
397
-
398
- export type ChatAIMetadataType = {
399
- is_active: boolean;
400
- snooze_until: string;
401
- activation_state: 'active' | 'inactive' | 'snoozed' | 'thinking';
402
- is_agent_allowed: boolean;
403
- is_flagging_allowed: boolean;
404
- } | null;
405
-
406
- /* -------------------------------------------------------------------------- */
407
- /* MESSAGE */
408
- /* -------------------------------------------------------------------------- */
409
-
410
- export type MediaType = {
411
- path?: string;
412
- mimetype?: string;
413
- filename?: string;
414
- dimensions?: { width: number; height: number; ar: number };
415
- size?: number;
416
- thumbnail?: string;
417
- filedata?: string;
418
- compress?: boolean;
419
- };
420
-
421
- export type MessageType = Merge<
422
- OverrideProperties<
423
- TablesInsert<'tbl_chat_messages'>,
424
- {
425
- message_id: string;
426
- org_id: string;
427
- org_phone: string;
428
- chat_id: string;
429
- message_type: (typeof SUPPORTED_TYPES)[number];
430
- media: MediaType | null;
431
- flag_metadata?: MessageFlagType | null;
432
- poll_info?: PollSendType | null;
433
- poll_results?: PollResultType | null;
434
- delivery_info?: DeliveryInfoType | null;
435
- raw_data?: {
436
- translations?: Record<string, string>;
437
- [key: string]: unknown;
438
- } | null;
439
- }
440
- >,
441
- {
442
- reactions?: ReactionType[];
443
- message_payload?: SingleMessagePayload;
444
- highlight?: number;
445
- is_private_note?: boolean;
446
- }
447
- >;
448
-
449
- export type MessageFlagType = {
450
- status: boolean;
451
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
452
- response_id?: string;
453
- response_timestamp?: string;
454
- response_email?: string;
455
- flagged_by?: string;
456
- flagged_at?: string;
457
- response_phone?: string;
458
- };
459
-
460
- export type MessageSendType = {
461
- queue_id: string;
462
- queue_position: string;
463
- };
464
-
465
- export type MessageBroadcastType = {
466
- broadcast_id: string;
467
- };
468
-
469
- /* -------------------------------------------------------------------------- */
470
-
471
- export type TicketType = OverrideProperties<
472
- Tables<'tbl_chat_tickets'>,
473
- {
474
- label_ids: { [key: string]: boolean };
475
- hubspot_metadata: {
476
- id?: string;
477
- type?: string;
478
- hubId?: string;
479
- pipeline: {
480
- id: string;
481
- label: string;
482
- };
483
- object_data?: HubspotObjectDataType;
484
- } | null;
485
- freshdesk_metadata: Record<string, string>;
486
- close_ticket_metadata?:
487
- | {
488
- closed_by: string;
489
- closed_at: string;
490
- closed_message?: string | null;
491
- send_reply_message_id?: string | null;
492
- }
493
- | any;
494
- }
495
- > & {
496
- chat?: ChatType;
497
- quoted_message?: MessageType;
498
- };
499
-
500
- export type ContactType = Merge<
501
- Tables<'tbl_contacts'>,
502
- {
503
- chats: ChatType[] | null;
504
- chat_ids?: string[];
505
- }
506
- >;
507
- export type ReactionType = Tables<'tbl_chat_reactions'>;
508
-
509
- export type NotificationType = Tables<'tbl_chat_notifications'>;
510
-
511
- export type ChatAccessType = Merge<
512
- TablesUpdate<'tbl_org_members'>,
513
- {
514
- has_access?: boolean;
515
- email: string | null;
516
- }
517
- >;
518
-
519
- export type QueueJobTypes = {
520
- addedTimestamp: number;
521
- attemptsMade: number;
522
- attemptsStarted: number;
523
- data: {
524
- body: string;
525
- chat_id: string;
526
- };
527
- finishedTimestamp: number;
528
- id: string;
529
- message_id: string;
530
- processedTimestamp: number;
531
- stacktrace: string[];
532
- status: string;
533
- };
534
-
535
- export type PhoneQueueStatusType = {
536
- active: number;
537
- failed: number;
538
- completed: number;
539
- is_running: boolean;
540
- pending: number;
541
- };
542
-
543
- export type PhoneType = OverrideProperties<
544
- Tables<'tbl_org_phones'>,
545
- {
546
- queue_status: {
547
- [key: string]: PhoneQueueStatusType;
548
- };
549
- }
550
- >;
551
-
552
- export type PhoneInfoType = Merge<
553
- Pick<
554
- PhoneType,
555
- | 'created_at'
556
- | 'first_connected_at'
557
- | 'is_ready'
558
- | 'label_ids'
559
- | 'org_id'
560
- | 'org_phone'
561
- | 'phone_id'
562
- | 'phone_image'
563
- | 'phone_name'
564
- | 'qr_code'
565
- | 'updated_at'
566
- | 'wa_state'
567
- >,
568
- {
569
- labels: string[];
570
- }
571
- >;
572
-
573
- /* -------------------------------- CONSTANTS ------------------------------- */
574
-
575
- export const labelColors = [
576
- '#9333EA',
577
- '#0D9488',
578
- '#DB2777',
579
- '#2563EB',
580
- '#F97316',
581
- ];
582
-
583
- export const enumChatColors = [
584
- '#B4876E',
585
- '#A5B337',
586
- '#06CF9C',
587
- '#25D366',
588
- '#02A698',
589
- '#7D9EF1',
590
- '#007BFC',
591
- '#5E47DE',
592
- '#7F66FF',
593
- '#9333EA',
594
- '#FA6533',
595
- '#C4532D',
596
- '#DC2626',
597
- '#FF2E74',
598
- '#DB2777',
599
- ] as const;
600
-
601
- export type RepeatDaysType =
602
- | 'monday'
603
- | 'tuesday'
604
- | 'wednesday'
605
- | 'thursday'
606
- | 'friday'
607
- | 'saturday'
608
- | 'sunday';
609
- export type RepeatIntervalType = 'day' | 'week' | 'month';
610
-
611
- export enum WhatsappGroupActionEnum {
612
- ADD = 'add',
613
- REMOVE = 'remove',
614
- PROMOTE = 'promote',
615
- DEMOTE = 'demote',
616
- INVITE = 'invite',
617
- LEAVE = 'leave',
618
- ANNOUNCE_TRUE = 'announce_true',
619
- ANNOUNCE_FALSE = 'announce_false',
620
- RESTRICT_TRUE = 'restrict_true',
621
- RESTRICT_FALSE = 'restrict_false',
622
- MEMBERADDMODE_TRUE = 'memberaddmode_true',
623
- MEMBERADDMODE_FALSE = 'memberaddmode_false',
624
- SUBJECT = 'subject',
625
- DESC = 'desc',
626
- CALL = 'call',
627
- }
628
-
629
- /* -------------------------- LISTING ENDPOINT -------------------------- */
630
-
631
- type ListingType = {
632
- from?: number;
633
- to?: number;
634
- count?: number;
635
- };
636
-
637
- export type ListNotificationsType = Merge<
638
- ListingType,
639
- {
640
- notifictions?: NotificationType[];
641
- }
642
- >;
643
-
644
- export type ListChatMessagesType = Merge<
645
- ListingType,
646
- {
647
- messages?: MessageType[];
648
- }
649
- >;
650
-
651
- export type ListContactsType = Merge<
652
- ListingType,
653
- {
654
- contacts?: ContactType[];
655
- }
656
- >;
657
-
658
- export type ListTicketsType = Merge<
659
- ListingType,
660
- {
661
- tickets?: TicketType[];
662
- }
663
- >;
664
-
665
- export type ListChatsType = Merge<
666
- ListingType,
667
- {
668
- chats?: ChatType[];
669
- }
670
- >;
671
-
672
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
673
-
674
- export const SUPPORTED_TYPES = [
675
- 'chat',
676
- 'sticker',
677
- 'image',
678
- 'video',
679
- 'document',
680
- 'vcard',
681
- 'multi_vcard',
682
- 'audio',
683
- 'ptt',
684
- 'poll_creation',
685
- 'location',
686
- 'ciphertext',
687
- ] as const;
688
-
689
- export type SendMessageContent = {
690
- message_type?: (typeof SUPPORTED_TYPES)[number];
691
- body?: string;
692
- media?: MediaType;
693
- contact_ids?: string[];
694
- location?: {
695
- latitude: string;
696
- longitude: string;
697
- options?: { name?: string; address?: string; url?: string };
698
- };
699
- poll?: PollSendType;
700
- quoted_message_id?: string;
701
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
702
- broadcast_id?: string;
703
- performed_by?: string;
704
- options?: Record<string, any>;
705
- };
706
-
707
- export type QuickReplyContent = Omit<
708
- SendMessageContent,
709
- 'broadcast_id' | 'variables'
710
- >;
711
-
712
- export type ScheduleMessagePayload = {
713
- scheduled_id?: string;
714
- is_repeat?: boolean | null;
715
- scheduled_at: string;
716
- repeat_config?: {
717
- timezone?: string;
718
- repeat_ends?: string;
719
- repeat_interval?: RepeatIntervalType;
720
- repeat_value?: number;
721
- repeat_days?: RepeatDaysType[];
722
- };
723
- };
724
-
725
- export type BroadcastVariableType = {
726
- chat_id: string;
727
- values: { [key: string]: string };
728
- };
729
-
730
- export type BroadcastMessagePayload = SendMessageContent & {
731
- chat_ids: string[];
732
- broadcast_id?: string;
733
- variables?: BroadcastVariableType[];
734
- delay?: number;
735
- };
736
-
737
- export type SingleMessagePayload = SendMessageContent & {
738
- chat_id: string;
739
- job_id?: string;
740
- priority?: number;
741
- scheduled_id?: string;
742
- };
743
-
744
- export type MessageAttachmentFileTypes =
745
- | 'image'
746
- | 'audio'
747
- | 'document'
748
- | 'video';
749
-
750
- export type AttachmentFileType = {
751
- result: string;
752
- file: File | null;
753
- type: MessageAttachmentFileTypes;
754
- localFileURL?: string;
755
- };
756
-
757
- export type AttachmentLinkType = {
758
- link: {
759
- url: string;
760
- type: MessageAttachmentFileTypes;
761
- name: string;
762
- mimetype?: string;
763
- };
764
- };
765
-
766
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
767
-
768
- /* -------------------------------- BROADCAST ------------------------------- */
769
-
770
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
771
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
772
- } & {
773
- chats: ChatType[];
774
- };
775
-
776
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
777
-
778
- export type ChatLogType = {
779
- log: Tables<'view_chat_logs'>;
780
- operations: Tables<'tbl_chat_logs'>[];
781
- };
782
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
783
-
784
- export type ChatParticipantOperationPayload = {
785
- participant_ids: string[];
786
- chat_ids: string[];
787
- performed_by: string;
788
- force_add_participants?: boolean;
789
- };
790
-
791
- export type ChatOperationReturn = {
792
- [participant_id: string]: {
793
- is_success: boolean;
794
- message?: string;
795
- code?: number;
796
- isInviteV4Sent?: boolean;
797
- };
798
- };
799
-
800
- /* ----------------------- BILLING - STRIPE ----------------------- */
801
-
802
- export type ChargebeeSubscription = Subscription;
803
- export type ChargebeeCustomer = Customer;
804
- export type ChargebeePrice = ItemPrice;
805
- export type ChargebeeUpcomingInvoice =
806
- Estimate.RenewalEstimateResponse['estimate'];
807
- export type ChargebeeLineItem =
808
- HostedPage.CheckoutNewForItemsInputParam['subscription_items'];
809
-
810
- /* -------------------------------- REALTIME -------------------------------- */
811
-
812
- export type PhoneStateType = {
813
- loading: boolean;
814
- state: string;
815
- sync: number;
816
- percent: number | null;
817
- message?: string;
818
- error?: string;
819
- };
820
-
821
- /* ------------------------------- INTEGRATIONS ----------------------------- */
822
-
823
- export type ChatInfoType = Merge<
824
- ChatType,
825
- {
826
- members: {
827
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
828
- } | null;
829
- chat_labels: string | null;
830
- custom_properties: { [key: string]: string } | null;
831
- }
832
- >;
833
-
834
- export type TicketInfoType = {
835
- chat: ChatInfoType;
836
- message: {
837
- body: string;
838
- chat_id: string;
839
- org_phone: string;
840
- timestamp: string;
841
- media_path: string;
842
- message_id: string;
843
- sender_name: string;
844
- performed_by: string;
845
- sender_phone: string;
846
- };
847
- ticket: {
848
- org_id: string;
849
- status: string;
850
- subject: string;
851
- assignee: string;
852
- due_date: string;
853
- priority: 0 | 1 | 2 | 3 | 4;
854
- raised_by: string;
855
- ticket_id: string;
856
- created_at: string;
857
- assigned_by: string;
858
- ticket_labels: string;
859
- quoted_message_id: string;
860
- ticket_custom_properties: { [key: string]: string } | null;
861
- closed_at: string;
862
- closed_by: string;
863
- closed_message: string;
864
- first_assigned_at: string | null;
865
- is_deleted: boolean;
866
- };
867
- attached_messages: {
868
- body: string;
869
- chat_id: string;
870
- org_phone: string;
871
- timestamp: string;
872
- media_path: string;
873
- message_id: string;
874
- sender_name: string;
875
- performed_by: string;
876
- sender_phone: string;
877
- }[];
878
- };
879
-
880
- export type IntegrationLogObjectType =
881
- | 'chat'
882
- | 'message'
883
- | 'reaction'
884
- | 'ticket'
885
- | 'phone';
886
- export enum IntegrationLogType {
887
- NEW_CHAT = 'chat.created',
888
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
889
- NEW_MESSAGE = 'message.created',
890
- MESSAGE_UPDATED = 'message.updated',
891
- MESSAGE_DELETED = 'message.deleted',
892
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
893
- MESSAGE_FLAGGED = 'message.flagged',
894
- MESSAGE_UNFLAGGED = 'message.unflagged',
895
- MESSAGE_TICKET_ATTACHED = 'message.ticket.attached',
896
- REACTION_CREATED = 'reaction.created',
897
- REACTION_UPDATED = 'reaction.updated',
898
- NEW_TICKET = 'ticket.created',
899
- TICKET_UPDATED = 'ticket.updated',
900
- TICKET_DELETED = 'ticket.deleted',
901
- PHONE_DISCONNECTED = 'org.phone.disconnected',
902
- PHONE_CONNECTED = 'org.phone.connected',
903
- PHONE_UPDATED = 'org.phone.updated',
904
- PHONE_QR_UPDATED = 'org.phone.qr',
905
- NOTE_CREATED = 'note.created',
906
- CHAT_CUSTOM_PROPERTIES_UPDATED = 'chat.custom_properties.updated',
907
- }
908
-
909
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
910
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
911
- ? TicketInfoType
912
- : T extends IntegrationLogType.NEW_CHAT
913
- ? Tables<'tbl_chats'>
914
- : T extends
915
- | IntegrationLogType.NEW_MESSAGE
916
- | IntegrationLogType.MESSAGE_UPDATED
917
- | IntegrationLogType.MESSAGE_DELETED
918
- | IntegrationLogType.MESSAGE_ACK_UPDATED
919
- | IntegrationLogType.MESSAGE_FLAGGED
920
- | IntegrationLogType.MESSAGE_UNFLAGGED
921
- | IntegrationLogType.MESSAGE_TICKET_ATTACHED
922
- ? Tables<'tbl_chat_messages'>
923
- : T extends
924
- | IntegrationLogType.REACTION_CREATED
925
- | IntegrationLogType.REACTION_UPDATED
926
- ? Tables<'tbl_chat_reactions'>
927
- : T extends
928
- | IntegrationLogType.PHONE_DISCONNECTED
929
- | IntegrationLogType.PHONE_CONNECTED
930
- | IntegrationLogType.PHONE_UPDATED
931
- | IntegrationLogType.PHONE_QR_UPDATED
932
- ? Tables<'tbl_org_phones'>
933
- : T extends IntegrationLogType.NOTE_CREATED
934
- ? Tables<'tbl_chat_notes'>
935
- : {
936
- [key: string]: unknown;
937
- };
938
-
939
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
940
- OverrideProperties<
941
- Tables<'tbl_integration_logs'>,
942
- {
943
- integration_name: T;
944
- metadata: {
945
- event: IntegrationLogMetadataType<T> & {
946
- event_type: string;
947
- org_id: string;
948
- previous_attributes: {
949
- [key: string]: unknown;
950
- };
951
- };
952
- hook_id: string;
953
- name: string;
954
- };
955
- }
956
- >;
957
-
958
- export type APIAuthDetails = {
959
- org_details: Tables<'view_org'> | null;
960
- phone_details: Tables<'tbl_org_phones'> | null;
961
- token_details: Tables<'tbl_integration_tokens'> | null;
962
- };
963
-
964
- export type WebhookDataType = OverrideProperties<
965
- Tables<'tbl_integration_hooks'>,
966
- {
967
- integration_name: string[];
968
- }
969
- >;
970
-
971
- export type HubspotObjectDataType = {
972
- createdAt: string;
973
- archived: boolean;
974
- id: string;
975
- type: 'contacts' | 'tickets' | 'companies';
976
- properties: Record<
977
- string,
978
- {
979
- groupLabel: string;
980
- groupName: string;
981
- propertyKeyName: string;
982
- propertyKey: string;
983
- propertyInternalValue: string;
984
- propertyValue: string;
985
- propertyType: string;
986
- propertyFieldType: string;
987
- }[]
988
- >;
989
- };
990
-
991
- /* ---------------------------- USER PREFERENCES ---------------------------- */
992
-
993
- export type UserPreferences = {
994
- theme: 'light' | 'dark';
995
- language: 'en' | 'es';
996
- left_sidebar_open: boolean;
997
- right_sidepanel_open: boolean;
998
- sync_wa_unread_count: boolean;
999
- pinned_chats: string[];
1000
- periskope_chat_limit: number;
1001
- notifications: Record<string, boolean>;
1002
- };
1003
-
1004
- /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
1005
-
1006
- export interface MostActiveMember {
1007
- sender_phone: string;
1008
- total_messages: number;
1009
- }
1010
-
1011
- export interface GroupAnalyticsResult {
1012
- total_messages: number;
1013
- total_joins: number;
1014
- total_leaves: number;
1015
- total_removes: number;
1016
- total_reactions: number;
1017
- most_active_members: MostActiveMember[];
1018
- }
1019
-
1020
- export interface TimeRange {
1021
- startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
1022
- endDateTime: string;
1023
- }
1024
-
1025
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
1026
-
1027
- export type PollSendType = {
1028
- pollName: string;
1029
- pollOptions: string[];
1030
- options?: {
1031
- allowMultipleAnswers?: boolean;
1032
- messageSecret?: number[] | null;
1033
- pollId?: string;
1034
- };
1035
- };
1036
-
1037
- export type PollResultType = {
1038
- [name: string]: Record<string, string>;
1039
- };
1040
-
1041
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
1042
-
1043
- export type CreateGroupOptions = {
1044
- messagesAdminsOnly?: boolean;
1045
- infoAdminsOnly?: boolean;
1046
- addMembersAdminsOnly?: boolean;
1047
- image?: string;
1048
- name?: string;
1049
- description?: string;
1050
- initiated_by?: string;
1051
- admins?: string[];
1052
- force_add_participants?: boolean;
1053
- };
1054
-
1055
- /* ------------------------------ DELIVERY INFO ----------------------------- */
1056
-
1057
- export type DeliveryInfoType = {
1058
- delivered: Record<string, number | undefined>;
1059
- read: Record<string, number | undefined>;
1060
- pending: string[];
1061
- read_count: number;
1062
- delivered_count: number;
1063
- };
1064
-
1065
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1066
-
1067
- export type OrgCreditsType = {
1068
- org_id: string;
1069
- recurring_allowance: number; // recurring credits replenished every cycle
1070
- recurring_balance: number; // recurring credits remaining in current cycle
1071
- topup_balance: number; // topup credits remaining
1072
- total_credits_used: number; // total credits used in current cycle
1073
- next_renewal_date: string;
1074
- topup_credits_used: number; // topup credits used in current cycle
1075
- recurring_credits_used: number; // recurring credits used in current cycle
1076
- };
1077
-
1078
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
1079
-
1080
- export type ChatRuleInfoType = {
1081
- chat: Merge<
1082
- Pick<
1083
- Tables<'view_chats'>,
1084
- | 'assigned_to'
1085
- | 'chat_id'
1086
- | 'chat_name'
1087
- | 'chat_type'
1088
- | 'created_at'
1089
- | 'group_description'
1090
- | 'info_admins_only'
1091
- | 'org_id'
1092
- | 'org_phone'
1093
- | 'chat_org_phones'
1094
- | 'messages_admins_only'
1095
- | 'custom_properties'
1096
- | 'initiated_by'
1097
- >,
1098
- {
1099
- has_flagged_messages: boolean;
1100
- labels: string[];
1101
- members: string[];
1102
- custom_properties: { [key: string]: string } | null;
1103
- assignee_name: string | null;
1104
- }
1105
- >;
1106
- };
1107
-
1108
- export type SenderRuleInfoType = Merge<
1109
- Omit<
1110
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1111
- | 'verified_name'
1112
- | 'verified_level'
1113
- | 'updated_at'
1114
- | 'short_name'
1115
- | 'pushname'
1116
- | 'periskope_name'
1117
- | 'org_phone'
1118
- | 'number'
1119
- | 'name'
1120
- | 'label_ids'
1121
- | 'is_wa_contact'
1122
- | 'is_user'
1123
- | 'is_my_contact'
1124
- | 'is_me'
1125
- | 'is_imported'
1126
- | 'is_group'
1127
- | 'is_blocked'
1128
- | 'contact_color'
1129
- | 'business_profile'
1130
- | 'id'
1131
- | 'contact_image'
1132
- | 'contact_type'
1133
- | 'chat_id'
1134
- | 'is_business'
1135
- | 'is_enterprise'
1136
- | 'is_super_admin'
1137
- | 'contact_lid'
1138
- >,
1139
- {
1140
- is_internal: boolean;
1141
- labels: string[] | null;
1142
- }
1143
- >;
1144
-
1145
- export type MessageRuleInfoType = {
1146
- chat: ChatRuleInfoType['chat'];
1147
- sender: SenderRuleInfoType;
1148
- message: OverrideProperties<
1149
- Omit<
1150
- Tables<'tbl_chat_messages'>,
1151
- | 'vcards'
1152
- | 'updated_at'
1153
- | 'unique_id'
1154
- | 'token'
1155
- | 'to'
1156
- | 'sent_message_id'
1157
- | 'raw_data'
1158
- | 'delivery_info'
1159
- | 'poll_results'
1160
- | 'poll_info'
1161
- | 'order_id'
1162
- | 'mentioned_ids'
1163
- | 'media_key'
1164
- | 'location'
1165
- | 'links'
1166
- | 'is_status'
1167
- | 'is_starred'
1168
- | 'is_gif'
1169
- | 'is_forwarded'
1170
- | 'is_ephemeral'
1171
- | 'is_deleted'
1172
- | 'fts'
1173
- | 'quoted_message_id'
1174
- | 'invite_v4'
1175
- | 'id'
1176
- | 'has_reaction'
1177
- | 'has_media'
1178
- | 'duration'
1179
- | 'broadcast'
1180
- | 'broadcast_id'
1181
- | 'device_type'
1182
- | 'forwarding_score'
1183
- | 'from'
1184
- | 'from_me'
1185
- | 'prev_body'
1186
- | 'flag_response_time'
1187
- | 'flag_metadata'
1188
- | 'ack'
1189
- >,
1190
- {
1191
- media: MediaType | null;
1192
- }
1193
- >;
1194
- };
1195
-
1196
- export type ReactionRuleInfoType = {
1197
- chat: MessageRuleInfoType['chat'];
1198
- sender: MessageRuleInfoType['sender'];
1199
- message: MessageRuleInfoType['message'];
1200
- reaction: Pick<
1201
- Tables<'tbl_chat_reactions'>,
1202
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1203
- >;
1204
- };
1205
-
1206
- export type TicketRuleInfoType = {
1207
- chat: MessageRuleInfoType['chat'];
1208
- sender: MessageRuleInfoType['sender'];
1209
- ticket: Merge<
1210
- Pick<
1211
- Tables<'tbl_chat_tickets'>,
1212
- | 'org_id'
1213
- | 'status'
1214
- | 'chat_id'
1215
- | 'subject'
1216
- | 'assignee'
1217
- | 'due_date'
1218
- | 'priority'
1219
- | 'raised_by'
1220
- | 'ticket_id'
1221
- | 'created_at'
1222
- | 'is_deleted'
1223
- >,
1224
- {
1225
- labels: string[] | null;
1226
- custom_properties: { [key: string]: string } | null;
1227
- }
1228
- >;
1229
- message: MessageRuleInfoType['message'];
1230
- };
1231
-
1232
- export type TaskRuleInfoType<
1233
- T extends 'ticket' | 'chat' | 'message' | 'todo' = 'todo',
1234
- > = {
1235
- associated_object_data: T extends 'message'
1236
- ? MessageRuleInfoType
1237
- : T extends 'ticket'
1238
- ? TicketRuleInfoType
1239
- : T extends 'chat'
1240
- ? ChatRuleInfoType
1241
- : null;
1242
- task: Pick<
1243
- TaskType,
1244
- | 'org_id'
1245
- | 'title'
1246
- | 'notes'
1247
- | 'status'
1248
- | 'assignee'
1249
- | 'due_date'
1250
- | 'priority'
1251
- | 'task_id'
1252
- | 'created_at'
1253
- >;
1254
- };
1255
-
1256
- export type FeatureFlagReturnType = Record<string, boolean>;
1257
-
1258
- export type RuleLogsType = OverrideProperties<
1259
- Tables<'tbl_rules_logs'>,
1260
- {
1261
- actions_progress: {
1262
- action_id: string;
1263
- action_type: Rule['actions'][number]['type'];
1264
- action_delay: Rule['actions'][number]['delay'];
1265
- ran_at: string | null;
1266
- action_status: 'success' | 'failed' | 'pending';
1267
- action_response: {
1268
- success: boolean;
1269
- data: Record<string, unknown> | null;
1270
- error: {
1271
- message: string;
1272
- name: string;
1273
- stack?: string;
1274
- _error?: Error | Record<string, unknown>;
1275
- } | null;
1276
- };
1277
- }[];
1278
- metadata: {
1279
- conditions: Rule['conditions'];
1280
- actions: Rule['actions'];
1281
- rule_metadata: Pick<
1282
- Rule,
1283
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1284
- >;
1285
- data: Record<string, unknown>;
1286
- };
1287
- conditions_progress: {
1288
- is_valid: boolean;
1289
- validation_progress: Record<
1290
- string,
1291
- {
1292
- res: boolean;
1293
- filter: Filter;
1294
- value: unknown;
1295
- }
1296
- >;
1297
- checked_at: string | null;
1298
- };
1299
- }
1300
- >;
1301
-
1302
- /************************** TASKS ***************************/
1303
-
1304
- export type ChatMetadataType = {
1305
- type: 'chat';
1306
- index: 'chat_id';
1307
- id: string;
1308
- object: Pick<ChatType, 'chat_id' | 'org_phone' | 'org_id'>;
1309
- };
1310
-
1311
- export type MessageMetadataType = {
1312
- type: 'message';
1313
- index: 'message_id';
1314
- id: string;
1315
- object: Pick<
1316
- MessageType,
1317
- | 'message_id'
1318
- | 'org_phone'
1319
- | 'chat_id'
1320
- | 'sender_phone'
1321
- | 'org_id'
1322
- | 'is_private_note'
1323
- >;
1324
- };
1325
-
1326
- export type TicketMetadataType = {
1327
- type: 'ticket';
1328
- index: 'ticket_id';
1329
- id: string;
1330
- object: Pick<
1331
- TicketType,
1332
- 'ticket_id' | 'quoted_message_id' | 'chat_id' | 'org_id'
1333
- >;
1334
- };
1335
-
1336
- export type AssociatedObjectMetadataType<
1337
- T extends 'chat' | 'message' | 'ticket' | 'todo' =
1338
- | 'chat'
1339
- | 'message'
1340
- | 'ticket'
1341
- | 'todo',
1342
- > = T extends 'chat'
1343
- ? ChatMetadataType
1344
- : T extends 'message'
1345
- ? MessageMetadataType
1346
- : T extends 'ticket'
1347
- ? TicketMetadataType
1348
- : null;
1349
-
1350
- export const isChatTask = (task: TaskType): task is TaskType<'chat'> =>
1351
- task.associated_object_metadata?.type === 'chat';
1352
-
1353
- export const isMessageTask = (task: TaskType): task is TaskType<'message'> =>
1354
- task.associated_object_metadata?.type === 'message';
1355
-
1356
- export const isTicketTask = (task: TaskType): task is TaskType<'ticket'> =>
1357
- task.associated_object_metadata?.type === 'ticket';
1358
-
1359
- export const isTodoTask = (task: TaskType): task is TaskType<'todo'> =>
1360
- task.type === 'todo';
1361
-
1362
- export type TaskType<
1363
- T extends 'chat' | 'message' | 'ticket' | 'todo' =
1364
- | 'chat'
1365
- | 'message'
1366
- | 'ticket'
1367
- | 'todo',
1368
- > = OverrideProperties<
1369
- Tables<'tbl_org_tasks'>,
1370
- {
1371
- reminder_setting: {
1372
- remind_in:
1373
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1374
- | string
1375
- | null;
1376
- repeat?: {
1377
- frequency: number;
1378
- interval: 'days' | 'weeks' | 'months' | 'years';
1379
- end: 'never' | 'after' | 'on';
1380
- on?: string;
1381
- };
1382
- } | null;
1383
- associated_object_metadata: AssociatedObjectMetadataType<T>;
1384
- status: 'open' | 'inprogress' | 'closed';
1385
- priority: 1 | 2 | 3;
1386
- completed_metadata?: {
1387
- completed_at: string;
1388
- completed_by: string;
1389
- } | null;
1390
- type: T;
1391
- }
1392
- >;
1393
-
1394
- type Choice = {
1395
- id: number;
1396
- label: string;
1397
- value: string;
1398
- position: number;
1399
- };
1400
-
1401
- export type FreshdeskFieldType = {
1402
- id: number;
1403
- name: string;
1404
- type: string;
1405
- label: string;
1406
- default: boolean;
1407
- archived: boolean;
1408
- position: number;
1409
- created_at: string;
1410
- updated_at: string;
1411
- customers_can_edit: boolean;
1412
- label_for_customers: string;
1413
- required_for_agents: boolean;
1414
- customers_can_filter: boolean;
1415
- required_for_closure: boolean;
1416
- displayed_to_customers: boolean;
1417
- required_for_customers: boolean;
1418
- choices?: Choice[];
1419
- };
1420
-
1421
- export type OrgWarmup = OverrideProperties<
1422
- Tables<{ schema: 'internal' }, 'tbl_org_warmup'>,
1423
- {
1424
- warmup_chats: { [key: string]: string };
1425
- }
1426
- >;
1427
-
1428
- /** ----------------------------- INTEGRATION TOKENS TYPES ----------------------------- **/
1429
-
1430
- export type FreshdeskIntegrationTokenType = OverrideProperties<
1431
- Tables<'tbl_integration_tokens'>,
1432
- {
1433
- type: 'freshdesk';
1434
- token_metadata: {
1435
- url: string;
1436
- apiKey: string;
1437
- fields: {
1438
- ticket: FreshdeskFieldType[];
1439
- company: FreshdeskFieldType[];
1440
- contact: FreshdeskFieldType[];
1441
- };
1442
- automation: {
1443
- id: number | string;
1444
- meta: {
1445
- total_count: number;
1446
- total_active_count: 17;
1447
- };
1448
- name: string;
1449
- active: boolean;
1450
- events: Array<{
1451
- to?: string;
1452
- from?: string;
1453
- field_name: string;
1454
- value?: string;
1455
- }>;
1456
- actions: Array<{
1457
- url: string;
1458
- content: Record<string, string>;
1459
- field_name: string;
1460
- content_type: string;
1461
- request_type: string;
1462
- content_layout: string;
1463
- }>;
1464
- summary: {
1465
- events: Array<string>;
1466
- actions: Array<string>;
1467
- performer: string;
1468
- conditions: {
1469
- [key: string]: Array<string>;
1470
- };
1471
- };
1472
- outdated: boolean;
1473
- position: number;
1474
- performer: {
1475
- type: string;
1476
- };
1477
- conditions: Array<{
1478
- name: string;
1479
- match_type: string;
1480
- properties: Array<{
1481
- value: Array<string>;
1482
- operator: string;
1483
- field_name: string;
1484
- resource_type: string;
1485
- case_sensitive: boolean;
1486
- }>;
1487
- }>;
1488
- created_at: string;
1489
- updated_at: string;
1490
- description: string | null;
1491
- last_updated_by: string | number;
1492
- affected_tickets_count: number | null;
1493
- };
1494
- org_details: {
1495
- address: {
1496
- city: string;
1497
- state: string;
1498
- street: string;
1499
- country: string;
1500
- postalcode: string;
1501
- };
1502
- timezone: string;
1503
- bundle_id: string;
1504
- tier_type: string;
1505
- account_id: number;
1506
- cloud_type: string;
1507
- data_center: string;
1508
- account_name: string;
1509
- total_agents: {
1510
- full_time: number;
1511
- occasional: number;
1512
- collaborators: number;
1513
- field_service: number;
1514
- };
1515
- account_domain: string;
1516
- contact_person: {
1517
- email: string;
1518
- lastname: string;
1519
- firstname: string;
1520
- };
1521
- hipaa_compliant: boolean;
1522
- organisation_id: number;
1523
- organisation_name: string;
1524
- };
1525
- custom_fields: {
1526
- ticket: FreshdeskFieldType[];
1527
- company: FreshdeskFieldType[];
1528
- contact: FreshdeskFieldType[];
1529
- };
1530
- integration_org_id: string | number;
1531
- ticket_auto_creation?: boolean;
1532
- };
1533
- }
1534
- >;
1535
-
1536
- export type ZohodeskIntegrationTokenType = OverrideProperties<
1537
- Tables<'tbl_integration_tokens'>,
1538
- {
1539
- type: 'zohodesk';
1540
- token_metadata: {
1541
- scope: string;
1542
- domain: string;
1543
- fields: Array<{
1544
- id: string;
1545
- name: string;
1546
- type: string;
1547
- apiName: string;
1548
- toolTip: string;
1549
- i18NLabel: string;
1550
- maxLength: number;
1551
- isMandatory: boolean;
1552
- toolTipType: string;
1553
- displayLabel: string;
1554
- isCustomField: boolean;
1555
- isEncryptedField: boolean;
1556
- showToHelpCenter: boolean;
1557
- }>;
1558
- org_id: string;
1559
- webhooks: {
1560
- id: string;
1561
- url: string;
1562
- name: string;
1563
- type: string;
1564
- createdBy: string;
1565
- isEnabled: boolean;
1566
- createdTime: string;
1567
- description: string;
1568
- modifiedTime: string;
1569
- subscriptions: {
1570
- [key: string]: {
1571
- departmentIds: string[];
1572
- includePrevState: boolean;
1573
- };
1574
- };
1575
- ignoreSourceId: boolean | null;
1576
- includeEventsFrom: string[];
1577
- };
1578
- api_domain: string;
1579
- authDomain: string;
1580
- expires_in: number;
1581
- token_type: string;
1582
- departments: Array<{
1583
- id: string;
1584
- name: string;
1585
- hasLogo: boolean;
1586
- creatorId: string;
1587
- isDefault: boolean;
1588
- isEnabled: boolean;
1589
- chatStatus: string;
1590
- createdTime: string;
1591
- description: string | null;
1592
- sanitizedName: string;
1593
- nameInCustomerPortal: string;
1594
- isAssignToTeamEnabled: boolean;
1595
- isVisibleInCustomerPortal: boolean;
1596
- }>;
1597
- org_details: {
1598
- id: number;
1599
- fax: string;
1600
- zip: string;
1601
- city: string;
1602
- alias: string | null;
1603
- state: string;
1604
- mobile: string;
1605
- street: string;
1606
- country: string;
1607
- edition: string;
1608
- logoURL: string;
1609
- website: string;
1610
- isDefault: boolean;
1611
- portalURL: string;
1612
- faviconURL: string;
1613
- portalName: string;
1614
- companyName: string;
1615
- description: string | null;
1616
- phoneNumber: string | null;
1617
- currencyCode: string;
1618
- isAdminInOrg: boolean;
1619
- employeeCount: number;
1620
- currencyLocale: string;
1621
- currencySymbol: string;
1622
- primaryContact: string;
1623
- isSandboxPortal: boolean;
1624
- isPayloadEncryptionEnabled: boolean;
1625
- };
1626
- access_token: string;
1627
- refresh_token: string;
1628
- integration_org_id: string | number;
1629
- ticket_auto_creation?: boolean;
1630
- };
1631
- }
1632
- >;
1633
-
1634
- export type ZohoCrmIntegrationTokenType = OverrideProperties<
1635
- Tables<'tbl_integration_tokens'>,
1636
- {
1637
- type: 'zohocrm';
1638
- token_metadata: {
1639
- access_token: string;
1640
- refresh_token: string;
1641
- scope: string;
1642
- api_domain: string;
1643
- token_type: string;
1644
- expires_in: number;
1645
- domain_extension: string;
1646
- authDomain: string;
1647
- integration_org_id: string;
1648
- org_scope_id?: string; // zgid from Zoho CRM, used for building record URLs
1649
- chat_messages_auto_logging?: boolean;
1650
- auto_create_entity?: 'contact' | 'account' | 'lead' | 'none';
1651
- org_details: {
1652
- id: string;
1653
- name: string;
1654
- currency: string;
1655
- time_zone: string;
1656
- currency_symbol: string;
1657
- currency_locale: string;
1658
- website: string;
1659
- description: string | null;
1660
- phone: string | null;
1661
- mobile: string | null;
1662
- fax: string | null;
1663
- street: string;
1664
- city: string;
1665
- state: string;
1666
- zip: string;
1667
- country: string;
1668
- logo_url: string;
1669
- is_sandbox: boolean;
1670
- is_admin_in_org: boolean;
1671
- employee_count: number;
1672
- primary_contact: string;
1673
- };
1674
- fields?: Array<{
1675
- name: string;
1676
- label: string;
1677
- zoho_api_name: string;
1678
- fieldType: string;
1679
- }>;
1680
- modules: Array<{
1681
- id: string;
1682
- name: string;
1683
- api_name: string;
1684
- singular_label: string;
1685
- plural_label: string;
1686
- is_custom: boolean;
1687
- is_creatable: boolean;
1688
- is_editable: boolean;
1689
- is_deletable: boolean;
1690
- is_webform_supported: boolean;
1691
- sequence_number: number;
1692
- fields: Array<{
1693
- id: string;
1694
- name: string;
1695
- api_name: string;
1696
- data_type: string;
1697
- required: boolean;
1698
- is_custom: boolean;
1699
- is_editable: boolean;
1700
- is_creatable: boolean;
1701
- is_webform_supported: boolean;
1702
- length: number;
1703
- decimal_places: number | null;
1704
- default_value: string | null;
1705
- picklist_values: Array<{
1706
- display_value: string;
1707
- actual_value: string;
1708
- }> | null;
1709
- }>;
1710
- }>;
1711
- webhooks?: {
1712
- id: string;
1713
- url: string;
1714
- name: string;
1715
- events: string[];
1716
- is_active: boolean;
1717
- created_time: string;
1718
- modified_time: string;
1719
- };
1720
- };
1721
- }
1722
- >;
1
+ import {
2
+ Coupon,
3
+ Customer,
4
+ Estimate,
5
+ HostedPage,
6
+ ItemPrice,
7
+ Subscription,
8
+ } from 'chargebee';
9
+
10
+ import { Merge, OverrideProperties } from 'type-fest';
11
+ import { Filter, Rule } from './rules.types';
12
+ import { Tables, TablesInsert, TablesUpdate } from './supabase.types';
13
+
14
+ /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
15
+
16
+ /* ------------------------------ PERISKOPE TYPES ------------------------------ */
17
+
18
+ export enum AllPlans {
19
+ FREE_TRIAL = 'free-trial',
20
+ // MONTHLY_STARTER = 'monthly-starter',
21
+ // YEARLY_STARTER = 'yearly-starter',
22
+ // MONTHLY_PRO = 'monthly-pro',
23
+ // YEARLY_PRO = 'yearly-pro',
24
+ ENTERPRISE = 'enterprise',
25
+ MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
26
+ YEARLY_STARTER_SINGLE = 'yearly-starter-single',
27
+ MONTHLY_PRO_SINGLE = 'monthly-pro-single',
28
+ YEARLY_PRO_SINGLE = 'yearly-pro-single',
29
+ }
30
+
31
+ export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
32
+
33
+ export type Enterprise = `${string}-enterprise`;
34
+
35
+ export type OrgPlanEnterprise = {
36
+ subscription_id: string;
37
+ plan_id: Enterprise;
38
+ interval: number;
39
+ frequency: Frequency;
40
+ user_limit: number;
41
+ phone_limit: number;
42
+ current_period_start: number;
43
+ current_period_end: number | null;
44
+ additional_user_limit?: number;
45
+ additional_phone_limit?: number;
46
+ allocated_user_limit?: number;
47
+ allocated_phone_limit?: number;
48
+ currency: string;
49
+ cancelled_at?: number;
50
+ cancel_schedule_created_at?: number;
51
+ subscription_status?: string;
52
+ discount?: number;
53
+ };
54
+
55
+ export type OrgPlanNonEnterprise = {
56
+ subscription_id: string;
57
+ plan_id: AllPlans;
58
+ interval: number;
59
+ frequency: Frequency;
60
+ user_limit: number;
61
+ phone_limit: number;
62
+ current_period_end: number;
63
+ current_period_start: number;
64
+ additional_user_limit?: number;
65
+ additional_phone_limit?: number;
66
+ allocated_user_limit?: number;
67
+ allocated_phone_limit?: number;
68
+ currency: string;
69
+ cancelled_at?: number;
70
+ cancel_schedule_created_at?: number;
71
+ subscription_status?: string;
72
+ discount?: number;
73
+ };
74
+
75
+ export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
76
+ ? OrgPlanEnterprise
77
+ : T extends AllPlans
78
+ ? OrgPlanNonEnterprise
79
+ : never;
80
+
81
+ export type MicrosurveyData = {
82
+ key: string;
83
+ text: string;
84
+ checked: boolean;
85
+ }[];
86
+
87
+ export type OrgPreferences = {
88
+ disable_allow_exports?: boolean;
89
+ disable_view_deleted_messages?: boolean;
90
+ sync_phone_contacts?: boolean;
91
+ mask_phone_numbers?: boolean;
92
+ show_sender_names?: boolean;
93
+ closed_chats?: Record<string, number>;
94
+ auto_read_muted_chats?: boolean;
95
+ member_permissions?: Record<string, boolean>;
96
+ show_active_phone_only_messages_right?: boolean;
97
+ };
98
+
99
+ type OrgPreferenceKey = keyof OrgPreferences;
100
+
101
+ export type OrgPreferencesValue = {
102
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
103
+ }[OrgPreferenceKey];
104
+
105
+ export type OrgAISettings = {
106
+ is_ai_agent_enabled?: boolean;
107
+ is_ai_flagging_enabled?: boolean;
108
+ is_ai_agent_default_on?: boolean;
109
+ ai_agent_activation_prompt?: string;
110
+ ai_flag_prompt?: string;
111
+ ai_nickname?: string;
112
+ confidence_score?: string;
113
+ company_overview?: string;
114
+ ai_responder_roles?: string;
115
+ human_agent_roles?: string;
116
+ ticket_creation_rules?: string;
117
+ private_note_creation_rules?: string;
118
+ response_delay_value?: string;
119
+ snooze_delay_value?: string;
120
+ temperature?: string;
121
+ top_p?: string;
122
+ top_k?: string;
123
+ ai_maintain_flag_status?: boolean;
124
+ enable_shift_timing?: boolean;
125
+ shift_start_time?: string;
126
+ shift_end_time?: string;
127
+ };
128
+
129
+ type OrgAISettingsKey = keyof OrgAISettings;
130
+
131
+ export type OrgAISettingsValue = {
132
+ [K in OrgAISettingsKey]: { key: K; value: OrgAISettings[K] };
133
+ }[OrgAISettingsKey];
134
+
135
+ export type CustomPropertySectionType = {
136
+ id: string;
137
+ name: string;
138
+ order: number;
139
+ type: 'chat' | 'ticket';
140
+ properties_order?: {
141
+ [id: string]: number;
142
+ };
143
+ };
144
+
145
+ export enum CustomPropertyValueType {
146
+ DROPDOWN = 'dropdown',
147
+ TEXT = 'text',
148
+ DATE = 'date',
149
+ FILE = 'file',
150
+ PICKLIST = 'picklist',
151
+ DEPENDENT_DROPDOWN = 'dependent_dropdown',
152
+ }
153
+
154
+ export type CustomPropertyMetadataType = {
155
+ section_id?: string;
156
+ };
157
+
158
+ export type CustomPropertyTextPropertiesType = {
159
+ property_value_type: CustomPropertyValueType.TEXT;
160
+ property_value: null;
161
+ property_metadata: CustomPropertyMetadataType;
162
+ };
163
+
164
+ export type CustomPropertyDropdownPropertiesType = {
165
+ property_value_type: CustomPropertyValueType.DROPDOWN;
166
+ property_value: {
167
+ [key: string]: string;
168
+ };
169
+ property_metadata: CustomPropertyMetadataType;
170
+ };
171
+
172
+ export type CustomPropertyPicklistPropertiesType = {
173
+ property_value_type: CustomPropertyValueType.PICKLIST;
174
+ property_value: {
175
+ [key: string]: string;
176
+ };
177
+ property_metadata: CustomPropertyMetadataType;
178
+ };
179
+
180
+ export type CustomPropertyDependentDropdownPropertiesType = {
181
+ property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
182
+ property_value: {
183
+ level_1: {
184
+ value: string;
185
+ label: string;
186
+ level_2: {
187
+ value: string;
188
+ label: string;
189
+ level_3: {
190
+ value: string;
191
+ label: string;
192
+ }[];
193
+ }[];
194
+ }[];
195
+ };
196
+ property_metadata: Merge<
197
+ CustomPropertyMetadataType,
198
+ {
199
+ level_names: {
200
+ level_1: string;
201
+ level_2: string;
202
+ level_3: string;
203
+ };
204
+ }
205
+ >;
206
+ };
207
+
208
+ export type CustomPropertyFilePropertiesType = {
209
+ property_value_type: CustomPropertyValueType.FILE;
210
+ property_value: null;
211
+ property_metadata: CustomPropertyMetadataType;
212
+ };
213
+
214
+ export type CustomPropertyDatePropertiesType = {
215
+ property_value_type: CustomPropertyValueType.DATE;
216
+ property_value: null;
217
+ property_metadata: CustomPropertyMetadataType;
218
+ };
219
+
220
+ export type CustomPropertyType = OverrideProperties<
221
+ Tables<'tbl_custom_properties'>,
222
+ | CustomPropertyDependentDropdownPropertiesType
223
+ | CustomPropertyTextPropertiesType
224
+ | CustomPropertyDropdownPropertiesType
225
+ | CustomPropertyPicklistPropertiesType
226
+ | CustomPropertyFilePropertiesType
227
+ | CustomPropertyDatePropertiesType
228
+ >;
229
+
230
+ export type OrgMetadata = {
231
+ phone_number: string;
232
+ ticket_prefix: string;
233
+ referralSource?: string;
234
+ contact_name?: string;
235
+ surveyData?: MicrosurveyData;
236
+ preferences?: OrgPreferences;
237
+ partition?: boolean;
238
+ tickets: {
239
+ prefix?: string;
240
+ emoji_ticketing: {
241
+ is_enabled?: boolean;
242
+ is_message_enabled?: boolean;
243
+ message_template?: string;
244
+ };
245
+ disable_auto_attach_message_to_ticket?: boolean;
246
+ };
247
+ attribution?: Object;
248
+ affiliate_id?: string;
249
+ custom_properties?: {
250
+ sections?: CustomPropertySectionType[];
251
+ };
252
+ rules?: {
253
+ limit?: number;
254
+ };
255
+ display_language?: string;
256
+ custom_invite?: {
257
+ is_enabled: boolean;
258
+ template: string;
259
+ };
260
+ };
261
+
262
+ export type GroupTemplateType = OverrideProperties<
263
+ Tables<'tbl_group_templates'>,
264
+ {
265
+ group_metadata: {
266
+ messagesAdminsOnly?: boolean;
267
+ infoAdminsOnly?: boolean;
268
+ addMembersAdminsOnly?: boolean;
269
+ description?: string;
270
+ admins?: string[];
271
+ };
272
+ }
273
+ >;
274
+
275
+ type AccessScopes = {
276
+ feature_flags: Record<string, boolean>;
277
+ integrations: boolean;
278
+ rules: boolean;
279
+ exports: boolean;
280
+ };
281
+
282
+ export type OrgMembersType = OverrideProperties<
283
+ Tables<'tbl_org_members'>,
284
+ {
285
+ member_metadata: {
286
+ shift_times: {
287
+ [day in
288
+ | 'monday'
289
+ | 'tuesday'
290
+ | 'wednesday'
291
+ | 'thursday'
292
+ | 'friday'
293
+ | 'saturday'
294
+ | 'sunday']?: [[string, string]];
295
+ };
296
+ override_status: boolean;
297
+ [key: string]: any;
298
+ };
299
+ }
300
+ >;
301
+
302
+ export type OrgType = OverrideProperties<
303
+ Merge<
304
+ Tables<'tbl_org'>,
305
+ {
306
+ user: OrgMembersType;
307
+ members: OrgMembersType[];
308
+ phones: Tables<'tbl_org_phones'>[];
309
+ labels: Tables<'tbl_org_labels'>[];
310
+ quick_replies: Tables<'tbl_quick_replies'>[];
311
+ custom_properties: CustomPropertyType[];
312
+ subscription_status: 'active' | 'inactive' | 'unpaid';
313
+ is_enterprise: boolean;
314
+ is_free_trial: boolean;
315
+ is_hubspot_connected: boolean;
316
+ is_freshdesk_connected: boolean;
317
+ is_zohodesk_connected: boolean;
318
+ is_zohocrm_connected: boolean;
319
+ access_scopes: AccessScopes;
320
+ rules: Rule[];
321
+ phone_limit: number;
322
+ user_limit: number;
323
+ allocated_user_limit: number;
324
+ allocated_phone_limit: number;
325
+ additional_user_limit: number;
326
+ additional_phone_limit: number;
327
+ }
328
+ >,
329
+ {
330
+ org_plan: OrgPlan<AllPlans | Enterprise>;
331
+ stripe_customer_details: Customer | null;
332
+ stripe_subscription_details: Array<Subscription> | null;
333
+ stripe_customer_id: Customer['id'] | null;
334
+ org_metadata: OrgMetadata;
335
+ ai_settings: OrgAISettings;
336
+ }
337
+ >;
338
+
339
+ export type ChatMemberType = Merge<
340
+ Tables<'tbl_chat_participants'>,
341
+ Tables<'tbl_contacts'>
342
+ >;
343
+
344
+ export type ChatType = Merge<
345
+ Tables<'view_chats'>,
346
+ {
347
+ chat_id: string;
348
+ latest_message: MessageType | null;
349
+ latest_message_timestamp: number | null;
350
+ latest_message_timestamp_map?: Record<string, number | null>;
351
+ members: { [key: string]: ChatMemberType } | null;
352
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
353
+ chat_access: { [key: string]: boolean };
354
+ label_ids: { [key: string]: boolean };
355
+ chat_org_phones?: string[];
356
+ message_unread_count: number | null;
357
+ hubspot_metadata: {
358
+ id: string;
359
+ type: string;
360
+ hubId: string;
361
+ object_data: HubspotObjectDataType;
362
+ } | null;
363
+ info_admins_only: boolean;
364
+ messages_admins_only: boolean;
365
+ unread_count?: { [key: string]: number };
366
+ active_phone: string | null;
367
+ flag_count_map?: { [key: string]: number };
368
+ is_archived?: boolean;
369
+ is_pinned?: boolean;
370
+ closed_at?: number | null;
371
+ common_chats?: string[];
372
+ freshdesk_metadata?: Record<string, any>;
373
+ zohodesk_metadata?: Record<string, any>;
374
+ zohocrm_metadata?: Record<string,any>;
375
+ pinned_messages?: {
376
+ message_id: string;
377
+ pinned_at: number;
378
+ expires_at: number;
379
+ }[];
380
+ group_metadata?: Record<string, any>;
381
+ snooze_metadata?: {
382
+ snooze_until: number;
383
+ snooze_message?: string;
384
+ snooze_by?: string;
385
+ };
386
+ member_unread_count?: {
387
+ [key: string]: number;
388
+ };
389
+ member_closed_at?: {
390
+ [key: string]: number;
391
+ };
392
+ ai_metadata: ChatAIMetadataType;
393
+ }
394
+ >;
395
+
396
+ export type ChatPropertiesType = Merge<Tables<'tbl_chat_properties'>, { ai_metadata: ChatAIMetadataType }>;
397
+
398
+ export type ChatAIMetadataType = {
399
+ is_active: boolean;
400
+ snooze_until: string;
401
+ activation_state: 'active' | 'inactive' | 'snoozed' | 'thinking';
402
+ is_agent_allowed: boolean;
403
+ is_flagging_allowed: boolean;
404
+ } | null;
405
+
406
+ /* -------------------------------------------------------------------------- */
407
+ /* MESSAGE */
408
+ /* -------------------------------------------------------------------------- */
409
+
410
+ export type MediaType = {
411
+ path?: string;
412
+ mimetype?: string;
413
+ filename?: string;
414
+ dimensions?: { width: number; height: number; ar: number };
415
+ size?: number;
416
+ thumbnail?: string;
417
+ filedata?: string;
418
+ compress?: boolean;
419
+ };
420
+
421
+ export type MessageType = Merge<
422
+ OverrideProperties<
423
+ TablesInsert<'tbl_chat_messages'>,
424
+ {
425
+ message_id: string;
426
+ org_id: string;
427
+ org_phone: string;
428
+ chat_id: string;
429
+ message_type: (typeof SUPPORTED_TYPES)[number];
430
+ media: MediaType | null;
431
+ flag_metadata?: MessageFlagType | null;
432
+ poll_info?: PollSendType | null;
433
+ poll_results?: PollResultType | null;
434
+ delivery_info?: DeliveryInfoType | null;
435
+ raw_data?: {
436
+ translations?: Record<string, string>;
437
+ [key: string]: unknown;
438
+ } | null;
439
+ }
440
+ >,
441
+ {
442
+ reactions?: ReactionType[];
443
+ message_payload?: SingleMessagePayload;
444
+ highlight?: number;
445
+ is_private_note?: boolean;
446
+ }
447
+ >;
448
+
449
+ export type MessageFlagType = {
450
+ status: boolean;
451
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
452
+ response_id?: string;
453
+ response_timestamp?: string;
454
+ response_email?: string;
455
+ flagged_by?: string;
456
+ flagged_at?: string;
457
+ response_phone?: string;
458
+ };
459
+
460
+ export type MessageSendType = {
461
+ queue_id: string;
462
+ queue_position: string;
463
+ };
464
+
465
+ export type MessageBroadcastType = {
466
+ broadcast_id: string;
467
+ };
468
+
469
+ /* -------------------------------------------------------------------------- */
470
+
471
+ export type TicketType = OverrideProperties<
472
+ Tables<'tbl_chat_tickets'>,
473
+ {
474
+ label_ids: { [key: string]: boolean };
475
+ hubspot_metadata: {
476
+ id?: string;
477
+ type?: string;
478
+ hubId?: string;
479
+ pipeline: {
480
+ id: string;
481
+ label: string;
482
+ };
483
+ object_data?: HubspotObjectDataType;
484
+ } | null;
485
+ freshdesk_metadata: Record<string, string>;
486
+ close_ticket_metadata?:
487
+ | {
488
+ closed_by: string;
489
+ closed_at: string;
490
+ closed_message?: string | null;
491
+ send_reply_message_id?: string | null;
492
+ }
493
+ | any;
494
+ }
495
+ > & {
496
+ chat?: ChatType;
497
+ quoted_message?: MessageType;
498
+ };
499
+
500
+ export type ContactType = Merge<
501
+ Tables<'tbl_contacts'>,
502
+ {
503
+ chats: ChatType[] | null;
504
+ chat_ids?: string[];
505
+ }
506
+ >;
507
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
508
+
509
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
510
+
511
+ export type ChatAccessType = Merge<
512
+ TablesUpdate<'tbl_org_members'>,
513
+ {
514
+ has_access?: boolean;
515
+ email: string | null;
516
+ }
517
+ >;
518
+
519
+ export type QueueJobTypes = {
520
+ addedTimestamp: number;
521
+ attemptsMade: number;
522
+ attemptsStarted: number;
523
+ data: {
524
+ body: string;
525
+ chat_id: string;
526
+ };
527
+ finishedTimestamp: number;
528
+ id: string;
529
+ message_id: string;
530
+ processedTimestamp: number;
531
+ stacktrace: string[];
532
+ status: string;
533
+ };
534
+
535
+ export type PhoneQueueStatusType = {
536
+ active: number;
537
+ failed: number;
538
+ completed: number;
539
+ is_running: boolean;
540
+ pending: number;
541
+ };
542
+
543
+ export type PhoneType = OverrideProperties<
544
+ Tables<'tbl_org_phones'>,
545
+ {
546
+ queue_status: {
547
+ [key: string]: PhoneQueueStatusType;
548
+ };
549
+ }
550
+ >;
551
+
552
+ export type PhoneInfoType = Merge<
553
+ Pick<
554
+ PhoneType,
555
+ | 'created_at'
556
+ | 'first_connected_at'
557
+ | 'is_ready'
558
+ | 'label_ids'
559
+ | 'org_id'
560
+ | 'org_phone'
561
+ | 'phone_id'
562
+ | 'phone_image'
563
+ | 'phone_name'
564
+ | 'qr_code'
565
+ | 'updated_at'
566
+ | 'wa_state'
567
+ >,
568
+ {
569
+ labels: string[];
570
+ }
571
+ >;
572
+
573
+ /* -------------------------------- CONSTANTS ------------------------------- */
574
+
575
+ export const labelColors = [
576
+ '#9333EA',
577
+ '#0D9488',
578
+ '#DB2777',
579
+ '#2563EB',
580
+ '#F97316',
581
+ ];
582
+
583
+ export const enumChatColors = [
584
+ '#B4876E',
585
+ '#A5B337',
586
+ '#06CF9C',
587
+ '#25D366',
588
+ '#02A698',
589
+ '#7D9EF1',
590
+ '#007BFC',
591
+ '#5E47DE',
592
+ '#7F66FF',
593
+ '#9333EA',
594
+ '#FA6533',
595
+ '#C4532D',
596
+ '#DC2626',
597
+ '#FF2E74',
598
+ '#DB2777',
599
+ ] as const;
600
+
601
+ export type RepeatDaysType =
602
+ | 'monday'
603
+ | 'tuesday'
604
+ | 'wednesday'
605
+ | 'thursday'
606
+ | 'friday'
607
+ | 'saturday'
608
+ | 'sunday';
609
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
610
+
611
+ export enum WhatsappGroupActionEnum {
612
+ ADD = 'add',
613
+ REMOVE = 'remove',
614
+ PROMOTE = 'promote',
615
+ DEMOTE = 'demote',
616
+ INVITE = 'invite',
617
+ LEAVE = 'leave',
618
+ ANNOUNCE_TRUE = 'announce_true',
619
+ ANNOUNCE_FALSE = 'announce_false',
620
+ RESTRICT_TRUE = 'restrict_true',
621
+ RESTRICT_FALSE = 'restrict_false',
622
+ MEMBERADDMODE_TRUE = 'memberaddmode_true',
623
+ MEMBERADDMODE_FALSE = 'memberaddmode_false',
624
+ SUBJECT = 'subject',
625
+ DESC = 'desc',
626
+ CALL = 'call',
627
+ }
628
+
629
+ /* -------------------------- LISTING ENDPOINT -------------------------- */
630
+
631
+ type ListingType = {
632
+ from?: number;
633
+ to?: number;
634
+ count?: number;
635
+ };
636
+
637
+ export type ListNotificationsType = Merge<
638
+ ListingType,
639
+ {
640
+ notifictions?: NotificationType[];
641
+ }
642
+ >;
643
+
644
+ export type ListChatMessagesType = Merge<
645
+ ListingType,
646
+ {
647
+ messages?: MessageType[];
648
+ }
649
+ >;
650
+
651
+ export type ListContactsType = Merge<
652
+ ListingType,
653
+ {
654
+ contacts?: ContactType[];
655
+ }
656
+ >;
657
+
658
+ export type ListTicketsType = Merge<
659
+ ListingType,
660
+ {
661
+ tickets?: TicketType[];
662
+ }
663
+ >;
664
+
665
+ export type ListChatsType = Merge<
666
+ ListingType,
667
+ {
668
+ chats?: ChatType[];
669
+ }
670
+ >;
671
+
672
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
673
+
674
+ export const SUPPORTED_TYPES = [
675
+ 'chat',
676
+ 'sticker',
677
+ 'image',
678
+ 'video',
679
+ 'document',
680
+ 'vcard',
681
+ 'multi_vcard',
682
+ 'audio',
683
+ 'ptt',
684
+ 'poll_creation',
685
+ 'location',
686
+ 'ciphertext',
687
+ ] as const;
688
+
689
+ export type SendMessageContent = {
690
+ message_type?: (typeof SUPPORTED_TYPES)[number];
691
+ body?: string;
692
+ media?: MediaType;
693
+ contact_ids?: string[];
694
+ location?: {
695
+ latitude: string;
696
+ longitude: string;
697
+ options?: { name?: string; address?: string; url?: string };
698
+ };
699
+ poll?: PollSendType;
700
+ quoted_message_id?: string;
701
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
702
+ broadcast_id?: string;
703
+ performed_by?: string;
704
+ options?: Record<string, any>;
705
+ };
706
+
707
+ export type QuickReplyContent = Omit<
708
+ SendMessageContent,
709
+ 'broadcast_id' | 'variables'
710
+ >;
711
+
712
+ export type ScheduleMessagePayload = {
713
+ scheduled_id?: string;
714
+ is_repeat?: boolean | null;
715
+ scheduled_at: string;
716
+ repeat_config?: {
717
+ timezone?: string;
718
+ repeat_ends?: string;
719
+ repeat_interval?: RepeatIntervalType;
720
+ repeat_value?: number;
721
+ repeat_days?: RepeatDaysType[];
722
+ };
723
+ };
724
+
725
+ export type BroadcastVariableType = {
726
+ chat_id: string;
727
+ values: { [key: string]: string };
728
+ };
729
+
730
+ export type BroadcastMessagePayload = SendMessageContent & {
731
+ chat_ids: string[];
732
+ broadcast_id?: string;
733
+ variables?: BroadcastVariableType[];
734
+ delay?: number;
735
+ };
736
+
737
+ export type SingleMessagePayload = SendMessageContent & {
738
+ chat_id: string;
739
+ job_id?: string;
740
+ priority?: number;
741
+ scheduled_id?: string;
742
+ };
743
+
744
+ export type MessageAttachmentFileTypes =
745
+ | 'image'
746
+ | 'audio'
747
+ | 'document'
748
+ | 'video';
749
+
750
+ export type AttachmentFileType = {
751
+ result: string;
752
+ file: File | null;
753
+ type: MessageAttachmentFileTypes;
754
+ localFileURL?: string;
755
+ };
756
+
757
+ export type AttachmentLinkType = {
758
+ link: {
759
+ url: string;
760
+ type: MessageAttachmentFileTypes;
761
+ name: string;
762
+ mimetype?: string;
763
+ };
764
+ };
765
+
766
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
767
+
768
+ /* -------------------------------- BROADCAST ------------------------------- */
769
+
770
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
771
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
772
+ } & {
773
+ chats: ChatType[];
774
+ };
775
+
776
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
777
+
778
+ export type ChatLogType = {
779
+ log: Tables<'view_chat_logs'>;
780
+ operations: Tables<'tbl_chat_logs'>[];
781
+ };
782
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
783
+
784
+ export type ChatParticipantOperationPayload = {
785
+ participant_ids: string[];
786
+ chat_ids: string[];
787
+ performed_by: string;
788
+ force_add_participants?: boolean;
789
+ };
790
+
791
+ export type ChatOperationReturn = {
792
+ [participant_id: string]: {
793
+ is_success: boolean;
794
+ message?: string;
795
+ code?: number;
796
+ isInviteV4Sent?: boolean;
797
+ };
798
+ };
799
+
800
+ /* ----------------------- BILLING - STRIPE ----------------------- */
801
+
802
+ export type ChargebeeSubscription = Subscription;
803
+ export type ChargebeeCustomer = Customer;
804
+ export type ChargebeePrice = ItemPrice;
805
+ export type ChargebeeUpcomingInvoice =
806
+ Estimate.RenewalEstimateResponse['estimate'];
807
+ export type ChargebeeLineItem =
808
+ HostedPage.CheckoutNewForItemsInputParam['subscription_items'];
809
+
810
+ /* -------------------------------- REALTIME -------------------------------- */
811
+
812
+ export type PhoneStateType = {
813
+ loading: boolean;
814
+ state: string;
815
+ sync: number;
816
+ percent: number | null;
817
+ message?: string;
818
+ error?: string;
819
+ };
820
+
821
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
822
+
823
+ export type ChatInfoType = Merge<
824
+ ChatType,
825
+ {
826
+ members: {
827
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
828
+ } | null;
829
+ chat_labels: string | null;
830
+ custom_properties: { [key: string]: string } | null;
831
+ }
832
+ >;
833
+
834
+ export type TicketInfoType = {
835
+ chat: ChatInfoType;
836
+ message: {
837
+ body: string;
838
+ chat_id: string;
839
+ org_phone: string;
840
+ timestamp: string;
841
+ media_path: string;
842
+ message_id: string;
843
+ sender_name: string;
844
+ performed_by: string;
845
+ sender_phone: string;
846
+ };
847
+ ticket: {
848
+ org_id: string;
849
+ status: string;
850
+ subject: string;
851
+ assignee: string;
852
+ due_date: string;
853
+ priority: 0 | 1 | 2 | 3 | 4;
854
+ raised_by: string;
855
+ ticket_id: string;
856
+ created_at: string;
857
+ assigned_by: string;
858
+ ticket_labels: string;
859
+ quoted_message_id: string;
860
+ ticket_custom_properties: { [key: string]: string } | null;
861
+ closed_at: string;
862
+ closed_by: string;
863
+ closed_message: string;
864
+ first_assigned_at: string | null;
865
+ is_deleted: boolean;
866
+ };
867
+ attached_messages: {
868
+ body: string;
869
+ chat_id: string;
870
+ org_phone: string;
871
+ timestamp: string;
872
+ media_path: string;
873
+ message_id: string;
874
+ sender_name: string;
875
+ performed_by: string;
876
+ sender_phone: string;
877
+ }[];
878
+ };
879
+
880
+ export type IntegrationLogObjectType =
881
+ | 'chat'
882
+ | 'message'
883
+ | 'reaction'
884
+ | 'ticket'
885
+ | 'phone';
886
+ export enum IntegrationLogType {
887
+ NEW_CHAT = 'chat.created',
888
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
889
+ NEW_MESSAGE = 'message.created',
890
+ MESSAGE_UPDATED = 'message.updated',
891
+ MESSAGE_DELETED = 'message.deleted',
892
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
893
+ MESSAGE_FLAGGED = 'message.flagged',
894
+ MESSAGE_UNFLAGGED = 'message.unflagged',
895
+ MESSAGE_TICKET_ATTACHED = 'message.ticket.attached',
896
+ REACTION_CREATED = 'reaction.created',
897
+ REACTION_UPDATED = 'reaction.updated',
898
+ NEW_TICKET = 'ticket.created',
899
+ TICKET_UPDATED = 'ticket.updated',
900
+ TICKET_DELETED = 'ticket.deleted',
901
+ PHONE_DISCONNECTED = 'org.phone.disconnected',
902
+ PHONE_CONNECTED = 'org.phone.connected',
903
+ PHONE_UPDATED = 'org.phone.updated',
904
+ PHONE_QR_UPDATED = 'org.phone.qr',
905
+ NOTE_CREATED = 'note.created',
906
+ CHAT_CUSTOM_PROPERTIES_UPDATED = 'chat.custom_properties.updated',
907
+ }
908
+
909
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
910
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
911
+ ? TicketInfoType
912
+ : T extends IntegrationLogType.NEW_CHAT
913
+ ? Tables<'tbl_chats'>
914
+ : T extends
915
+ | IntegrationLogType.NEW_MESSAGE
916
+ | IntegrationLogType.MESSAGE_UPDATED
917
+ | IntegrationLogType.MESSAGE_DELETED
918
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
919
+ | IntegrationLogType.MESSAGE_FLAGGED
920
+ | IntegrationLogType.MESSAGE_UNFLAGGED
921
+ | IntegrationLogType.MESSAGE_TICKET_ATTACHED
922
+ ? Tables<'tbl_chat_messages'>
923
+ : T extends
924
+ | IntegrationLogType.REACTION_CREATED
925
+ | IntegrationLogType.REACTION_UPDATED
926
+ ? Tables<'tbl_chat_reactions'>
927
+ : T extends
928
+ | IntegrationLogType.PHONE_DISCONNECTED
929
+ | IntegrationLogType.PHONE_CONNECTED
930
+ | IntegrationLogType.PHONE_UPDATED
931
+ | IntegrationLogType.PHONE_QR_UPDATED
932
+ ? Tables<'tbl_org_phones'>
933
+ : T extends IntegrationLogType.NOTE_CREATED
934
+ ? Tables<'tbl_chat_notes'>
935
+ : {
936
+ [key: string]: unknown;
937
+ };
938
+
939
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
940
+ OverrideProperties<
941
+ Tables<'tbl_integration_logs'>,
942
+ {
943
+ integration_name: T;
944
+ metadata: {
945
+ event: IntegrationLogMetadataType<T> & {
946
+ event_type: string;
947
+ org_id: string;
948
+ previous_attributes: {
949
+ [key: string]: unknown;
950
+ };
951
+ };
952
+ hook_id: string;
953
+ name: string;
954
+ };
955
+ }
956
+ >;
957
+
958
+ export type APIAuthDetails = {
959
+ org_details: Tables<'view_org'> | null;
960
+ phone_details: Tables<'tbl_org_phones'> | null;
961
+ token_details: Tables<'tbl_integration_tokens'> | null;
962
+ };
963
+
964
+ export type WebhookDataType = OverrideProperties<
965
+ Tables<'tbl_integration_hooks'>,
966
+ {
967
+ integration_name: string[];
968
+ }
969
+ >;
970
+
971
+ export type HubspotObjectDataType = {
972
+ createdAt: string;
973
+ archived: boolean;
974
+ id: string;
975
+ type: 'contacts' | 'tickets' | 'companies';
976
+ properties: Record<
977
+ string,
978
+ {
979
+ groupLabel: string;
980
+ groupName: string;
981
+ propertyKeyName: string;
982
+ propertyKey: string;
983
+ propertyInternalValue: string;
984
+ propertyValue: string;
985
+ propertyType: string;
986
+ propertyFieldType: string;
987
+ }[]
988
+ >;
989
+ };
990
+
991
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
992
+
993
+ export type UserPreferences = {
994
+ theme: 'light' | 'dark';
995
+ language: 'en' | 'es';
996
+ left_sidebar_open: boolean;
997
+ right_sidepanel_open: boolean;
998
+ sync_wa_unread_count: boolean;
999
+ pinned_chats: string[];
1000
+ periskope_chat_limit: number;
1001
+ notifications: Record<string, boolean>;
1002
+ };
1003
+
1004
+ /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
1005
+
1006
+ export interface MostActiveMember {
1007
+ sender_phone: string;
1008
+ total_messages: number;
1009
+ }
1010
+
1011
+ export interface GroupAnalyticsResult {
1012
+ total_messages: number;
1013
+ total_joins: number;
1014
+ total_leaves: number;
1015
+ total_removes: number;
1016
+ total_reactions: number;
1017
+ most_active_members: MostActiveMember[];
1018
+ }
1019
+
1020
+ export interface TimeRange {
1021
+ startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
1022
+ endDateTime: string;
1023
+ }
1024
+
1025
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
1026
+
1027
+ export type PollSendType = {
1028
+ pollName: string;
1029
+ pollOptions: string[];
1030
+ options?: {
1031
+ allowMultipleAnswers?: boolean;
1032
+ messageSecret?: number[] | null;
1033
+ pollId?: string;
1034
+ };
1035
+ };
1036
+
1037
+ export type PollResultType = {
1038
+ [name: string]: Record<string, string>;
1039
+ };
1040
+
1041
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
1042
+
1043
+ export type CreateGroupOptions = {
1044
+ messagesAdminsOnly?: boolean;
1045
+ infoAdminsOnly?: boolean;
1046
+ addMembersAdminsOnly?: boolean;
1047
+ image?: string;
1048
+ name?: string;
1049
+ description?: string;
1050
+ initiated_by?: string;
1051
+ admins?: string[];
1052
+ force_add_participants?: boolean;
1053
+ };
1054
+
1055
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
1056
+
1057
+ export type DeliveryInfoType = {
1058
+ delivered: Record<string, number | undefined>;
1059
+ read: Record<string, number | undefined>;
1060
+ pending: string[];
1061
+ read_count: number;
1062
+ delivered_count: number;
1063
+ };
1064
+
1065
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
1066
+
1067
+ export type OrgCreditsType = {
1068
+ org_id: string;
1069
+ recurring_allowance: number; // recurring credits replenished every cycle
1070
+ recurring_balance: number; // recurring credits remaining in current cycle
1071
+ topup_balance: number; // topup credits remaining
1072
+ total_credits_used: number; // total credits used in current cycle
1073
+ next_renewal_date: string;
1074
+ topup_credits_used: number; // topup credits used in current cycle
1075
+ recurring_credits_used: number; // recurring credits used in current cycle
1076
+ };
1077
+
1078
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
1079
+
1080
+ export type ChatRuleInfoType = {
1081
+ chat: Merge<
1082
+ Pick<
1083
+ Tables<'view_chats'>,
1084
+ | 'assigned_to'
1085
+ | 'chat_id'
1086
+ | 'chat_name'
1087
+ | 'chat_type'
1088
+ | 'created_at'
1089
+ | 'group_description'
1090
+ | 'info_admins_only'
1091
+ | 'org_id'
1092
+ | 'org_phone'
1093
+ | 'chat_org_phones'
1094
+ | 'messages_admins_only'
1095
+ | 'custom_properties'
1096
+ | 'initiated_by'
1097
+ >,
1098
+ {
1099
+ has_flagged_messages: boolean;
1100
+ labels: string[];
1101
+ members: string[];
1102
+ custom_properties: { [key: string]: string } | null;
1103
+ assignee_name: string | null;
1104
+ }
1105
+ >;
1106
+ };
1107
+
1108
+ export type SenderRuleInfoType = Merge<
1109
+ Omit<
1110
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1111
+ | 'verified_name'
1112
+ | 'verified_level'
1113
+ | 'updated_at'
1114
+ | 'short_name'
1115
+ | 'pushname'
1116
+ | 'periskope_name'
1117
+ | 'org_phone'
1118
+ | 'number'
1119
+ | 'name'
1120
+ | 'label_ids'
1121
+ | 'is_wa_contact'
1122
+ | 'is_user'
1123
+ | 'is_my_contact'
1124
+ | 'is_me'
1125
+ | 'is_imported'
1126
+ | 'is_group'
1127
+ | 'is_blocked'
1128
+ | 'contact_color'
1129
+ | 'business_profile'
1130
+ | 'id'
1131
+ | 'contact_image'
1132
+ | 'contact_type'
1133
+ | 'chat_id'
1134
+ | 'is_business'
1135
+ | 'is_enterprise'
1136
+ | 'is_super_admin'
1137
+ | 'contact_lid'
1138
+ >,
1139
+ {
1140
+ is_internal: boolean;
1141
+ labels: string[] | null;
1142
+ }
1143
+ >;
1144
+
1145
+ export type MessageRuleInfoType = {
1146
+ chat: ChatRuleInfoType['chat'];
1147
+ sender: SenderRuleInfoType;
1148
+ message: OverrideProperties<
1149
+ Omit<
1150
+ Tables<'tbl_chat_messages'>,
1151
+ | 'vcards'
1152
+ | 'updated_at'
1153
+ | 'unique_id'
1154
+ | 'token'
1155
+ | 'to'
1156
+ | 'sent_message_id'
1157
+ | 'raw_data'
1158
+ | 'delivery_info'
1159
+ | 'poll_results'
1160
+ | 'poll_info'
1161
+ | 'order_id'
1162
+ | 'mentioned_ids'
1163
+ | 'media_key'
1164
+ | 'location'
1165
+ | 'links'
1166
+ | 'is_status'
1167
+ | 'is_starred'
1168
+ | 'is_gif'
1169
+ | 'is_forwarded'
1170
+ | 'is_ephemeral'
1171
+ | 'is_deleted'
1172
+ | 'fts'
1173
+ | 'quoted_message_id'
1174
+ | 'invite_v4'
1175
+ | 'id'
1176
+ | 'has_reaction'
1177
+ | 'has_media'
1178
+ | 'duration'
1179
+ | 'broadcast'
1180
+ | 'broadcast_id'
1181
+ | 'device_type'
1182
+ | 'forwarding_score'
1183
+ | 'from'
1184
+ | 'from_me'
1185
+ | 'prev_body'
1186
+ | 'flag_response_time'
1187
+ | 'flag_metadata'
1188
+ | 'ack'
1189
+ >,
1190
+ {
1191
+ media: MediaType | null;
1192
+ }
1193
+ >;
1194
+ };
1195
+
1196
+ export type ReactionRuleInfoType = {
1197
+ chat: MessageRuleInfoType['chat'];
1198
+ sender: MessageRuleInfoType['sender'];
1199
+ message: MessageRuleInfoType['message'];
1200
+ reaction: Pick<
1201
+ Tables<'tbl_chat_reactions'>,
1202
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1203
+ >;
1204
+ };
1205
+
1206
+ export type TicketRuleInfoType = {
1207
+ chat: MessageRuleInfoType['chat'];
1208
+ sender: MessageRuleInfoType['sender'];
1209
+ ticket: Merge<
1210
+ Pick<
1211
+ Tables<'tbl_chat_tickets'>,
1212
+ | 'org_id'
1213
+ | 'status'
1214
+ | 'chat_id'
1215
+ | 'subject'
1216
+ | 'assignee'
1217
+ | 'due_date'
1218
+ | 'priority'
1219
+ | 'raised_by'
1220
+ | 'ticket_id'
1221
+ | 'created_at'
1222
+ | 'is_deleted'
1223
+ >,
1224
+ {
1225
+ labels: string[] | null;
1226
+ custom_properties: { [key: string]: string } | null;
1227
+ }
1228
+ >;
1229
+ message: MessageRuleInfoType['message'];
1230
+ };
1231
+
1232
+ export type TaskRuleInfoType<
1233
+ T extends 'ticket' | 'chat' | 'message' | 'todo' = 'todo',
1234
+ > = {
1235
+ associated_object_data: T extends 'message'
1236
+ ? MessageRuleInfoType
1237
+ : T extends 'ticket'
1238
+ ? TicketRuleInfoType
1239
+ : T extends 'chat'
1240
+ ? ChatRuleInfoType
1241
+ : null;
1242
+ task: Pick<
1243
+ TaskType,
1244
+ | 'org_id'
1245
+ | 'title'
1246
+ | 'notes'
1247
+ | 'status'
1248
+ | 'assignee'
1249
+ | 'due_date'
1250
+ | 'priority'
1251
+ | 'task_id'
1252
+ | 'created_at'
1253
+ >;
1254
+ };
1255
+
1256
+ export type FeatureFlagReturnType = Record<string, boolean>;
1257
+
1258
+ export type RuleLogsType = OverrideProperties<
1259
+ Tables<'tbl_rules_logs'>,
1260
+ {
1261
+ actions_progress: {
1262
+ action_id: string;
1263
+ action_type: Rule['actions'][number]['type'];
1264
+ action_delay: Rule['actions'][number]['delay'];
1265
+ ran_at: string | null;
1266
+ action_status: 'success' | 'failed' | 'pending';
1267
+ action_response: {
1268
+ success: boolean;
1269
+ data: Record<string, unknown> | null;
1270
+ error: {
1271
+ message: string;
1272
+ name: string;
1273
+ stack?: string;
1274
+ _error?: Error | Record<string, unknown>;
1275
+ } | null;
1276
+ };
1277
+ }[];
1278
+ metadata: {
1279
+ conditions: Rule['conditions'];
1280
+ actions: Rule['actions'];
1281
+ rule_metadata: Pick<
1282
+ Rule,
1283
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
1284
+ >;
1285
+ data: Record<string, unknown>;
1286
+ };
1287
+ conditions_progress: {
1288
+ is_valid: boolean;
1289
+ validation_progress: Record<
1290
+ string,
1291
+ {
1292
+ res: boolean;
1293
+ filter: Filter;
1294
+ value: unknown;
1295
+ }
1296
+ >;
1297
+ checked_at: string | null;
1298
+ };
1299
+ }
1300
+ >;
1301
+
1302
+ /************************** TASKS ***************************/
1303
+
1304
+ export type ChatMetadataType = {
1305
+ type: 'chat';
1306
+ index: 'chat_id';
1307
+ id: string;
1308
+ object: Pick<ChatType, 'chat_id' | 'org_phone' | 'org_id'>;
1309
+ };
1310
+
1311
+ export type MessageMetadataType = {
1312
+ type: 'message';
1313
+ index: 'message_id';
1314
+ id: string;
1315
+ object: Pick<
1316
+ MessageType,
1317
+ | 'message_id'
1318
+ | 'org_phone'
1319
+ | 'chat_id'
1320
+ | 'sender_phone'
1321
+ | 'org_id'
1322
+ | 'is_private_note'
1323
+ >;
1324
+ };
1325
+
1326
+ export type TicketMetadataType = {
1327
+ type: 'ticket';
1328
+ index: 'ticket_id';
1329
+ id: string;
1330
+ object: Pick<
1331
+ TicketType,
1332
+ 'ticket_id' | 'quoted_message_id' | 'chat_id' | 'org_id'
1333
+ >;
1334
+ };
1335
+
1336
+ export type AssociatedObjectMetadataType<
1337
+ T extends 'chat' | 'message' | 'ticket' | 'todo' =
1338
+ | 'chat'
1339
+ | 'message'
1340
+ | 'ticket'
1341
+ | 'todo',
1342
+ > = T extends 'chat'
1343
+ ? ChatMetadataType
1344
+ : T extends 'message'
1345
+ ? MessageMetadataType
1346
+ : T extends 'ticket'
1347
+ ? TicketMetadataType
1348
+ : null;
1349
+
1350
+ export const isChatTask = (task: TaskType): task is TaskType<'chat'> =>
1351
+ task.associated_object_metadata?.type === 'chat';
1352
+
1353
+ export const isMessageTask = (task: TaskType): task is TaskType<'message'> =>
1354
+ task.associated_object_metadata?.type === 'message';
1355
+
1356
+ export const isTicketTask = (task: TaskType): task is TaskType<'ticket'> =>
1357
+ task.associated_object_metadata?.type === 'ticket';
1358
+
1359
+ export const isTodoTask = (task: TaskType): task is TaskType<'todo'> =>
1360
+ task.type === 'todo';
1361
+
1362
+ export type TaskType<
1363
+ T extends 'chat' | 'message' | 'ticket' | 'todo' =
1364
+ | 'chat'
1365
+ | 'message'
1366
+ | 'ticket'
1367
+ | 'todo',
1368
+ > = OverrideProperties<
1369
+ Tables<'tbl_org_tasks'>,
1370
+ {
1371
+ reminder_setting: {
1372
+ remind_in:
1373
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1374
+ | string
1375
+ | null;
1376
+ repeat?: {
1377
+ frequency: number;
1378
+ interval: 'days' | 'weeks' | 'months' | 'years';
1379
+ end: 'never' | 'after' | 'on';
1380
+ on?: string;
1381
+ };
1382
+ } | null;
1383
+ associated_object_metadata: AssociatedObjectMetadataType<T>;
1384
+ status: 'open' | 'inprogress' | 'closed';
1385
+ priority: 1 | 2 | 3;
1386
+ completed_metadata?: {
1387
+ completed_at: string;
1388
+ completed_by: string;
1389
+ } | null;
1390
+ type: T;
1391
+ }
1392
+ >;
1393
+
1394
+ type Choice = {
1395
+ id: number;
1396
+ label: string;
1397
+ value: string;
1398
+ position: number;
1399
+ };
1400
+
1401
+ export type FreshdeskFieldType = {
1402
+ id: number;
1403
+ name: string;
1404
+ type: string;
1405
+ label: string;
1406
+ default: boolean;
1407
+ archived: boolean;
1408
+ position: number;
1409
+ created_at: string;
1410
+ updated_at: string;
1411
+ customers_can_edit: boolean;
1412
+ label_for_customers: string;
1413
+ required_for_agents: boolean;
1414
+ customers_can_filter: boolean;
1415
+ required_for_closure: boolean;
1416
+ displayed_to_customers: boolean;
1417
+ required_for_customers: boolean;
1418
+ choices?: Choice[];
1419
+ };
1420
+
1421
+ export type OrgWarmup = OverrideProperties<
1422
+ Tables<{ schema: 'internal' }, 'tbl_org_warmup'>,
1423
+ {
1424
+ warmup_chats: { [key: string]: string };
1425
+ }
1426
+ >;
1427
+
1428
+ /** ----------------------------- INTEGRATION TOKENS TYPES ----------------------------- **/
1429
+
1430
+ export type FreshdeskIntegrationTokenType = OverrideProperties<
1431
+ Tables<'tbl_integration_tokens'>,
1432
+ {
1433
+ type: 'freshdesk';
1434
+ token_metadata: {
1435
+ url: string;
1436
+ apiKey: string;
1437
+ fields: {
1438
+ ticket: FreshdeskFieldType[];
1439
+ company: FreshdeskFieldType[];
1440
+ contact: FreshdeskFieldType[];
1441
+ };
1442
+ automation: {
1443
+ id: number | string;
1444
+ meta: {
1445
+ total_count: number;
1446
+ total_active_count: 17;
1447
+ };
1448
+ name: string;
1449
+ active: boolean;
1450
+ events: Array<{
1451
+ to?: string;
1452
+ from?: string;
1453
+ field_name: string;
1454
+ value?: string;
1455
+ }>;
1456
+ actions: Array<{
1457
+ url: string;
1458
+ content: Record<string, string>;
1459
+ field_name: string;
1460
+ content_type: string;
1461
+ request_type: string;
1462
+ content_layout: string;
1463
+ }>;
1464
+ summary: {
1465
+ events: Array<string>;
1466
+ actions: Array<string>;
1467
+ performer: string;
1468
+ conditions: {
1469
+ [key: string]: Array<string>;
1470
+ };
1471
+ };
1472
+ outdated: boolean;
1473
+ position: number;
1474
+ performer: {
1475
+ type: string;
1476
+ };
1477
+ conditions: Array<{
1478
+ name: string;
1479
+ match_type: string;
1480
+ properties: Array<{
1481
+ value: Array<string>;
1482
+ operator: string;
1483
+ field_name: string;
1484
+ resource_type: string;
1485
+ case_sensitive: boolean;
1486
+ }>;
1487
+ }>;
1488
+ created_at: string;
1489
+ updated_at: string;
1490
+ description: string | null;
1491
+ last_updated_by: string | number;
1492
+ affected_tickets_count: number | null;
1493
+ };
1494
+ org_details: {
1495
+ address: {
1496
+ city: string;
1497
+ state: string;
1498
+ street: string;
1499
+ country: string;
1500
+ postalcode: string;
1501
+ };
1502
+ timezone: string;
1503
+ bundle_id: string;
1504
+ tier_type: string;
1505
+ account_id: number;
1506
+ cloud_type: string;
1507
+ data_center: string;
1508
+ account_name: string;
1509
+ total_agents: {
1510
+ full_time: number;
1511
+ occasional: number;
1512
+ collaborators: number;
1513
+ field_service: number;
1514
+ };
1515
+ account_domain: string;
1516
+ contact_person: {
1517
+ email: string;
1518
+ lastname: string;
1519
+ firstname: string;
1520
+ };
1521
+ hipaa_compliant: boolean;
1522
+ organisation_id: number;
1523
+ organisation_name: string;
1524
+ };
1525
+ custom_fields: {
1526
+ ticket: FreshdeskFieldType[];
1527
+ company: FreshdeskFieldType[];
1528
+ contact: FreshdeskFieldType[];
1529
+ };
1530
+ integration_org_id: string | number;
1531
+ ticket_auto_creation?: boolean;
1532
+ };
1533
+ }
1534
+ >;
1535
+
1536
+ export type ZohodeskIntegrationTokenType = OverrideProperties<
1537
+ Tables<'tbl_integration_tokens'>,
1538
+ {
1539
+ type: 'zohodesk';
1540
+ token_metadata: {
1541
+ scope: string;
1542
+ domain: string;
1543
+ fields: Array<{
1544
+ id: string;
1545
+ name: string;
1546
+ type: string;
1547
+ apiName: string;
1548
+ toolTip: string;
1549
+ i18NLabel: string;
1550
+ maxLength: number;
1551
+ isMandatory: boolean;
1552
+ toolTipType: string;
1553
+ displayLabel: string;
1554
+ isCustomField: boolean;
1555
+ isEncryptedField: boolean;
1556
+ showToHelpCenter: boolean;
1557
+ }>;
1558
+ org_id: string;
1559
+ webhooks: {
1560
+ id: string;
1561
+ url: string;
1562
+ name: string;
1563
+ type: string;
1564
+ createdBy: string;
1565
+ isEnabled: boolean;
1566
+ createdTime: string;
1567
+ description: string;
1568
+ modifiedTime: string;
1569
+ subscriptions: {
1570
+ [key: string]: {
1571
+ departmentIds: string[];
1572
+ includePrevState: boolean;
1573
+ };
1574
+ };
1575
+ ignoreSourceId: boolean | null;
1576
+ includeEventsFrom: string[];
1577
+ };
1578
+ api_domain: string;
1579
+ authDomain: string;
1580
+ expires_in: number;
1581
+ token_type: string;
1582
+ departments: Array<{
1583
+ id: string;
1584
+ name: string;
1585
+ hasLogo: boolean;
1586
+ creatorId: string;
1587
+ isDefault: boolean;
1588
+ isEnabled: boolean;
1589
+ chatStatus: string;
1590
+ createdTime: string;
1591
+ description: string | null;
1592
+ sanitizedName: string;
1593
+ nameInCustomerPortal: string;
1594
+ isAssignToTeamEnabled: boolean;
1595
+ isVisibleInCustomerPortal: boolean;
1596
+ }>;
1597
+ org_details: {
1598
+ id: number;
1599
+ fax: string;
1600
+ zip: string;
1601
+ city: string;
1602
+ alias: string | null;
1603
+ state: string;
1604
+ mobile: string;
1605
+ street: string;
1606
+ country: string;
1607
+ edition: string;
1608
+ logoURL: string;
1609
+ website: string;
1610
+ isDefault: boolean;
1611
+ portalURL: string;
1612
+ faviconURL: string;
1613
+ portalName: string;
1614
+ companyName: string;
1615
+ description: string | null;
1616
+ phoneNumber: string | null;
1617
+ currencyCode: string;
1618
+ isAdminInOrg: boolean;
1619
+ employeeCount: number;
1620
+ currencyLocale: string;
1621
+ currencySymbol: string;
1622
+ primaryContact: string;
1623
+ isSandboxPortal: boolean;
1624
+ isPayloadEncryptionEnabled: boolean;
1625
+ };
1626
+ access_token: string;
1627
+ refresh_token: string;
1628
+ integration_org_id: string | number;
1629
+ ticket_auto_creation?: boolean;
1630
+ };
1631
+ }
1632
+ >;
1633
+
1634
+ export type ZohoCrmIntegrationTokenType = OverrideProperties<
1635
+ Tables<'tbl_integration_tokens'>,
1636
+ {
1637
+ type: 'zohocrm';
1638
+ token_metadata: {
1639
+ access_token: string;
1640
+ refresh_token: string;
1641
+ scope: string;
1642
+ api_domain: string;
1643
+ token_type: string;
1644
+ expires_in: number;
1645
+ domain_extension: string;
1646
+ authDomain: string;
1647
+ integration_org_id: string;
1648
+ org_scope_id?: string; // zgid from Zoho CRM, used for building record URLs
1649
+ chat_messages_auto_logging?: boolean;
1650
+ auto_create_entity?: 'contact' | 'account' | 'lead' | 'none';
1651
+ bypass_webhook_workflow_creation?: boolean;
1652
+ org_details: {
1653
+ id: string;
1654
+ name: string;
1655
+ currency: string;
1656
+ time_zone: string;
1657
+ currency_symbol: string;
1658
+ currency_locale: string;
1659
+ website: string;
1660
+ description: string | null;
1661
+ phone: string | null;
1662
+ mobile: string | null;
1663
+ fax: string | null;
1664
+ street: string;
1665
+ city: string;
1666
+ state: string;
1667
+ zip: string;
1668
+ country: string;
1669
+ logo_url: string;
1670
+ is_sandbox: boolean;
1671
+ is_admin_in_org: boolean;
1672
+ employee_count: number;
1673
+ primary_contact: string;
1674
+ };
1675
+ fields?: Array<{
1676
+ name: string;
1677
+ label: string;
1678
+ zoho_api_name: string;
1679
+ fieldType: string;
1680
+ }>;
1681
+ modules: Array<{
1682
+ id: string;
1683
+ name: string;
1684
+ api_name: string;
1685
+ singular_label: string;
1686
+ plural_label: string;
1687
+ is_custom: boolean;
1688
+ is_creatable: boolean;
1689
+ is_editable: boolean;
1690
+ is_deletable: boolean;
1691
+ is_webform_supported: boolean;
1692
+ sequence_number: number;
1693
+ fields: Array<{
1694
+ id: string;
1695
+ name: string;
1696
+ api_name: string;
1697
+ data_type: string;
1698
+ required: boolean;
1699
+ is_custom: boolean;
1700
+ is_editable: boolean;
1701
+ is_creatable: boolean;
1702
+ is_webform_supported: boolean;
1703
+ length: number;
1704
+ decimal_places: number | null;
1705
+ default_value: string | null;
1706
+ picklist_values: Array<{
1707
+ display_value: string;
1708
+ actual_value: string;
1709
+ }> | null;
1710
+ }>;
1711
+ }>;
1712
+ webhooks?: {
1713
+ id: string;
1714
+ url: string;
1715
+ name: string;
1716
+ events: string[];
1717
+ is_active: boolean;
1718
+ created_time: string;
1719
+ modified_time: string;
1720
+ };
1721
+ };
1722
+ }
1723
+ >;