@periskope/types 0.6.284 → 0.6.285

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