@periskope/types 0.6.274 → 0.6.276

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,1242 +1,1242 @@
1
- import type { default as _Stripe } from 'stripe';
2
- import { Merge, OverrideProperties } from 'type-fest';
3
- import { Filter, Rule } from './rules.types';
4
- import { Enums, Tables, TablesInsert, TablesUpdate } from './supabase.types';
5
- import { WorkflowActionTypes } from './workflows.types';
6
-
7
- /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
8
-
9
- /* ------------------------------ PERISKOPE TYPES ------------------------------ */
10
-
11
- export enum AllPlans {
12
- FREE_TRIAL = 'free-trial',
13
- // MONTHLY_STARTER = 'monthly-starter',
14
- // YEARLY_STARTER = 'yearly-starter',
15
- // MONTHLY_PRO = 'monthly-pro',
16
- // YEARLY_PRO = 'yearly-pro',
17
- ENTERPRISE = 'enterprise',
18
- MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
19
- YEARLY_STARTER_SINGLE = 'yearly-starter-single',
20
- MONTHLY_PRO_SINGLE = 'monthly-pro-single',
21
- YEARLY_PRO_SINGLE = 'yearly-pro-single',
22
- }
23
-
24
- export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
25
-
26
- export type Enterprise = `${string}-enterprise`;
27
-
28
- export type OrgPlanEnterprise = {
29
- subscription_id: string;
30
- plan_id: Enterprise;
31
- interval: number;
32
- frequency: Frequency;
33
- user_limit: number;
34
- phone_limit: number;
35
- current_period_start: number;
36
- current_period_end: number | null;
37
- additional_user_limit?: number;
38
- additional_phone_limit?: number;
39
- };
40
-
41
- export type OrgPlanNonEnterprise = {
42
- subscription_id: string;
43
- plan_id: AllPlans;
44
- interval: number;
45
- frequency: Frequency;
46
- user_limit: number;
47
- phone_limit: number;
48
- current_period_end: number;
49
- current_period_start: number;
50
- additional_user_limit?: number;
51
- additional_phone_limit?: number;
52
- };
53
-
54
- export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
55
- ? OrgPlanEnterprise
56
- : T extends AllPlans
57
- ? OrgPlanNonEnterprise
58
- : never;
59
-
60
- export type MicrosurveyData = {
61
- key: string;
62
- text: string;
63
- checked: boolean;
64
- }[];
65
-
66
- export type OrgPreferences = {
67
- disable_ai_flagging?: boolean;
68
- disable_ai_responder?: boolean;
69
- disable_allow_exports?: boolean;
70
- sync_phone_contacts?: boolean;
71
- mask_phone_numbers?: boolean;
72
- show_sender_names?: boolean;
73
- closed_chats?: Record<string, number>;
74
- auto_read_muted_chats?: boolean;
75
- };
76
-
77
- type OrgPreferenceKey = keyof OrgPreferences;
78
-
79
- export type OrgPreferencesValue = {
80
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
81
- }[OrgPreferenceKey];
82
-
83
- export type CustomPropertySectionType = {
84
- id: string;
85
- name: string;
86
- order: number;
87
- type: 'chat' | 'ticket';
88
- properties_order?: {
89
- [id: string]: number;
90
- };
91
- };
92
-
93
- export enum CustomPropertyValueType {
94
- DROPDOWN = 'dropdown',
95
- TEXT = 'text',
96
- DATE = 'date',
97
- FILE = 'file',
98
- PICKLIST = 'picklist',
99
- DEPENDENT_DROPDOWN = 'dependent_dropdown',
100
- }
101
-
102
- export type CustomPropertyMetadataType = {
103
- section_id?: string;
104
- };
105
-
106
- export type CustomPropertyTextPropertiesType = {
107
- property_value_type: CustomPropertyValueType.TEXT;
108
- property_value: null;
109
- property_metadata: CustomPropertyMetadataType;
110
- };
111
-
112
- export type CustomPropertyDropdownPropertiesType = {
113
- property_value_type: CustomPropertyValueType.DROPDOWN;
114
- property_value: {
115
- [key: string]: string;
116
- };
117
- property_metadata: CustomPropertyMetadataType;
118
- };
119
-
120
- export type CustomPropertyPicklistPropertiesType = {
121
- property_value_type: CustomPropertyValueType.PICKLIST;
122
- property_value: {
123
- [key: string]: string;
124
- };
125
- property_metadata: CustomPropertyMetadataType;
126
- };
127
-
128
- export type CustomPropertyDependentDropdownPropertiesType = {
129
- property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
130
- property_value: {
131
- level_1: {
132
- value: string;
133
- label: string;
134
- level_2: {
135
- value: string;
136
- label: string;
137
- level_3: {
138
- value: string;
139
- label: string;
140
- }[];
141
- }[];
142
- }[];
143
- };
144
- property_metadata: Merge<
145
- CustomPropertyMetadataType,
146
- {
147
- level_names: {
148
- level_1: string;
149
- level_2: string;
150
- level_3: string;
151
- };
152
- }
153
- >;
154
- };
155
-
156
- export type CustomPropertyFilePropertiesType = {
157
- property_value_type: CustomPropertyValueType.FILE;
158
- property_value: null;
159
- property_metadata: CustomPropertyMetadataType;
160
- };
161
-
162
- export type CustomPropertyDatePropertiesType = {
163
- property_value_type: CustomPropertyValueType.DATE;
164
- property_value: null;
165
- property_metadata: CustomPropertyMetadataType;
166
- };
167
-
168
- export type CustomPropertyType = OverrideProperties<
169
- Tables<'tbl_custom_properties'>,
170
- | CustomPropertyDependentDropdownPropertiesType
171
- | CustomPropertyTextPropertiesType
172
- | CustomPropertyDropdownPropertiesType
173
- | CustomPropertyPicklistPropertiesType
174
- | CustomPropertyFilePropertiesType
175
- | CustomPropertyDatePropertiesType
176
- >;
177
-
178
- export type OrgMetadata = {
179
- phone_number: string;
180
- ticket_prefix: string;
181
- referralSource?: string;
182
- surveyData?: MicrosurveyData;
183
- preferences?: OrgPreferences;
184
- hubspot: {
185
- hubspot_pipelines?: {
186
- id: string;
187
- label: string;
188
- default_stage: { id: string; label: string };
189
- }[];
190
- hubspot_hidden_fields?: string[];
191
- };
192
- partition?: boolean;
193
- tickets: {
194
- prefix?: string;
195
- emoji_ticketing: {
196
- is_enabled?: boolean;
197
- is_message_enabled?: boolean;
198
- message_template?: string;
199
- };
200
- };
201
- attribution?: Object;
202
- affiliate_id?: string;
203
- custom_properties?: {
204
- sections?: CustomPropertySectionType[];
205
- };
206
- rules?: {
207
- limit?: number;
208
- };
209
- ai?: {
210
- flag_prompt?: string;
211
- };
212
- display_language?: string;
213
- };
214
-
215
- export type GroupTemplateType = OverrideProperties<
216
- Tables<'tbl_group_templates'>,
217
- {
218
- group_metadata: {
219
- messagesAdminsOnly?: boolean;
220
- infoAdminsOnly?: boolean;
221
- addMembersAdminsOnly?: boolean;
222
- description?: string;
223
- admins?: string[];
224
- };
225
- }
226
- >;
227
-
228
- type AccessScopes = {
229
- feature_flags: Record<string, boolean>;
230
- integrations: boolean;
231
- rules: boolean;
232
- exports: boolean;
233
- };
234
-
235
- export type OrgMembersType = OverrideProperties<
236
- Tables<'tbl_org_members'>,
237
- {
238
- member_metadata: {
239
- shift_times: {
240
- [day in
241
- | 'monday'
242
- | 'tuesday'
243
- | 'wednesday'
244
- | 'thursday'
245
- | 'friday'
246
- | 'saturday'
247
- | 'sunday']?: [[string, string]];
248
- };
249
- override_status: boolean;
250
- [key: string]: any;
251
- };
252
- }
253
- >;
254
-
255
- export type OrgType = OverrideProperties<
256
- Merge<
257
- Tables<'tbl_org'>,
258
- {
259
- user: OrgMembersType;
260
- members: OrgMembersType[];
261
- phones: Tables<'tbl_org_phones'>[];
262
- labels: Tables<'tbl_org_labels'>[];
263
- quick_replies: Tables<'tbl_quick_replies'>[];
264
- custom_properties: CustomPropertyType[];
265
- subscription_status: 'active' | 'inactive' | 'unpaid';
266
- is_enterprise: boolean;
267
- is_free_trial: boolean;
268
- is_hubspot_connected: boolean;
269
- is_freshdesk_connected: boolean;
270
- is_zohodesk_connected: boolean;
271
- access_scopes: AccessScopes;
272
- rules: Rule[];
273
- phone_limit: number;
274
- user_limit: number;
275
- }
276
- >,
277
- {
278
- org_plan: OrgPlan<AllPlans | Enterprise>;
279
- stripe_customer_details: _Stripe.Customer | null;
280
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
281
- stripe_customer_id: _Stripe.Customer['id'] | null;
282
- org_metadata: OrgMetadata;
283
- }
284
- >;
285
-
286
- export type ChatMemberType = Merge<
287
- Tables<'tbl_chat_participants'>,
288
- Tables<'tbl_contacts'>
289
- >;
290
-
291
- export type ChatType = Merge<
292
- Tables<'view_chats'>,
293
- {
294
- chat_id: string;
295
- latest_message: MessageType | null;
296
- latest_message_timestamp: number | null;
297
- members: { [key: string]: ChatMemberType } | null;
298
- chat_type: 'user' | 'group' | 'business' | 'unknown';
299
- chat_access: { [key: string]: boolean };
300
- label_ids: { [key: string]: boolean };
301
- chat_org_phones?: string[];
302
- message_unread_count: number | null;
303
- hubspot_metadata: {
304
- id: string;
305
- type: string;
306
- hubId: string;
307
- object_data: HubspotObjectDataType;
308
- } | null;
309
- info_admins_only: boolean;
310
- messages_admins_only: boolean;
311
- unread_count?: { [key: string]: number };
312
- active_phone: string | null;
313
- flag_count_map?: { [key: string]: number };
314
- is_archived?: boolean;
315
- is_pinned?: boolean;
316
- closed_at?: number | null;
317
- common_chats?: string[];
318
- freshdesk_metadata?: Record<string, any>;
319
- zohodesk_metadata?: Record<string, any>;
320
- pinned_messages?: {
321
- message_id: string;
322
- pinned_at: number;
323
- expires_at: number;
324
- }[];
325
- group_metadata?: Record<string, any>;
326
- snooze_metadata?: {
327
- snooze_until: number;
328
- snooze_message?: string;
329
- snooze_by?: string;
330
- },
331
- member_unread_count?: {
332
- [key: string]: number;
333
- };
334
- }
335
- >;
336
-
337
- /* -------------------------------------------------------------------------- */
338
- /* MESSAGE */
339
- /* -------------------------------------------------------------------------- */
340
-
341
- export type MediaType = {
342
- path?: string;
343
- mimetype?: string;
344
- filename?: string;
345
- dimensions?: { width: number; height: number; ar: number };
346
- size?: number;
347
- thumbnail?: string;
348
- filedata?: string;
349
- compress?: boolean;
350
- };
351
-
352
- export type MessageType = Merge<
353
- OverrideProperties<
354
- TablesInsert<'tbl_chat_messages'>,
355
- {
356
- message_id: string;
357
- org_id: string;
358
- org_phone: string;
359
- chat_id: string;
360
- message_type: (typeof SUPPORTED_TYPES)[number];
361
- media: MediaType | null;
362
- flag_metadata?: MessageFlagType | null;
363
- poll_info?: PollSendType | null;
364
- poll_results?: PollResultType | null;
365
- delivery_info?: DeliveryInfoType | null;
366
- raw_data?: {
367
- translations?: Record<string, string>;
368
- [key: string]: unknown;
369
- } | null;
370
- }
371
- >,
372
- {
373
- reactions?: ReactionType[];
374
- message_payload?: SingleMessagePayload;
375
- highlight?: number;
376
- is_private_note?: boolean;
377
- }
378
- >;
379
-
380
- export type MessageFlagType = {
381
- status: boolean;
382
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
383
- response_id?: string;
384
- response_timestamp?: string;
385
- response_email?: string;
386
- flagged_by?: string;
387
- flagged_at?: string;
388
- };
389
-
390
- export type MessageSendType = {
391
- queue_id: string;
392
- queue_position: string;
393
- };
394
-
395
- export type MessageBroadcastType = {
396
- broadcast_id: string;
397
- };
398
-
399
- /* -------------------------------------------------------------------------- */
400
-
401
- export type TicketType = OverrideProperties<
402
- Tables<'tbl_chat_tickets'>,
403
- {
404
- label_ids: { [key: string]: boolean };
405
- hubspot_metadata: {
406
- id?: string;
407
- type?: string;
408
- hubId?: string;
409
- pipeline: {
410
- id: string;
411
- label: string;
412
- };
413
- object_data?: HubspotObjectDataType;
414
- } | null;
415
- freshdesk_metadata: Record<string, string>;
416
- close_ticket_metadata?:
417
- | {
418
- closed_by: string;
419
- closed_at: string;
420
- closed_message?: string | null;
421
- send_reply_message_id?: string | null;
422
- }
423
- | any;
424
- }
425
- >;
426
-
427
- export type ContactType = Merge<
428
- Tables<'tbl_contacts'>,
429
- {
430
- chats: ChatType[] | null;
431
- chat_ids?: string[];
432
- }
433
- >;
434
- export type ReactionType = Tables<'tbl_chat_reactions'>;
435
-
436
- export type NotificationType = Tables<'tbl_chat_notifications'>;
437
-
438
- export type ChatAccessType = Merge<
439
- TablesUpdate<'tbl_org_members'>,
440
- {
441
- has_access?: boolean;
442
- email: string | null;
443
- }
444
- >;
445
-
446
- export type QueueJobTypes = {
447
- addedTimestamp: number;
448
- attemptsMade: number;
449
- attemptsStarted: number;
450
- data: {
451
- body: string;
452
- chat_id: string;
453
- };
454
- finishedTimestamp: number;
455
- id: string;
456
- message_id: string;
457
- processedTimestamp: number;
458
- stacktrace: string[];
459
- status: string;
460
- };
461
-
462
- export type PhoneQueueStatusType = {
463
- active: number;
464
- failed: number;
465
- completed: number;
466
- is_running: boolean;
467
- pending: number;
468
- };
469
-
470
- export type PhoneType = OverrideProperties<
471
- Tables<'tbl_org_phones'>,
472
- {
473
- queue_status: {
474
- [key: string]: PhoneQueueStatusType;
475
- };
476
- }
477
- >;
478
-
479
- export type PhoneInfoType = Merge<
480
- Pick<
481
- PhoneType,
482
- | 'created_at'
483
- | 'first_connected_at'
484
- | 'is_ready'
485
- | 'label_ids'
486
- | 'org_id'
487
- | 'org_phone'
488
- | 'phone_id'
489
- | 'phone_image'
490
- | 'phone_name'
491
- | 'qr_code'
492
- | 'updated_at'
493
- | 'wa_state'
494
- >,
495
- {
496
- labels: string[];
497
- }
498
- >;
499
-
500
- /* -------------------------------- CONSTANTS ------------------------------- */
501
-
502
- export const labelColors = [
503
- '#9333EA',
504
- '#0D9488',
505
- '#DB2777',
506
- '#2563EB',
507
- '#F97316',
508
- ];
509
-
510
- export const enumChatColors = [
511
- '#B4876E',
512
- '#A5B337',
513
- '#06CF9C',
514
- '#25D366',
515
- '#02A698',
516
- '#7D9EF1',
517
- '#007BFC',
518
- '#5E47DE',
519
- '#7F66FF',
520
- '#9333EA',
521
- '#FA6533',
522
- '#C4532D',
523
- '#DC2626',
524
- '#FF2E74',
525
- '#DB2777',
526
- ] as const;
527
-
528
- export type RepeatDaysType =
529
- | 'monday'
530
- | 'tuesday'
531
- | 'wednesday'
532
- | 'thursday'
533
- | 'friday'
534
- | 'saturday'
535
- | 'sunday';
536
- export type RepeatIntervalType = 'day' | 'week' | 'month';
537
-
538
- /* -------------------------- LISTING ENDPOINT -------------------------- */
539
-
540
- type ListingType = {
541
- from?: number;
542
- to?: number;
543
- count?: number;
544
- };
545
-
546
- export type ListNotificationsType = Merge<
547
- ListingType,
548
- {
549
- notifictions?: NotificationType[];
550
- }
551
- >;
552
-
553
- export type ListChatMessagesType = Merge<
554
- ListingType,
555
- {
556
- messages?: MessageType[];
557
- }
558
- >;
559
-
560
- export type ListContactsType = Merge<
561
- ListingType,
562
- {
563
- contacts?: ContactType[];
564
- }
565
- >;
566
-
567
- export type ListTicketsType = Merge<
568
- ListingType,
569
- {
570
- tickets?: TicketType[];
571
- }
572
- >;
573
-
574
- export type ListChatsType = Merge<
575
- ListingType,
576
- {
577
- chats?: ChatType[];
578
- }
579
- >;
580
-
581
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
582
-
583
- export const SUPPORTED_TYPES = [
584
- 'chat',
585
- 'sticker',
586
- 'image',
587
- 'video',
588
- 'document',
589
- 'vcard',
590
- 'multi_vcard',
591
- 'audio',
592
- 'ptt',
593
- 'poll_creation',
594
- 'location',
595
- 'ciphertext',
596
- ] as const;
597
-
598
- export type SendMessageContent = {
599
- message_type?: (typeof SUPPORTED_TYPES)[number];
600
- body?: string;
601
- media?: MediaType;
602
- contact_ids?: string[];
603
- location?: {
604
- latitude: string;
605
- longitude: string;
606
- options?: { name?: string; address?: string; url?: string };
607
- };
608
- poll?: PollSendType;
609
- quoted_message_id?: string;
610
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
611
- broadcast_id?: string;
612
- performed_by?: string;
613
- options?: Record<string, any>;
614
- };
615
-
616
- export type QuickReplyContent = Omit<
617
- SendMessageContent,
618
- 'broadcast_id' | 'variables'
619
- >;
620
-
621
- export type ScheduleMessagePayload = {
622
- scheduled_id?: string;
623
- is_repeat?: boolean | null;
624
- scheduled_at: string;
625
- repeat_config?: {
626
- timezone?: string;
627
- repeat_ends?: string;
628
- repeat_interval?: RepeatIntervalType;
629
- repeat_value?: number;
630
- repeat_days?: RepeatDaysType[];
631
- };
632
- };
633
-
634
- export type BroadcastVariableType = {
635
- chat_id: string;
636
- values: { [key: string]: string };
637
- };
638
-
639
- export type BroadcastMessagePayload = SendMessageContent & {
640
- chat_ids: string[];
641
- broadcast_id?: string;
642
- variables?: BroadcastVariableType[];
643
- delay?: number;
644
- };
645
-
646
- export type SingleMessagePayload = SendMessageContent & {
647
- chat_id: string;
648
- job_id?: string;
649
- priority?: number;
650
- };
651
-
652
- export type MessageAttachmentFileTypes =
653
- | 'image'
654
- | 'audio'
655
- | 'document'
656
- | 'video';
657
-
658
- export type AttachmentFileType = {
659
- result: string;
660
- file: File | null;
661
- type: MessageAttachmentFileTypes;
662
- localFileURL?: string;
663
- };
664
-
665
- export type AttachmentLinkType = {
666
- link: {
667
- url: string;
668
- type: MessageAttachmentFileTypes;
669
- name: string;
670
- mimetype?: string;
671
- };
672
- };
673
-
674
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
675
-
676
- /* -------------------------------- BROADCAST ------------------------------- */
677
-
678
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
679
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
680
- } & {
681
- chats: ChatType[];
682
- };
683
-
684
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
685
-
686
- export type ChatLogType = {
687
- log: Tables<'view_chat_logs'>;
688
- operations: Tables<'tbl_chat_logs'>[];
689
- };
690
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
691
-
692
- export type ChatParticipantOperationPayload = {
693
- participant_ids: string[];
694
- chat_ids: string[];
695
- performed_by: string;
696
- };
697
-
698
- export type ChatOperationReturn = {
699
- [participant_id: string]: {
700
- is_success: boolean;
701
- message?: string;
702
- code?: number;
703
- isInviteV4Sent?: boolean;
704
- };
705
- };
706
-
707
- /* ----------------------- BILLING - STRIPE ----------------------- */
708
-
709
- export type StripeSubscription = _Stripe.Subscription;
710
- export type StripeCustomer = _Stripe.Customer;
711
- export type StripeCoupon = _Stripe.Coupon;
712
- export type StripePrice = _Stripe.Price;
713
- export type Stripe = _Stripe;
714
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
715
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
716
-
717
- /* -------------------------------- REALTIME -------------------------------- */
718
-
719
- export type PhoneStateType = {
720
- loading: boolean;
721
- state: string;
722
- sync: number;
723
- percent: number | null;
724
- message?: string;
725
- error?: string;
726
- };
727
-
728
- /* ------------------------------- INTEGRATIONS ----------------------------- */
729
-
730
- export type ChatInfoType = Merge<
731
- ChatType,
732
- {
733
- members: {
734
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
735
- } | null;
736
- chat_labels: string | null;
737
- custom_properties: { [key: string]: string } | null;
738
- }
739
- >;
740
-
741
- export type TicketInfoType = {
742
- chat: ChatInfoType;
743
- message: {
744
- body: string;
745
- chat_id: string;
746
- org_phone: string;
747
- timestamp: string;
748
- media_path: string;
749
- message_id: string;
750
- sender_name: string;
751
- performed_by: string;
752
- sender_phone: string;
753
- };
754
- ticket: {
755
- org_id: string;
756
- status: string;
757
- subject: string;
758
- assignee: string;
759
- due_date: string;
760
- priority: 0 | 1 | 2 | 3 | 4;
761
- raised_by: string;
762
- ticket_id: string;
763
- created_at: string;
764
- assigned_by: string;
765
- ticket_labels: string;
766
- quoted_message_id: string;
767
- ticket_custom_properties: { [key: string]: string } | null;
768
- };
769
- attached_messages: {
770
- body: string;
771
- chat_id: string;
772
- org_phone: string;
773
- timestamp: string;
774
- media_path: string;
775
- message_id: string;
776
- sender_name: string;
777
- performed_by: string;
778
- sender_phone: string;
779
- }[];
780
- };
781
-
782
- export type IntegrationLogObjectType =
783
- | 'chat'
784
- | 'message'
785
- | 'reaction'
786
- | 'ticket'
787
- | 'phone';
788
- export enum IntegrationLogType {
789
- NEW_CHAT = 'chat.created',
790
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
791
- NEW_MESSAGE = 'message.created',
792
- MESSAGE_UPDATED = 'message.updated',
793
- MESSAGE_DELETED = 'message.deleted',
794
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
795
- REACTION_CREATED = 'reaction.created',
796
- REACTION_UPDATED = 'reaction.updated',
797
- NEW_TICKET = 'ticket.created',
798
- TICKET_UPDATED = 'ticket.updated',
799
- TICKET_DELETED = 'ticket.deleted',
800
- MESSAGE_FLAGGED = 'message.flagged',
801
- MESSAGE_UNFLAGGED = 'message.unflagged',
802
- PHONE_DISCONNECTED = 'org.phone.disconnected',
803
- PHONE_CONNECTED = 'org.phone.connected',
804
- PHONE_UPDATED = 'org.phone.updated',
805
- PHONE_QR_UPDATED = 'org.phone.qr',
806
- }
807
-
808
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
809
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
810
- ? TicketInfoType
811
- : T extends IntegrationLogType.NEW_CHAT
812
- ? Tables<'tbl_chats'>
813
- : T extends
814
- | IntegrationLogType.NEW_MESSAGE
815
- | IntegrationLogType.MESSAGE_UPDATED
816
- | IntegrationLogType.MESSAGE_DELETED
817
- | IntegrationLogType.MESSAGE_ACK_UPDATED
818
- | IntegrationLogType.MESSAGE_FLAGGED
819
- | IntegrationLogType.MESSAGE_UNFLAGGED
820
- ? Tables<'tbl_chat_messages'>
821
- : T extends
822
- | IntegrationLogType.REACTION_CREATED
823
- | IntegrationLogType.REACTION_UPDATED
824
- ? Tables<'tbl_chat_reactions'>
825
- : T extends
826
- | IntegrationLogType.PHONE_DISCONNECTED
827
- | IntegrationLogType.PHONE_CONNECTED
828
- | IntegrationLogType.PHONE_UPDATED
829
- | IntegrationLogType.PHONE_QR_UPDATED
830
- ? Tables<'tbl_org_phones'>
831
- : {
832
- [key: string]: unknown;
833
- };
834
-
835
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
836
- OverrideProperties<
837
- Tables<'tbl_integration_logs'>,
838
- {
839
- integration_name: T;
840
- metadata: {
841
- event: IntegrationLogMetadataType<T> & {
842
- event_type: string;
843
- org_id: string;
844
- previous_attributes: {
845
- [key: string]: unknown;
846
- };
847
- };
848
- hook_id: string;
849
- name: string;
850
- };
851
- }
852
- >;
853
-
854
- export type APIAuthDetails = {
855
- org_details: Tables<'view_org'> | null;
856
- phone_details: Tables<'tbl_org_phones'> | null;
857
- token_details: Tables<'tbl_integration_tokens'> | null;
858
- };
859
-
860
- export type WebhookDataType = OverrideProperties<
861
- Tables<'tbl_integration_hooks'>,
862
- {
863
- integration_name: string[];
864
- }
865
- >;
866
-
867
- export type HubspotObjectDataType = {
868
- createdAt: string;
869
- archived: boolean;
870
- id: string;
871
- type: 'contacts' | 'tickets' | 'companies';
872
- properties: Record<
873
- string,
874
- {
875
- groupLabel: string;
876
- groupName: string;
877
- propertyKeyName: string;
878
- propertyKey: string;
879
- propertyInternalValue: string;
880
- propertyValue: string;
881
- propertyType: string;
882
- propertyFieldType: string;
883
- }[]
884
- >;
885
- };
886
-
887
- /* ---------------------------- USER PREFERENCES ---------------------------- */
888
-
889
- export type UserPreferences = {
890
- theme: 'light' | 'dark';
891
- language: 'en' | 'es';
892
- left_sidebar_open: boolean;
893
- right_sidepanel_open: boolean;
894
- sync_wa_unread_count: boolean;
895
- pinned_chats: string[];
896
- archived_chats: string[];
897
- closed_chats: Record<string, number>;
898
- periskope_chat_limit: number;
899
- notifications: Record<string, boolean>;
900
- };
901
-
902
- /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
903
-
904
- export interface MostActiveMember {
905
- sender_phone: string;
906
- total_messages: number;
907
- }
908
-
909
- export interface GroupAnalyticsResult {
910
- total_messages: number;
911
- total_joins: number;
912
- total_leaves: number;
913
- total_removes: number;
914
- total_reactions: number;
915
- most_active_members: MostActiveMember[];
916
- }
917
-
918
- export interface TimeRange {
919
- startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
920
- endDateTime: string;
921
- }
922
-
923
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
924
-
925
- export type PollSendType = {
926
- pollName: string;
927
- pollOptions: string[];
928
- options?: {
929
- allowMultipleAnswers?: boolean;
930
- messageSecret?: number[] | null;
931
- pollId?: string;
932
- };
933
- };
934
-
935
- export type PollResultType = {
936
- [name: string]: Record<string, string>;
937
- };
938
-
939
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
940
-
941
- export type CreateGroupOptions = {
942
- messagesAdminsOnly?: boolean;
943
- infoAdminsOnly?: boolean;
944
- addMembersAdminsOnly?: boolean;
945
- image?: string;
946
- name?: string;
947
- description?: string;
948
- initiated_by?: string;
949
- admins?: string[];
950
- };
951
-
952
- /* ------------------------------ DELIVERY INFO ----------------------------- */
953
-
954
- export type DeliveryInfoType = {
955
- delivered: Record<string, number | undefined>;
956
- read: Record<string, number | undefined>;
957
- pending: string[];
958
- read_count: number;
959
- delivered_count: number;
960
- };
961
-
962
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
963
-
964
- export type OrgCreditsType = {
965
- org_id: string;
966
- recurring_allowance: number; // recurring credits replenished every cycle
967
- recurring_balance: number; // recurring credits remaining in current cycle
968
- topup_balance: number; // topup credits remaining
969
- total_credits_used: number; // total credits used in current cycle
970
- next_renewal_date: string;
971
- topup_credits_used: number; // topup credits used in current cycle
972
- recurring_credits_used: number; // recurring credits used in current cycle
973
- };
974
-
975
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
976
-
977
- export type ChatRuleInfoType = Merge<
978
- Pick<
979
- Tables<'view_chats'>,
980
- | 'assigned_to'
981
- | 'chat_id'
982
- | 'chat_name'
983
- | 'chat_type'
984
- | 'created_at'
985
- | 'group_description'
986
- | 'info_admins_only'
987
- | 'org_id'
988
- | 'org_phone'
989
- | 'chat_org_phones'
990
- | 'messages_admins_only'
991
- | 'custom_properties'
992
- | 'initiated_by'
993
- >,
994
- {
995
- has_flagged_messages: boolean;
996
- labels: string[];
997
- members: string[];
998
- custom_properties: { [key: string]: string } | null;
999
- }
1000
- >;
1001
-
1002
- export type SenderRuleInfoType = Merge<
1003
- Omit<
1004
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1005
- | 'verified_name'
1006
- | 'verified_level'
1007
- | 'updated_at'
1008
- | 'short_name'
1009
- | 'pushname'
1010
- | 'periskope_name'
1011
- | 'org_phone'
1012
- | 'number'
1013
- | 'name'
1014
- | 'label_ids'
1015
- | 'is_wa_contact'
1016
- | 'is_user'
1017
- | 'is_my_contact'
1018
- | 'is_me'
1019
- | 'is_imported'
1020
- | 'is_group'
1021
- | 'is_blocked'
1022
- | 'contact_color'
1023
- | 'business_profile'
1024
- | 'id'
1025
- | 'contact_image'
1026
- | 'contact_type'
1027
- | 'chat_id'
1028
- | 'is_business'
1029
- | 'is_enterprise'
1030
- | 'is_super_admin'
1031
- >,
1032
- {
1033
- is_internal: boolean;
1034
- labels: string[] | null;
1035
- }
1036
- >;
1037
-
1038
- export type MessageRuleInfoType = {
1039
- chat: ChatRuleInfoType;
1040
- sender: SenderRuleInfoType;
1041
- message: OverrideProperties<
1042
- Omit<
1043
- Tables<'tbl_chat_messages'>,
1044
- | 'vcards'
1045
- | 'updated_at'
1046
- | 'unique_id'
1047
- | 'token'
1048
- | 'to'
1049
- | 'sent_message_id'
1050
- | 'raw_data'
1051
- | 'delivery_info'
1052
- | 'poll_results'
1053
- | 'poll_info'
1054
- | 'order_id'
1055
- | 'mentioned_ids'
1056
- | 'media_key'
1057
- | 'location'
1058
- | 'links'
1059
- | 'is_status'
1060
- | 'is_starred'
1061
- | 'is_gif'
1062
- | 'is_forwarded'
1063
- | 'is_ephemeral'
1064
- | 'is_deleted'
1065
- | 'fts'
1066
- | 'quoted_message_id'
1067
- | 'invite_v4'
1068
- | 'id'
1069
- | 'has_reaction'
1070
- | 'has_media'
1071
- | 'duration'
1072
- | 'broadcast'
1073
- | 'broadcast_id'
1074
- | 'device_type'
1075
- | 'forwarding_score'
1076
- | 'from'
1077
- | 'from_me'
1078
- | 'prev_body'
1079
- | 'flag_response_time'
1080
- | 'flag_metadata'
1081
- | 'ack'
1082
- >,
1083
- {
1084
- media: MediaType | null;
1085
- }
1086
- >;
1087
- };
1088
-
1089
- export type ReactionRuleInfoType = {
1090
- chat: ChatRuleInfoType;
1091
- sender: SenderRuleInfoType;
1092
- message: MessageRuleInfoType['message'];
1093
- reaction: Pick<
1094
- Tables<'tbl_chat_reactions'>,
1095
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1096
- >;
1097
- };
1098
-
1099
- export type TicketRuleInfoType = {
1100
- chat: ChatRuleInfoType;
1101
- sender: SenderRuleInfoType;
1102
- ticket: Merge<
1103
- Pick<
1104
- Tables<'tbl_chat_tickets'>,
1105
- | 'org_id'
1106
- | 'status'
1107
- | 'chat_id'
1108
- | 'subject'
1109
- | 'assignee'
1110
- | 'due_date'
1111
- | 'priority'
1112
- | 'raised_by'
1113
- | 'ticket_id'
1114
- | 'created_at'
1115
- | 'is_deleted'
1116
- >,
1117
- {
1118
- labels: string[] | null;
1119
- custom_properties: { [key: string]: string } | null;
1120
- }
1121
- >;
1122
- message: MessageRuleInfoType['message'];
1123
- };
1124
- export type FeatureFlagReturnType = Record<string, boolean>;
1125
-
1126
- export type RuleLogsType = OverrideProperties<
1127
- Tables<'tbl_rules_logs'>,
1128
- {
1129
- actions_progress: {
1130
- action_id: string;
1131
- action_type: Rule['actions'][number]['type'];
1132
- action_delay: Rule['actions'][number]['delay'];
1133
- ran_at: string | null;
1134
- action_status: 'success' | 'failed' | 'pending';
1135
- action_response: {
1136
- success: boolean;
1137
- data: Record<string, unknown> | null;
1138
- error: {
1139
- message: string;
1140
- name: string;
1141
- stack?: string;
1142
- _error?: Error | Record<string, unknown>;
1143
- } | null;
1144
- };
1145
- }[];
1146
- metadata: {
1147
- conditions: Rule['conditions'];
1148
- actions: Rule['actions'];
1149
- rule_metadata: Pick<
1150
- Rule,
1151
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
1152
- >;
1153
- data: Record<string, unknown>;
1154
- };
1155
- conditions_progress: {
1156
- is_valid: boolean;
1157
- validation_progress: Record<
1158
- string,
1159
- {
1160
- res: boolean;
1161
- filter: Filter;
1162
- value: unknown;
1163
- }
1164
- >;
1165
- checked_at: string | null;
1166
- };
1167
- }
1168
- >;
1169
-
1170
- /************************** TASKS ***************************/
1171
-
1172
- export type TaskType = OverrideProperties<
1173
- Tables<'tbl_org_tasks'>,
1174
- {
1175
- reminder_setting: {
1176
- remind_in:
1177
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1178
- | string
1179
- | null;
1180
- repeat?: {
1181
- frequency: number;
1182
- interval: 'days' | 'weeks' | 'months' | 'years';
1183
- end: 'never' | 'after' | 'on';
1184
- on?: string;
1185
- };
1186
- } | null;
1187
- associated_object_metadata:
1188
- | {
1189
- type: 'chat';
1190
- index: 'chat_id';
1191
- id: string;
1192
- object: ChatType;
1193
- }
1194
- | {
1195
- type: 'message';
1196
- index: 'message_id';
1197
- id: string;
1198
- object: MessageType;
1199
- }
1200
- | {
1201
- type: 'ticket';
1202
- index: 'ticket_id';
1203
- id: string;
1204
- object: TicketType;
1205
- }
1206
- | null;
1207
- status: 'open' | 'inprogress' | 'closed';
1208
- priority: 1 | 2 | 3;
1209
- completed_metadata?: {
1210
- completed_at: string;
1211
- completed_by: string;
1212
- } | null;
1213
- type: 'todo' | 'chat' | 'message' | 'ticket';
1214
- }
1215
- >;
1216
-
1217
- type Choice = {
1218
- id: number;
1219
- label: string;
1220
- value: string;
1221
- position: number;
1222
- };
1223
-
1224
- export type FreshdeskCustomFieldType = {
1225
- id: number;
1226
- name: string;
1227
- label: string;
1228
- position: number;
1229
- required_for_agents: boolean;
1230
- archived: boolean;
1231
- customers_can_edit: boolean;
1232
- label_for_customers: string;
1233
- required_for_customers: boolean;
1234
- customers_can_filter: boolean;
1235
- required_for_closure: boolean;
1236
- displayed_to_customers: boolean;
1237
- type: string;
1238
- default: boolean;
1239
- created_at: string;
1240
- updated_at: string;
1241
- choices?: Choice[];
1242
- };
1
+ import type { default as _Stripe } from 'stripe';
2
+ import { Merge, OverrideProperties } from 'type-fest';
3
+ import { Filter, Rule } from './rules.types';
4
+ import { Tables, TablesInsert, TablesUpdate } from './supabase.types';
5
+
6
+ /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
7
+
8
+ /* ------------------------------ PERISKOPE TYPES ------------------------------ */
9
+
10
+ export enum AllPlans {
11
+ FREE_TRIAL = 'free-trial',
12
+ // MONTHLY_STARTER = 'monthly-starter',
13
+ // YEARLY_STARTER = 'yearly-starter',
14
+ // MONTHLY_PRO = 'monthly-pro',
15
+ // YEARLY_PRO = 'yearly-pro',
16
+ ENTERPRISE = 'enterprise',
17
+ MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
18
+ YEARLY_STARTER_SINGLE = 'yearly-starter-single',
19
+ MONTHLY_PRO_SINGLE = 'monthly-pro-single',
20
+ YEARLY_PRO_SINGLE = 'yearly-pro-single',
21
+ }
22
+
23
+ export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
24
+
25
+ export type Enterprise = `${string}-enterprise`;
26
+
27
+ export type OrgPlanEnterprise = {
28
+ subscription_id: string;
29
+ plan_id: Enterprise;
30
+ interval: number;
31
+ frequency: Frequency;
32
+ user_limit: number;
33
+ phone_limit: number;
34
+ current_period_start: number;
35
+ current_period_end: number | null;
36
+ additional_user_limit?: number;
37
+ additional_phone_limit?: number;
38
+ };
39
+
40
+ export type OrgPlanNonEnterprise = {
41
+ subscription_id: string;
42
+ plan_id: AllPlans;
43
+ interval: number;
44
+ frequency: Frequency;
45
+ user_limit: number;
46
+ phone_limit: number;
47
+ current_period_end: number;
48
+ current_period_start: number;
49
+ additional_user_limit?: number;
50
+ additional_phone_limit?: number;
51
+ };
52
+
53
+ export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
54
+ ? OrgPlanEnterprise
55
+ : T extends AllPlans
56
+ ? OrgPlanNonEnterprise
57
+ : never;
58
+
59
+ export type MicrosurveyData = {
60
+ key: string;
61
+ text: string;
62
+ checked: boolean;
63
+ }[];
64
+
65
+ export type OrgPreferences = {
66
+ disable_ai_flagging?: boolean;
67
+ disable_ai_responder?: boolean;
68
+ disable_allow_exports?: boolean;
69
+ sync_phone_contacts?: boolean;
70
+ mask_phone_numbers?: boolean;
71
+ show_sender_names?: boolean;
72
+ closed_chats?: Record<string, number>;
73
+ auto_read_muted_chats?: boolean;
74
+ member_permissions?: Record<string, boolean>;
75
+ };
76
+
77
+ type OrgPreferenceKey = keyof OrgPreferences;
78
+
79
+ export type OrgPreferencesValue = {
80
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
81
+ }[OrgPreferenceKey];
82
+
83
+ export type CustomPropertySectionType = {
84
+ id: string;
85
+ name: string;
86
+ order: number;
87
+ type: 'chat' | 'ticket';
88
+ properties_order?: {
89
+ [id: string]: number;
90
+ };
91
+ };
92
+
93
+ export enum CustomPropertyValueType {
94
+ DROPDOWN = 'dropdown',
95
+ TEXT = 'text',
96
+ DATE = 'date',
97
+ FILE = 'file',
98
+ PICKLIST = 'picklist',
99
+ DEPENDENT_DROPDOWN = 'dependent_dropdown',
100
+ }
101
+
102
+ export type CustomPropertyMetadataType = {
103
+ section_id?: string;
104
+ };
105
+
106
+ export type CustomPropertyTextPropertiesType = {
107
+ property_value_type: CustomPropertyValueType.TEXT;
108
+ property_value: null;
109
+ property_metadata: CustomPropertyMetadataType;
110
+ };
111
+
112
+ export type CustomPropertyDropdownPropertiesType = {
113
+ property_value_type: CustomPropertyValueType.DROPDOWN;
114
+ property_value: {
115
+ [key: string]: string;
116
+ };
117
+ property_metadata: CustomPropertyMetadataType;
118
+ };
119
+
120
+ export type CustomPropertyPicklistPropertiesType = {
121
+ property_value_type: CustomPropertyValueType.PICKLIST;
122
+ property_value: {
123
+ [key: string]: string;
124
+ };
125
+ property_metadata: CustomPropertyMetadataType;
126
+ };
127
+
128
+ export type CustomPropertyDependentDropdownPropertiesType = {
129
+ property_value_type: CustomPropertyValueType.DEPENDENT_DROPDOWN;
130
+ property_value: {
131
+ level_1: {
132
+ value: string;
133
+ label: string;
134
+ level_2: {
135
+ value: string;
136
+ label: string;
137
+ level_3: {
138
+ value: string;
139
+ label: string;
140
+ }[];
141
+ }[];
142
+ }[];
143
+ };
144
+ property_metadata: Merge<
145
+ CustomPropertyMetadataType,
146
+ {
147
+ level_names: {
148
+ level_1: string;
149
+ level_2: string;
150
+ level_3: string;
151
+ };
152
+ }
153
+ >;
154
+ };
155
+
156
+ export type CustomPropertyFilePropertiesType = {
157
+ property_value_type: CustomPropertyValueType.FILE;
158
+ property_value: null;
159
+ property_metadata: CustomPropertyMetadataType;
160
+ };
161
+
162
+ export type CustomPropertyDatePropertiesType = {
163
+ property_value_type: CustomPropertyValueType.DATE;
164
+ property_value: null;
165
+ property_metadata: CustomPropertyMetadataType;
166
+ };
167
+
168
+ export type CustomPropertyType = OverrideProperties<
169
+ Tables<'tbl_custom_properties'>,
170
+ | CustomPropertyDependentDropdownPropertiesType
171
+ | CustomPropertyTextPropertiesType
172
+ | CustomPropertyDropdownPropertiesType
173
+ | CustomPropertyPicklistPropertiesType
174
+ | CustomPropertyFilePropertiesType
175
+ | CustomPropertyDatePropertiesType
176
+ >;
177
+
178
+ export type OrgMetadata = {
179
+ phone_number: string;
180
+ ticket_prefix: string;
181
+ referralSource?: string;
182
+ surveyData?: MicrosurveyData;
183
+ preferences?: OrgPreferences;
184
+ hubspot: {
185
+ hubspot_pipelines?: {
186
+ id: string;
187
+ label: string;
188
+ default_stage: { id: string; label: string };
189
+ }[];
190
+ hubspot_hidden_fields?: string[];
191
+ };
192
+ partition?: boolean;
193
+ tickets: {
194
+ prefix?: string;
195
+ emoji_ticketing: {
196
+ is_enabled?: boolean;
197
+ is_message_enabled?: boolean;
198
+ message_template?: string;
199
+ };
200
+ };
201
+ attribution?: Object;
202
+ affiliate_id?: string;
203
+ custom_properties?: {
204
+ sections?: CustomPropertySectionType[];
205
+ };
206
+ rules?: {
207
+ limit?: number;
208
+ };
209
+ ai?: {
210
+ flag_prompt?: string;
211
+ };
212
+ display_language?: string;
213
+ };
214
+
215
+ export type GroupTemplateType = OverrideProperties<
216
+ Tables<'tbl_group_templates'>,
217
+ {
218
+ group_metadata: {
219
+ messagesAdminsOnly?: boolean;
220
+ infoAdminsOnly?: boolean;
221
+ addMembersAdminsOnly?: boolean;
222
+ description?: string;
223
+ admins?: string[];
224
+ };
225
+ }
226
+ >;
227
+
228
+ type AccessScopes = {
229
+ feature_flags: Record<string, boolean>;
230
+ integrations: boolean;
231
+ rules: boolean;
232
+ exports: boolean;
233
+ };
234
+
235
+ export type OrgMembersType = OverrideProperties<
236
+ Tables<'tbl_org_members'>,
237
+ {
238
+ member_metadata: {
239
+ shift_times: {
240
+ [day in
241
+ | 'monday'
242
+ | 'tuesday'
243
+ | 'wednesday'
244
+ | 'thursday'
245
+ | 'friday'
246
+ | 'saturday'
247
+ | 'sunday']?: [[string, string]];
248
+ };
249
+ override_status: boolean;
250
+ [key: string]: any;
251
+ };
252
+ }
253
+ >;
254
+
255
+ export type OrgType = OverrideProperties<
256
+ Merge<
257
+ Tables<'tbl_org'>,
258
+ {
259
+ user: OrgMembersType;
260
+ members: OrgMembersType[];
261
+ phones: Tables<'tbl_org_phones'>[];
262
+ labels: Tables<'tbl_org_labels'>[];
263
+ quick_replies: Tables<'tbl_quick_replies'>[];
264
+ custom_properties: CustomPropertyType[];
265
+ subscription_status: 'active' | 'inactive' | 'unpaid';
266
+ is_enterprise: boolean;
267
+ is_free_trial: boolean;
268
+ is_hubspot_connected: boolean;
269
+ is_freshdesk_connected: boolean;
270
+ is_zohodesk_connected: boolean;
271
+ access_scopes: AccessScopes;
272
+ rules: Rule[];
273
+ phone_limit: number;
274
+ user_limit: number;
275
+ }
276
+ >,
277
+ {
278
+ org_plan: OrgPlan<AllPlans | Enterprise>;
279
+ stripe_customer_details: _Stripe.Customer | null;
280
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
281
+ stripe_customer_id: _Stripe.Customer['id'] | null;
282
+ org_metadata: OrgMetadata;
283
+ }
284
+ >;
285
+
286
+ export type ChatMemberType = Merge<
287
+ Tables<'tbl_chat_participants'>,
288
+ Tables<'tbl_contacts'>
289
+ >;
290
+
291
+ export type ChatType = Merge<
292
+ Tables<'view_chats'>,
293
+ {
294
+ chat_id: string;
295
+ latest_message: MessageType | null;
296
+ latest_message_timestamp: number | null;
297
+ members: { [key: string]: ChatMemberType } | null;
298
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
299
+ chat_access: { [key: string]: boolean };
300
+ label_ids: { [key: string]: boolean };
301
+ chat_org_phones?: string[];
302
+ message_unread_count: number | null;
303
+ hubspot_metadata: {
304
+ id: string;
305
+ type: string;
306
+ hubId: string;
307
+ object_data: HubspotObjectDataType;
308
+ } | null;
309
+ info_admins_only: boolean;
310
+ messages_admins_only: boolean;
311
+ unread_count?: { [key: string]: number };
312
+ active_phone: string | null;
313
+ flag_count_map?: { [key: string]: number };
314
+ is_archived?: boolean;
315
+ is_pinned?: boolean;
316
+ closed_at?: number | null;
317
+ common_chats?: string[];
318
+ freshdesk_metadata?: Record<string, any>;
319
+ zohodesk_metadata?: Record<string, any>;
320
+ pinned_messages?: {
321
+ message_id: string;
322
+ pinned_at: number;
323
+ expires_at: number;
324
+ }[];
325
+ group_metadata?: Record<string, any>;
326
+ snooze_metadata?: {
327
+ snooze_until: number;
328
+ snooze_message?: string;
329
+ snooze_by?: string;
330
+ };
331
+ member_unread_count?: {
332
+ [key: string]: number;
333
+ };
334
+ }
335
+ >;
336
+
337
+ /* -------------------------------------------------------------------------- */
338
+ /* MESSAGE */
339
+ /* -------------------------------------------------------------------------- */
340
+
341
+ export type MediaType = {
342
+ path?: string;
343
+ mimetype?: string;
344
+ filename?: string;
345
+ dimensions?: { width: number; height: number; ar: number };
346
+ size?: number;
347
+ thumbnail?: string;
348
+ filedata?: string;
349
+ compress?: boolean;
350
+ };
351
+
352
+ export type MessageType = Merge<
353
+ OverrideProperties<
354
+ TablesInsert<'tbl_chat_messages'>,
355
+ {
356
+ message_id: string;
357
+ org_id: string;
358
+ org_phone: string;
359
+ chat_id: string;
360
+ message_type: (typeof SUPPORTED_TYPES)[number];
361
+ media: MediaType | null;
362
+ flag_metadata?: MessageFlagType | null;
363
+ poll_info?: PollSendType | null;
364
+ poll_results?: PollResultType | null;
365
+ delivery_info?: DeliveryInfoType | null;
366
+ raw_data?: {
367
+ translations?: Record<string, string>;
368
+ [key: string]: unknown;
369
+ } | null;
370
+ }
371
+ >,
372
+ {
373
+ reactions?: ReactionType[];
374
+ message_payload?: SingleMessagePayload;
375
+ highlight?: number;
376
+ is_private_note?: boolean;
377
+ }
378
+ >;
379
+
380
+ export type MessageFlagType = {
381
+ status: boolean;
382
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
383
+ response_id?: string;
384
+ response_timestamp?: string;
385
+ response_email?: string;
386
+ flagged_by?: string;
387
+ flagged_at?: string;
388
+ };
389
+
390
+ export type MessageSendType = {
391
+ queue_id: string;
392
+ queue_position: string;
393
+ };
394
+
395
+ export type MessageBroadcastType = {
396
+ broadcast_id: string;
397
+ };
398
+
399
+ /* -------------------------------------------------------------------------- */
400
+
401
+ export type TicketType = OverrideProperties<
402
+ Tables<'tbl_chat_tickets'>,
403
+ {
404
+ label_ids: { [key: string]: boolean };
405
+ hubspot_metadata: {
406
+ id?: string;
407
+ type?: string;
408
+ hubId?: string;
409
+ pipeline: {
410
+ id: string;
411
+ label: string;
412
+ };
413
+ object_data?: HubspotObjectDataType;
414
+ } | null;
415
+ freshdesk_metadata: Record<string, string>;
416
+ close_ticket_metadata?:
417
+ | {
418
+ closed_by: string;
419
+ closed_at: string;
420
+ closed_message?: string | null;
421
+ send_reply_message_id?: string | null;
422
+ }
423
+ | any;
424
+ }
425
+ >;
426
+
427
+ export type ContactType = Merge<
428
+ Tables<'tbl_contacts'>,
429
+ {
430
+ chats: ChatType[] | null;
431
+ chat_ids?: string[];
432
+ }
433
+ >;
434
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
435
+
436
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
437
+
438
+ export type ChatAccessType = Merge<
439
+ TablesUpdate<'tbl_org_members'>,
440
+ {
441
+ has_access?: boolean;
442
+ email: string | null;
443
+ }
444
+ >;
445
+
446
+ export type QueueJobTypes = {
447
+ addedTimestamp: number;
448
+ attemptsMade: number;
449
+ attemptsStarted: number;
450
+ data: {
451
+ body: string;
452
+ chat_id: string;
453
+ };
454
+ finishedTimestamp: number;
455
+ id: string;
456
+ message_id: string;
457
+ processedTimestamp: number;
458
+ stacktrace: string[];
459
+ status: string;
460
+ };
461
+
462
+ export type PhoneQueueStatusType = {
463
+ active: number;
464
+ failed: number;
465
+ completed: number;
466
+ is_running: boolean;
467
+ pending: number;
468
+ };
469
+
470
+ export type PhoneType = OverrideProperties<
471
+ Tables<'tbl_org_phones'>,
472
+ {
473
+ queue_status: {
474
+ [key: string]: PhoneQueueStatusType;
475
+ };
476
+ }
477
+ >;
478
+
479
+ export type PhoneInfoType = Merge<
480
+ Pick<
481
+ PhoneType,
482
+ | 'created_at'
483
+ | 'first_connected_at'
484
+ | 'is_ready'
485
+ | 'label_ids'
486
+ | 'org_id'
487
+ | 'org_phone'
488
+ | 'phone_id'
489
+ | 'phone_image'
490
+ | 'phone_name'
491
+ | 'qr_code'
492
+ | 'updated_at'
493
+ | 'wa_state'
494
+ >,
495
+ {
496
+ labels: string[];
497
+ }
498
+ >;
499
+
500
+ /* -------------------------------- CONSTANTS ------------------------------- */
501
+
502
+ export const labelColors = [
503
+ '#9333EA',
504
+ '#0D9488',
505
+ '#DB2777',
506
+ '#2563EB',
507
+ '#F97316',
508
+ ];
509
+
510
+ export const enumChatColors = [
511
+ '#B4876E',
512
+ '#A5B337',
513
+ '#06CF9C',
514
+ '#25D366',
515
+ '#02A698',
516
+ '#7D9EF1',
517
+ '#007BFC',
518
+ '#5E47DE',
519
+ '#7F66FF',
520
+ '#9333EA',
521
+ '#FA6533',
522
+ '#C4532D',
523
+ '#DC2626',
524
+ '#FF2E74',
525
+ '#DB2777',
526
+ ] as const;
527
+
528
+ export type RepeatDaysType =
529
+ | 'monday'
530
+ | 'tuesday'
531
+ | 'wednesday'
532
+ | 'thursday'
533
+ | 'friday'
534
+ | 'saturday'
535
+ | 'sunday';
536
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
537
+
538
+ /* -------------------------- LISTING ENDPOINT -------------------------- */
539
+
540
+ type ListingType = {
541
+ from?: number;
542
+ to?: number;
543
+ count?: number;
544
+ };
545
+
546
+ export type ListNotificationsType = Merge<
547
+ ListingType,
548
+ {
549
+ notifictions?: NotificationType[];
550
+ }
551
+ >;
552
+
553
+ export type ListChatMessagesType = Merge<
554
+ ListingType,
555
+ {
556
+ messages?: MessageType[];
557
+ }
558
+ >;
559
+
560
+ export type ListContactsType = Merge<
561
+ ListingType,
562
+ {
563
+ contacts?: ContactType[];
564
+ }
565
+ >;
566
+
567
+ export type ListTicketsType = Merge<
568
+ ListingType,
569
+ {
570
+ tickets?: TicketType[];
571
+ }
572
+ >;
573
+
574
+ export type ListChatsType = Merge<
575
+ ListingType,
576
+ {
577
+ chats?: ChatType[];
578
+ }
579
+ >;
580
+
581
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
582
+
583
+ export const SUPPORTED_TYPES = [
584
+ 'chat',
585
+ 'sticker',
586
+ 'image',
587
+ 'video',
588
+ 'document',
589
+ 'vcard',
590
+ 'multi_vcard',
591
+ 'audio',
592
+ 'ptt',
593
+ 'poll_creation',
594
+ 'location',
595
+ 'ciphertext',
596
+ ] as const;
597
+
598
+ export type SendMessageContent = {
599
+ message_type?: (typeof SUPPORTED_TYPES)[number];
600
+ body?: string;
601
+ media?: MediaType;
602
+ contact_ids?: string[];
603
+ location?: {
604
+ latitude: string;
605
+ longitude: string;
606
+ options?: { name?: string; address?: string; url?: string };
607
+ };
608
+ poll?: PollSendType;
609
+ quoted_message_id?: string;
610
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
611
+ broadcast_id?: string;
612
+ performed_by?: string;
613
+ options?: Record<string, any>;
614
+ };
615
+
616
+ export type QuickReplyContent = Omit<
617
+ SendMessageContent,
618
+ 'broadcast_id' | 'variables'
619
+ >;
620
+
621
+ export type ScheduleMessagePayload = {
622
+ scheduled_id?: string;
623
+ is_repeat?: boolean | null;
624
+ scheduled_at: string;
625
+ repeat_config?: {
626
+ timezone?: string;
627
+ repeat_ends?: string;
628
+ repeat_interval?: RepeatIntervalType;
629
+ repeat_value?: number;
630
+ repeat_days?: RepeatDaysType[];
631
+ };
632
+ };
633
+
634
+ export type BroadcastVariableType = {
635
+ chat_id: string;
636
+ values: { [key: string]: string };
637
+ };
638
+
639
+ export type BroadcastMessagePayload = SendMessageContent & {
640
+ chat_ids: string[];
641
+ broadcast_id?: string;
642
+ variables?: BroadcastVariableType[];
643
+ delay?: number;
644
+ };
645
+
646
+ export type SingleMessagePayload = SendMessageContent & {
647
+ chat_id: string;
648
+ job_id?: string;
649
+ priority?: number;
650
+ };
651
+
652
+ export type MessageAttachmentFileTypes =
653
+ | 'image'
654
+ | 'audio'
655
+ | 'document'
656
+ | 'video';
657
+
658
+ export type AttachmentFileType = {
659
+ result: string;
660
+ file: File | null;
661
+ type: MessageAttachmentFileTypes;
662
+ localFileURL?: string;
663
+ };
664
+
665
+ export type AttachmentLinkType = {
666
+ link: {
667
+ url: string;
668
+ type: MessageAttachmentFileTypes;
669
+ name: string;
670
+ mimetype?: string;
671
+ };
672
+ };
673
+
674
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
675
+
676
+ /* -------------------------------- BROADCAST ------------------------------- */
677
+
678
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
679
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
680
+ } & {
681
+ chats: ChatType[];
682
+ };
683
+
684
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
685
+
686
+ export type ChatLogType = {
687
+ log: Tables<'view_chat_logs'>;
688
+ operations: Tables<'tbl_chat_logs'>[];
689
+ };
690
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
691
+
692
+ export type ChatParticipantOperationPayload = {
693
+ participant_ids: string[];
694
+ chat_ids: string[];
695
+ performed_by: string;
696
+ };
697
+
698
+ export type ChatOperationReturn = {
699
+ [participant_id: string]: {
700
+ is_success: boolean;
701
+ message?: string;
702
+ code?: number;
703
+ isInviteV4Sent?: boolean;
704
+ };
705
+ };
706
+
707
+ /* ----------------------- BILLING - STRIPE ----------------------- */
708
+
709
+ export type StripeSubscription = _Stripe.Subscription;
710
+ export type StripeCustomer = _Stripe.Customer;
711
+ export type StripeCoupon = _Stripe.Coupon;
712
+ export type StripePrice = _Stripe.Price;
713
+ export type Stripe = _Stripe;
714
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
715
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
716
+
717
+ /* -------------------------------- REALTIME -------------------------------- */
718
+
719
+ export type PhoneStateType = {
720
+ loading: boolean;
721
+ state: string;
722
+ sync: number;
723
+ percent: number | null;
724
+ message?: string;
725
+ error?: string;
726
+ };
727
+
728
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
729
+
730
+ export type ChatInfoType = Merge<
731
+ ChatType,
732
+ {
733
+ members: {
734
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
735
+ } | null;
736
+ chat_labels: string | null;
737
+ custom_properties: { [key: string]: string } | null;
738
+ }
739
+ >;
740
+
741
+ export type TicketInfoType = {
742
+ chat: ChatInfoType;
743
+ message: {
744
+ body: string;
745
+ chat_id: string;
746
+ org_phone: string;
747
+ timestamp: string;
748
+ media_path: string;
749
+ message_id: string;
750
+ sender_name: string;
751
+ performed_by: string;
752
+ sender_phone: string;
753
+ };
754
+ ticket: {
755
+ org_id: string;
756
+ status: string;
757
+ subject: string;
758
+ assignee: string;
759
+ due_date: string;
760
+ priority: 0 | 1 | 2 | 3 | 4;
761
+ raised_by: string;
762
+ ticket_id: string;
763
+ created_at: string;
764
+ assigned_by: string;
765
+ ticket_labels: string;
766
+ quoted_message_id: string;
767
+ ticket_custom_properties: { [key: string]: string } | null;
768
+ };
769
+ attached_messages: {
770
+ body: string;
771
+ chat_id: string;
772
+ org_phone: string;
773
+ timestamp: string;
774
+ media_path: string;
775
+ message_id: string;
776
+ sender_name: string;
777
+ performed_by: string;
778
+ sender_phone: string;
779
+ }[];
780
+ };
781
+
782
+ export type IntegrationLogObjectType =
783
+ | 'chat'
784
+ | 'message'
785
+ | 'reaction'
786
+ | 'ticket'
787
+ | 'phone';
788
+ export enum IntegrationLogType {
789
+ NEW_CHAT = 'chat.created',
790
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
791
+ NEW_MESSAGE = 'message.created',
792
+ MESSAGE_UPDATED = 'message.updated',
793
+ MESSAGE_DELETED = 'message.deleted',
794
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
795
+ REACTION_CREATED = 'reaction.created',
796
+ REACTION_UPDATED = 'reaction.updated',
797
+ NEW_TICKET = 'ticket.created',
798
+ TICKET_UPDATED = 'ticket.updated',
799
+ TICKET_DELETED = 'ticket.deleted',
800
+ MESSAGE_FLAGGED = 'message.flagged',
801
+ MESSAGE_UNFLAGGED = 'message.unflagged',
802
+ PHONE_DISCONNECTED = 'org.phone.disconnected',
803
+ PHONE_CONNECTED = 'org.phone.connected',
804
+ PHONE_UPDATED = 'org.phone.updated',
805
+ PHONE_QR_UPDATED = 'org.phone.qr',
806
+ }
807
+
808
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
809
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
810
+ ? TicketInfoType
811
+ : T extends IntegrationLogType.NEW_CHAT
812
+ ? Tables<'tbl_chats'>
813
+ : T extends
814
+ | IntegrationLogType.NEW_MESSAGE
815
+ | IntegrationLogType.MESSAGE_UPDATED
816
+ | IntegrationLogType.MESSAGE_DELETED
817
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
818
+ | IntegrationLogType.MESSAGE_FLAGGED
819
+ | IntegrationLogType.MESSAGE_UNFLAGGED
820
+ ? Tables<'tbl_chat_messages'>
821
+ : T extends
822
+ | IntegrationLogType.REACTION_CREATED
823
+ | IntegrationLogType.REACTION_UPDATED
824
+ ? Tables<'tbl_chat_reactions'>
825
+ : T extends
826
+ | IntegrationLogType.PHONE_DISCONNECTED
827
+ | IntegrationLogType.PHONE_CONNECTED
828
+ | IntegrationLogType.PHONE_UPDATED
829
+ | IntegrationLogType.PHONE_QR_UPDATED
830
+ ? Tables<'tbl_org_phones'>
831
+ : {
832
+ [key: string]: unknown;
833
+ };
834
+
835
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
836
+ OverrideProperties<
837
+ Tables<'tbl_integration_logs'>,
838
+ {
839
+ integration_name: T;
840
+ metadata: {
841
+ event: IntegrationLogMetadataType<T> & {
842
+ event_type: string;
843
+ org_id: string;
844
+ previous_attributes: {
845
+ [key: string]: unknown;
846
+ };
847
+ };
848
+ hook_id: string;
849
+ name: string;
850
+ };
851
+ }
852
+ >;
853
+
854
+ export type APIAuthDetails = {
855
+ org_details: Tables<'view_org'> | null;
856
+ phone_details: Tables<'tbl_org_phones'> | null;
857
+ token_details: Tables<'tbl_integration_tokens'> | null;
858
+ };
859
+
860
+ export type WebhookDataType = OverrideProperties<
861
+ Tables<'tbl_integration_hooks'>,
862
+ {
863
+ integration_name: string[];
864
+ }
865
+ >;
866
+
867
+ export type HubspotObjectDataType = {
868
+ createdAt: string;
869
+ archived: boolean;
870
+ id: string;
871
+ type: 'contacts' | 'tickets' | 'companies';
872
+ properties: Record<
873
+ string,
874
+ {
875
+ groupLabel: string;
876
+ groupName: string;
877
+ propertyKeyName: string;
878
+ propertyKey: string;
879
+ propertyInternalValue: string;
880
+ propertyValue: string;
881
+ propertyType: string;
882
+ propertyFieldType: string;
883
+ }[]
884
+ >;
885
+ };
886
+
887
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
888
+
889
+ export type UserPreferences = {
890
+ theme: 'light' | 'dark';
891
+ language: 'en' | 'es';
892
+ left_sidebar_open: boolean;
893
+ right_sidepanel_open: boolean;
894
+ sync_wa_unread_count: boolean;
895
+ pinned_chats: string[];
896
+ archived_chats: string[];
897
+ closed_chats: Record<string, number>;
898
+ periskope_chat_limit: number;
899
+ notifications: Record<string, boolean>;
900
+ };
901
+
902
+ /* ---------------------------- GROUP ANALYTICS SIDEPANEL TYPES---------------------------- */
903
+
904
+ export interface MostActiveMember {
905
+ sender_phone: string;
906
+ total_messages: number;
907
+ }
908
+
909
+ export interface GroupAnalyticsResult {
910
+ total_messages: number;
911
+ total_joins: number;
912
+ total_leaves: number;
913
+ total_removes: number;
914
+ total_reactions: number;
915
+ most_active_members: MostActiveMember[];
916
+ }
917
+
918
+ export interface TimeRange {
919
+ startDateTime: string; // Format: 'YYYY-MM-DD HH:MM:SS.ms+TZ' (e.g., '2025-04-21 06:30:21.24+00')
920
+ endDateTime: string;
921
+ }
922
+
923
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
924
+
925
+ export type PollSendType = {
926
+ pollName: string;
927
+ pollOptions: string[];
928
+ options?: {
929
+ allowMultipleAnswers?: boolean;
930
+ messageSecret?: number[] | null;
931
+ pollId?: string;
932
+ };
933
+ };
934
+
935
+ export type PollResultType = {
936
+ [name: string]: Record<string, string>;
937
+ };
938
+
939
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
940
+
941
+ export type CreateGroupOptions = {
942
+ messagesAdminsOnly?: boolean;
943
+ infoAdminsOnly?: boolean;
944
+ addMembersAdminsOnly?: boolean;
945
+ image?: string;
946
+ name?: string;
947
+ description?: string;
948
+ initiated_by?: string;
949
+ admins?: string[];
950
+ };
951
+
952
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
953
+
954
+ export type DeliveryInfoType = {
955
+ delivered: Record<string, number | undefined>;
956
+ read: Record<string, number | undefined>;
957
+ pending: string[];
958
+ read_count: number;
959
+ delivered_count: number;
960
+ };
961
+
962
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
963
+
964
+ export type OrgCreditsType = {
965
+ org_id: string;
966
+ recurring_allowance: number; // recurring credits replenished every cycle
967
+ recurring_balance: number; // recurring credits remaining in current cycle
968
+ topup_balance: number; // topup credits remaining
969
+ total_credits_used: number; // total credits used in current cycle
970
+ next_renewal_date: string;
971
+ topup_credits_used: number; // topup credits used in current cycle
972
+ recurring_credits_used: number; // recurring credits used in current cycle
973
+ };
974
+
975
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
976
+
977
+ export type ChatRuleInfoType = Merge<
978
+ Pick<
979
+ Tables<'view_chats'>,
980
+ | 'assigned_to'
981
+ | 'chat_id'
982
+ | 'chat_name'
983
+ | 'chat_type'
984
+ | 'created_at'
985
+ | 'group_description'
986
+ | 'info_admins_only'
987
+ | 'org_id'
988
+ | 'org_phone'
989
+ | 'chat_org_phones'
990
+ | 'messages_admins_only'
991
+ | 'custom_properties'
992
+ | 'initiated_by'
993
+ >,
994
+ {
995
+ has_flagged_messages: boolean;
996
+ labels: string[];
997
+ members: string[];
998
+ custom_properties: { [key: string]: string } | null;
999
+ }
1000
+ >;
1001
+
1002
+ export type SenderRuleInfoType = Merge<
1003
+ Omit<
1004
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
1005
+ | 'verified_name'
1006
+ | 'verified_level'
1007
+ | 'updated_at'
1008
+ | 'short_name'
1009
+ | 'pushname'
1010
+ | 'periskope_name'
1011
+ | 'org_phone'
1012
+ | 'number'
1013
+ | 'name'
1014
+ | 'label_ids'
1015
+ | 'is_wa_contact'
1016
+ | 'is_user'
1017
+ | 'is_my_contact'
1018
+ | 'is_me'
1019
+ | 'is_imported'
1020
+ | 'is_group'
1021
+ | 'is_blocked'
1022
+ | 'contact_color'
1023
+ | 'business_profile'
1024
+ | 'id'
1025
+ | 'contact_image'
1026
+ | 'contact_type'
1027
+ | 'chat_id'
1028
+ | 'is_business'
1029
+ | 'is_enterprise'
1030
+ | 'is_super_admin'
1031
+ >,
1032
+ {
1033
+ is_internal: boolean;
1034
+ labels: string[] | null;
1035
+ }
1036
+ >;
1037
+
1038
+ export type MessageRuleInfoType = {
1039
+ chat: ChatRuleInfoType;
1040
+ sender: SenderRuleInfoType;
1041
+ message: OverrideProperties<
1042
+ Omit<
1043
+ Tables<'tbl_chat_messages'>,
1044
+ | 'vcards'
1045
+ | 'updated_at'
1046
+ | 'unique_id'
1047
+ | 'token'
1048
+ | 'to'
1049
+ | 'sent_message_id'
1050
+ | 'raw_data'
1051
+ | 'delivery_info'
1052
+ | 'poll_results'
1053
+ | 'poll_info'
1054
+ | 'order_id'
1055
+ | 'mentioned_ids'
1056
+ | 'media_key'
1057
+ | 'location'
1058
+ | 'links'
1059
+ | 'is_status'
1060
+ | 'is_starred'
1061
+ | 'is_gif'
1062
+ | 'is_forwarded'
1063
+ | 'is_ephemeral'
1064
+ | 'is_deleted'
1065
+ | 'fts'
1066
+ | 'quoted_message_id'
1067
+ | 'invite_v4'
1068
+ | 'id'
1069
+ | 'has_reaction'
1070
+ | 'has_media'
1071
+ | 'duration'
1072
+ | 'broadcast'
1073
+ | 'broadcast_id'
1074
+ | 'device_type'
1075
+ | 'forwarding_score'
1076
+ | 'from'
1077
+ | 'from_me'
1078
+ | 'prev_body'
1079
+ | 'flag_response_time'
1080
+ | 'flag_metadata'
1081
+ | 'ack'
1082
+ >,
1083
+ {
1084
+ media: MediaType | null;
1085
+ }
1086
+ >;
1087
+ };
1088
+
1089
+ export type ReactionRuleInfoType = {
1090
+ chat: ChatRuleInfoType;
1091
+ sender: SenderRuleInfoType;
1092
+ message: MessageRuleInfoType['message'];
1093
+ reaction: Pick<
1094
+ Tables<'tbl_chat_reactions'>,
1095
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
1096
+ >;
1097
+ };
1098
+
1099
+ export type TicketRuleInfoType = {
1100
+ chat: ChatRuleInfoType;
1101
+ sender: SenderRuleInfoType;
1102
+ ticket: Merge<
1103
+ Pick<
1104
+ Tables<'tbl_chat_tickets'>,
1105
+ | 'org_id'
1106
+ | 'status'
1107
+ | 'chat_id'
1108
+ | 'subject'
1109
+ | 'assignee'
1110
+ | 'due_date'
1111
+ | 'priority'
1112
+ | 'raised_by'
1113
+ | 'ticket_id'
1114
+ | 'created_at'
1115
+ | 'is_deleted'
1116
+ >,
1117
+ {
1118
+ labels: string[] | null;
1119
+ custom_properties: { [key: string]: string } | null;
1120
+ }
1121
+ >;
1122
+ message: MessageRuleInfoType['message'];
1123
+ };
1124
+ export type FeatureFlagReturnType = Record<string, boolean>;
1125
+
1126
+ export type RuleLogsType = OverrideProperties<
1127
+ Tables<'tbl_rules_logs'>,
1128
+ {
1129
+ actions_progress: {
1130
+ action_id: string;
1131
+ action_type: Rule['actions'][number]['type'];
1132
+ action_delay: Rule['actions'][number]['delay'];
1133
+ ran_at: string | null;
1134
+ action_status: 'success' | 'failed' | 'pending';
1135
+ action_response: {
1136
+ success: boolean;
1137
+ data: Record<string, unknown> | null;
1138
+ error: {
1139
+ message: string;
1140
+ name: string;
1141
+ stack?: string;
1142
+ _error?: Error | Record<string, unknown>;
1143
+ } | null;
1144
+ };
1145
+ }[];
1146
+ metadata: {
1147
+ conditions: Rule['conditions'];
1148
+ actions: Rule['actions'];
1149
+ rule_metadata: Pick<
1150
+ Rule,
1151
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
1152
+ >;
1153
+ data: Record<string, unknown>;
1154
+ };
1155
+ conditions_progress: {
1156
+ is_valid: boolean;
1157
+ validation_progress: Record<
1158
+ string,
1159
+ {
1160
+ res: boolean;
1161
+ filter: Filter;
1162
+ value: unknown;
1163
+ }
1164
+ >;
1165
+ checked_at: string | null;
1166
+ };
1167
+ }
1168
+ >;
1169
+
1170
+ /************************** TASKS ***************************/
1171
+
1172
+ export type TaskType = OverrideProperties<
1173
+ Tables<'tbl_org_tasks'>,
1174
+ {
1175
+ reminder_setting: {
1176
+ remind_in:
1177
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
1178
+ | string
1179
+ | null;
1180
+ repeat?: {
1181
+ frequency: number;
1182
+ interval: 'days' | 'weeks' | 'months' | 'years';
1183
+ end: 'never' | 'after' | 'on';
1184
+ on?: string;
1185
+ };
1186
+ } | null;
1187
+ associated_object_metadata:
1188
+ | {
1189
+ type: 'chat';
1190
+ index: 'chat_id';
1191
+ id: string;
1192
+ object: ChatType;
1193
+ }
1194
+ | {
1195
+ type: 'message';
1196
+ index: 'message_id';
1197
+ id: string;
1198
+ object: MessageType;
1199
+ }
1200
+ | {
1201
+ type: 'ticket';
1202
+ index: 'ticket_id';
1203
+ id: string;
1204
+ object: TicketType;
1205
+ }
1206
+ | null;
1207
+ status: 'open' | 'inprogress' | 'closed';
1208
+ priority: 1 | 2 | 3;
1209
+ completed_metadata?: {
1210
+ completed_at: string;
1211
+ completed_by: string;
1212
+ } | null;
1213
+ type: 'todo' | 'chat' | 'message' | 'ticket';
1214
+ }
1215
+ >;
1216
+
1217
+ type Choice = {
1218
+ id: number;
1219
+ label: string;
1220
+ value: string;
1221
+ position: number;
1222
+ };
1223
+
1224
+ export type FreshdeskCustomFieldType = {
1225
+ id: number;
1226
+ name: string;
1227
+ label: string;
1228
+ position: number;
1229
+ required_for_agents: boolean;
1230
+ archived: boolean;
1231
+ customers_can_edit: boolean;
1232
+ label_for_customers: string;
1233
+ required_for_customers: boolean;
1234
+ customers_can_filter: boolean;
1235
+ required_for_closure: boolean;
1236
+ displayed_to_customers: boolean;
1237
+ type: string;
1238
+ default: boolean;
1239
+ created_at: string;
1240
+ updated_at: string;
1241
+ choices?: Choice[];
1242
+ };