@periskope/types 0.6.424 → 0.6.425

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