@periskope/types 0.6.264 → 0.6.265

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