@periskope/types 0.6.432 → 0.6.434

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