@periskope/types 0.6.415 → 0.6.417

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