@periskope/types 0.6.408 → 0.6.410

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