@periskope/types 0.6.210 → 0.6.211

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,980 +1,980 @@
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 OrgMetadata = {
82
- phone_number: string;
83
- ticket_prefix: string;
84
- referralSource?: string;
85
- surveyData?: MicrosurveyData;
86
- preferences?: OrgPreferences;
87
- hubspot: {
88
- hubspot_pipelines?: {
89
- id: string;
90
- label: string;
91
- default_stage: { id: string; label: string };
92
- }[];
93
- hubspot_hidden_fields?: string[];
94
- };
95
- partition?: boolean;
96
- tickets: {
97
- prefix?: string;
98
- emoji_ticketing: {
99
- is_enabled?: boolean;
100
- is_message_enabled?: boolean;
101
- message_template?: string;
102
- };
103
- };
104
- attribution?: Object;
105
- affiliate_id?: string;
106
- custom_properties?: {
107
- chats_order?: {
108
- [id: string]: number;
109
- };
110
- tickets_order?: {
111
- [id: string]: number;
112
- };
113
- };
114
- rules?: {
115
- limit?: number;
116
- };
117
- ai?: {
118
- flag_prompt?: string;
119
- };
120
- display_language?: string;
121
- };
122
-
123
- type AccessScopes = {
124
- feature_flags: Record<string, boolean>;
125
- integrations: boolean;
126
- rules: boolean;
127
- exports: boolean;
128
- };
129
-
130
- export type OrgType = OverrideProperties<
131
- Merge<
132
- Tables<'tbl_org'>,
133
- {
134
- user: Tables<'tbl_org_members'>;
135
- members: Tables<'tbl_org_members'>[];
136
- phones: Tables<'tbl_org_phones'>[];
137
- labels: Tables<'tbl_org_labels'>[];
138
- quick_replies: Tables<'tbl_quick_replies'>[];
139
- custom_properties: Tables<'tbl_custom_properties'>[];
140
- subscription_status: 'active' | 'inactive' | 'unpaid';
141
- is_enterprise: boolean;
142
- is_free_trial: boolean;
143
- is_hubspot_connected: boolean;
144
- is_freshdesk_connected: boolean;
145
- is_zohodesk_connected: boolean;
146
- access_scopes: AccessScopes;
147
- rules: Rule[];
148
- }
149
- >,
150
- {
151
- org_plan: OrgPlan<AllPlans | Enterprise>;
152
- stripe_customer_details: _Stripe.Customer | null;
153
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
154
- stripe_customer_id: _Stripe.Customer['id'] | null;
155
- org_metadata: OrgMetadata;
156
- }
157
- >;
158
-
159
- export type ChatMemberType = Merge<
160
- Tables<'tbl_chat_participants'>,
161
- Tables<'tbl_contacts'>
162
- >;
163
-
164
- export type ChatType = Merge<
165
- Tables<'view_chats'>,
166
- {
167
- chat_id: string;
168
- latest_message: MessageType | null;
169
- latest_message_timestamp: number | null;
170
- members: { [key: string]: ChatMemberType } | null;
171
- chat_type: 'user' | 'group' | 'business' | 'unknown';
172
- chat_access: { [key: string]: boolean };
173
- label_ids: { [key: string]: boolean };
174
- chat_org_phones?: string[];
175
- message_unread_count: number | null;
176
- hubspot_metadata: {
177
- id: string;
178
- type: string;
179
- hubId: string;
180
- object_data: HubspotObjectDataType;
181
- } | null;
182
- info_admins_only: boolean;
183
- messages_admins_only: boolean;
184
- unread_count?: { [key: string]: number };
185
- active_phone: string | null;
186
- flag_count_map?: { [key: string]: number };
187
- is_archived?: boolean;
188
- is_pinned?: boolean;
189
- closed_at?: number | null;
190
- common_chats?: string[];
191
- freshdesk_metadata?: Record<string, any>;
192
- zohodesk_metadata?: Record<string, any>;
193
- pinned_messages?: {
194
- message_id: string;
195
- pinned_at: number;
196
- expires_at: number;
197
- }[];
198
- }
199
- >;
200
-
201
- /* -------------------------------------------------------------------------- */
202
- /* MESSAGE */
203
- /* -------------------------------------------------------------------------- */
204
-
205
- export type MediaType = {
206
- path?: string;
207
- mimetype?: string;
208
- filename?: string;
209
- dimensions?: { width: number; height: number; ar: number };
210
- size?: number;
211
- thumbnail?: string;
212
- filedata?: string;
213
- compress?: boolean;
214
- };
215
-
216
- export type MessageType = Merge<
217
- OverrideProperties<
218
- TablesInsert<'tbl_chat_messages'>,
219
- {
220
- message_id: string;
221
- org_id: string;
222
- org_phone: string;
223
- chat_id: string;
224
- message_type: (typeof SUPPORTED_TYPES)[number];
225
- media: MediaType | null;
226
- flag_metadata?: MessageFlagType | null;
227
- poll_info?: PollSendType | null;
228
- poll_results?: PollResultType | null;
229
- delivery_info?: DeliveryInfoType | null;
230
- raw_data: {
231
- translations?: Record<string, string>;
232
- [key: string]: unknown;
233
- } | null;
234
- }
235
- >,
236
- {
237
- reactions?: ReactionType[];
238
- message_payload?: SingleMessagePayload;
239
- highlight?: number;
240
- is_private_note?: boolean;
241
- }
242
- >;
243
-
244
- export type MessageFlagType = {
245
- status: boolean;
246
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
247
- response_id?: string;
248
- response_timestamp?: string;
249
- response_email?: string;
250
- };
251
-
252
- /* -------------------------------------------------------------------------- */
253
-
254
- export type TicketType = OverrideProperties<
255
- Tables<'tbl_chat_tickets'>,
256
- {
257
- label_ids: { [key: string]: boolean };
258
- hubspot_metadata: {
259
- id?: string;
260
- type?: string;
261
- hubId?: string;
262
- pipeline: {
263
- id: string;
264
- label: string;
265
- };
266
- object_data?: HubspotObjectDataType;
267
- } | null;
268
- freshdesk_metadata: Record<string, string>;
269
- close_ticket_metadata?:
270
- | {
271
- closed_by: string;
272
- closed_at: string;
273
- closed_message?: string | null;
274
- send_reply_message_id?: string | null;
275
- }
276
- | any;
277
- }
278
- >;
279
-
280
- export type ContactType = Merge<
281
- Tables<'tbl_contacts'>,
282
- {
283
- chats: ChatType[] | null;
284
- chat_ids?: string[];
285
- }
286
- >;
287
- export type ReactionType = Tables<'tbl_chat_reactions'>;
288
-
289
- export type NotificationType = Tables<'tbl_chat_notifications'>;
290
-
291
- export type ChatAccessType = Merge<
292
- TablesUpdate<'tbl_org_members'>,
293
- {
294
- has_access?: boolean;
295
- email: string | null;
296
- }
297
- >;
298
-
299
- export type PhoneQueueStatusType = {
300
- active: number;
301
- failed: number;
302
- completed: number;
303
- is_running: boolean;
304
- pending: number;
305
- };
306
-
307
- export type PhoneType = OverrideProperties<
308
- Tables<'tbl_org_phones'>,
309
- {
310
- queue_status: {
311
- [key: string]: PhoneQueueStatusType;
312
- };
313
- }
314
- >;
315
-
316
- /* -------------------------------- CONSTANTS ------------------------------- */
317
-
318
- export const labelColors = [
319
- '#9333EA',
320
- '#0D9488',
321
- '#DB2777',
322
- '#2563EB',
323
- '#F97316',
324
- ];
325
-
326
- export const enumChatColors = [
327
- '#B4876E',
328
- '#A5B337',
329
- '#06CF9C',
330
- '#25D366',
331
- '#02A698',
332
- '#7D9EF1',
333
- '#007BFC',
334
- '#5E47DE',
335
- '#7F66FF',
336
- '#9333EA',
337
- '#FA6533',
338
- '#C4532D',
339
- '#DC2626',
340
- '#FF2E74',
341
- '#DB2777',
342
- ] as const;
343
-
344
- export type RepeatDaysType =
345
- | 'monday'
346
- | 'tuesday'
347
- | 'wednesday'
348
- | 'thursday'
349
- | 'friday'
350
- | 'saturday'
351
- | 'sunday';
352
- export type RepeatIntervalType = 'day' | 'week' | 'month';
353
-
354
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
355
-
356
- export const SUPPORTED_TYPES = [
357
- 'chat',
358
- 'sticker',
359
- 'image',
360
- 'video',
361
- 'document',
362
- 'vcard',
363
- 'multi_vcard',
364
- 'audio',
365
- 'ptt',
366
- 'poll_creation',
367
- 'location',
368
- 'ciphertext',
369
- ] as const;
370
-
371
- export type SendMessageContent = {
372
- message_type?: (typeof SUPPORTED_TYPES)[number];
373
- body?: string;
374
- media?: MediaType;
375
- contact_ids?: string[];
376
- location?: {
377
- latitude: string;
378
- longitude: string;
379
- options?: { name?: string; address?: string; url?: string };
380
- };
381
- poll?: PollSendType;
382
- quoted_message_id?: string;
383
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
384
- broadcast_id?: string;
385
- performed_by?: string;
386
- };
387
-
388
- export type QuickReplyContent = Omit<
389
- SendMessageContent,
390
- 'broadcast_id' | 'variables'
391
- >;
392
-
393
- export type ScheduleMessagePayload = {
394
- scheduled_id?: string;
395
- is_repeat?: boolean | null;
396
- scheduled_at: string;
397
- repeat_config?: {
398
- repeat_ends?: string;
399
- repeat_interval?: RepeatIntervalType;
400
- repeat_value?: number;
401
- repeat_days?: RepeatDaysType[];
402
- };
403
- };
404
-
405
- export type BroadcastVariableType = {
406
- chat_id: string;
407
- values: { [key: string]: string };
408
- };
409
-
410
- export type BroadcastMessagePayload = SendMessageContent & {
411
- chat_ids: string[];
412
- broadcast_id?: string;
413
- variables?: BroadcastVariableType[];
414
- delay?: number;
415
- };
416
-
417
- export type SingleMessagePayload = SendMessageContent & {
418
- chat_id: string;
419
- job_id?: string;
420
- priority?: number;
421
- };
422
-
423
- export type MessageAttachmentFileTypes =
424
- | 'image'
425
- | 'audio'
426
- | 'document'
427
- | 'video';
428
-
429
- export type AttachmentFileType = {
430
- result: string;
431
- file: File | null;
432
- type: MessageAttachmentFileTypes;
433
- localFileURL?: string;
434
- };
435
-
436
- export type AttachmentLinkType = {
437
- link: {
438
- url: string;
439
- type: MessageAttachmentFileTypes;
440
- name: string;
441
- mimetype?: string;
442
- };
443
- };
444
-
445
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
446
-
447
- /* -------------------------------- BROADCAST ------------------------------- */
448
-
449
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
450
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
451
- } & {
452
- chats: ChatType[];
453
- };
454
-
455
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
456
-
457
- export type ChatLogType = {
458
- log: Tables<'view_chat_logs'>;
459
- operations: Tables<'tbl_chat_logs'>[];
460
- };
461
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
462
-
463
- export type ChatParticipantOperationPayload = {
464
- participant_ids: string[];
465
- chat_ids: string[];
466
- performed_by: string;
467
- };
468
-
469
- export type ChatOperationReturn = {
470
- [participant_id: string]: {
471
- is_success: boolean;
472
- message?: string;
473
- code?: number;
474
- isInviteV4Sent?: boolean;
475
- };
476
- };
477
-
478
- /* ----------------------- BILLING - STRIPE ----------------------- */
479
-
480
- export type StripeSubscription = _Stripe.Subscription;
481
- export type StripeCustomer = _Stripe.Customer;
482
- export type StripeCoupon = _Stripe.Coupon;
483
- export type StripePrice = _Stripe.Price;
484
- export type Stripe = _Stripe;
485
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
486
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
487
-
488
- /* -------------------------------- REALTIME -------------------------------- */
489
-
490
- export type PhoneStateType = {
491
- loading: boolean;
492
- state: string;
493
- sync: number;
494
- percent: number | null;
495
- message?: string;
496
- error?: string;
497
- };
498
-
499
- /* ------------------------------- INTEGRATIONS ----------------------------- */
500
-
501
- export type ChatInfoType = Merge<
502
- ChatType,
503
- {
504
- members: {
505
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
506
- } | null;
507
- chat_labels: string | null;
508
- custom_properties: { [key: string]: string } | null;
509
- }
510
- >;
511
-
512
- export type TicketInfoType = {
513
- chat: ChatInfoType;
514
- message: {
515
- body: string;
516
- chat_id: string;
517
- org_phone: string;
518
- timestamp: string;
519
- media_path: string;
520
- message_id: string;
521
- sender_name: string;
522
- performed_by: string;
523
- sender_phone: string;
524
- };
525
- ticket: {
526
- org_id: string;
527
- status: string;
528
- subject: string;
529
- assignee: string;
530
- due_date: string;
531
- priority: 0 | 1 | 2 | 3 | 4;
532
- raised_by: string;
533
- ticket_id: string;
534
- created_at: string;
535
- assigned_by: string;
536
- ticket_labels: string;
537
- quoted_message_id: string;
538
- ticket_custom_properties: { [key: string]: string } | null;
539
- };
540
- attached_messages: {
541
- body: string;
542
- chat_id: string;
543
- org_phone: string;
544
- timestamp: string;
545
- media_path: string;
546
- message_id: string;
547
- sender_name: string;
548
- performed_by: string;
549
- sender_phone: string;
550
- }[];
551
- };
552
-
553
- export type IntegrationLogObjectType =
554
- | 'chat'
555
- | 'message'
556
- | 'reaction'
557
- | 'ticket';
558
-
559
- export enum IntegrationLogType {
560
- NEW_CHAT = 'chat.created',
561
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
562
- NEW_MESSAGE = 'message.created',
563
- MESSAGE_UPDATED = 'message.updated',
564
- MESSAGE_DELETED = 'message.deleted',
565
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
566
- REACTION_CREATED = 'reaction.created',
567
- REACTION_UPDATED = 'reaction.updated',
568
- NEW_TICKET = 'ticket.created',
569
- TICKET_UPDATED = 'ticket.updated',
570
- TICKET_DELETED = 'ticket.deleted',
571
- MESSAGE_FLAGGED = 'message.flagged',
572
- MESSAGE_UNFLAGGED = 'message.unflagged',
573
- }
574
-
575
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
576
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
577
- ? TicketInfoType
578
- : T extends IntegrationLogType.NEW_CHAT
579
- ? Tables<'tbl_chats'>
580
- : T extends
581
- | IntegrationLogType.NEW_MESSAGE
582
- | IntegrationLogType.MESSAGE_UPDATED
583
- | IntegrationLogType.MESSAGE_DELETED
584
- | IntegrationLogType.MESSAGE_ACK_UPDATED
585
- | IntegrationLogType.MESSAGE_FLAGGED
586
- | IntegrationLogType.MESSAGE_UNFLAGGED
587
- ? Tables<'tbl_chat_messages'>
588
- : T extends
589
- | IntegrationLogType.REACTION_CREATED
590
- | IntegrationLogType.REACTION_UPDATED
591
- ? Tables<'tbl_chat_reactions'>
592
- : {
593
- [key: string]: unknown;
594
- };
595
-
596
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
597
- OverrideProperties<
598
- Tables<'tbl_integration_logs'>,
599
- {
600
- integration_name: T;
601
- metadata: {
602
- event: IntegrationLogMetadataType<T> & {
603
- event_type: string;
604
- org_id: string;
605
- previous_attributes: {
606
- [key: string]: unknown;
607
- };
608
- };
609
- hook_id: string;
610
- name: string;
611
- };
612
- }
613
- >;
614
-
615
- export type APIAuthDetails = {
616
- org_details: Tables<'view_org'> | null;
617
- phone_details: Tables<'tbl_org_phones'> | null;
618
- token_details: Tables<'tbl_integration_tokens'> | null;
619
- };
620
-
621
- export type WebhookDataType = OverrideProperties<
622
- Tables<'tbl_integration_hooks'>,
623
- {
624
- integration_name: string[];
625
- }
626
- >;
627
-
628
- export type HubspotObjectDataType = {
629
- createdAt: string;
630
- archived: boolean;
631
- id: string;
632
- type: 'contacts' | 'tickets' | 'companies';
633
- properties: Record<
634
- string,
635
- {
636
- groupLabel: string;
637
- groupName: string;
638
- propertyKeyName: string;
639
- propertyKey: string;
640
- propertyInternalValue: string;
641
- propertyValue: string;
642
- propertyType: string;
643
- propertyFieldType: string;
644
- }[]
645
- >;
646
- };
647
-
648
- /* ---------------------------- USER PREFERENCES ---------------------------- */
649
-
650
- export type UserPreferences = {
651
- theme: 'light' | 'dark';
652
- language: 'en' | 'es';
653
- left_sidebar_open: boolean;
654
- right_sidepanel_open: boolean;
655
- sync_wa_unread_count: boolean;
656
- pinned_chats: string[];
657
- archived_chats: string[];
658
- closed_chats: Record<string, number>;
659
- periskope_chat_limit: number;
660
- notifications: Record<string, boolean>;
661
- };
662
-
663
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
664
-
665
- export type PollSendType = {
666
- pollName: string;
667
- pollOptions: string[];
668
- options?: {
669
- allowMultipleAnswers?: boolean;
670
- messageSecret?: number[] | null;
671
- pollId?: string;
672
- };
673
- };
674
-
675
- export type PollResultType = {
676
- [name: string]: Record<string, string>;
677
- };
678
-
679
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
680
-
681
- export type CreateGroupOptions = {
682
- messagesAdminsOnly?: boolean;
683
- infoAdminsOnly?: boolean;
684
- addMembersAdminsOnly?: boolean;
685
- image?: string;
686
- name?: string;
687
- description?: string;
688
- initiated_by?: string;
689
- admins?: string[];
690
- };
691
-
692
- /* ------------------------------ DELIVERY INFO ----------------------------- */
693
-
694
- export type DeliveryInfoType = {
695
- delivered: Record<string, number | undefined>;
696
- read: Record<string, number | undefined>;
697
- pending: string[];
698
- read_count: number;
699
- delivered_count: number;
700
- };
701
-
702
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
703
-
704
- export type OrgCreditsType = {
705
- org_id: string;
706
- recurring_allowance: number; // recurring credits replenished every month
707
- recurring_balance: number; // recurring credits remaining in current month
708
- topup_balance: number; // topup credits remaining
709
- total_credits_used: number; // total credits used in current month
710
- next_renewal_date: string;
711
- };
712
-
713
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
714
-
715
- export type ChatRuleInfoType = Merge<
716
- Pick<
717
- Tables<'view_chats'>,
718
- | 'assigned_to'
719
- | 'chat_id'
720
- | 'chat_name'
721
- | 'chat_type'
722
- | 'created_at'
723
- | 'group_description'
724
- | 'info_admins_only'
725
- | 'org_id'
726
- | 'org_phone'
727
- | 'chat_org_phones'
728
- | 'messages_admins_only'
729
- | 'custom_properties'
730
- | 'initiated_by'
731
- >,
732
- {
733
- has_flagged_messages: boolean;
734
- labels: string[];
735
- members: string[];
736
- custom_properties: { [key: string]: string } | null;
737
- }
738
- >;
739
-
740
- export type SenderRuleInfoType = Merge<
741
- Omit<
742
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
743
- | 'verified_name'
744
- | 'verified_level'
745
- | 'updated_at'
746
- | 'short_name'
747
- | 'pushname'
748
- | 'periskope_name'
749
- | 'org_phone'
750
- | 'number'
751
- | 'name'
752
- | 'label_ids'
753
- | 'is_wa_contact'
754
- | 'is_user'
755
- | 'is_my_contact'
756
- | 'is_me'
757
- | 'is_imported'
758
- | 'is_group'
759
- | 'is_blocked'
760
- | 'contact_color'
761
- | 'business_profile'
762
- | 'id'
763
- | 'contact_image'
764
- | 'contact_type'
765
- | 'chat_id'
766
- | 'is_business'
767
- | 'is_enterprise'
768
- | 'is_super_admin'
769
- >,
770
- {
771
- is_internal: boolean;
772
- labels: string[] | null;
773
- }
774
- >;
775
-
776
- export type MessageRuleInfoType = {
777
- chat: ChatRuleInfoType;
778
- sender: SenderRuleInfoType;
779
- message: OverrideProperties<
780
- Omit<
781
- Tables<'tbl_chat_messages'>,
782
- | 'vcards'
783
- | 'updated_at'
784
- | 'unique_id'
785
- | 'token'
786
- | 'to'
787
- | 'sent_message_id'
788
- | 'raw_data'
789
- | 'delivery_info'
790
- | 'poll_results'
791
- | 'poll_info'
792
- | 'order_id'
793
- | 'mentioned_ids'
794
- | 'media_key'
795
- | 'location'
796
- | 'links'
797
- | 'is_status'
798
- | 'is_starred'
799
- | 'is_gif'
800
- | 'is_forwarded'
801
- | 'is_ephemeral'
802
- | 'is_deleted'
803
- | 'fts'
804
- | 'quoted_message_id'
805
- | 'invite_v4'
806
- | 'id'
807
- | 'has_reaction'
808
- | 'has_media'
809
- | 'duration'
810
- | 'broadcast'
811
- | 'broadcast_id'
812
- | 'device_type'
813
- | 'forwarding_score'
814
- | 'from'
815
- | 'from_me'
816
- | 'prev_body'
817
- | 'flag_response_time'
818
- | 'flag_metadata'
819
- | 'ack'
820
- >,
821
- {
822
- media: MediaType | null;
823
- }
824
- >;
825
- };
826
-
827
- export type ReactionRuleInfoType = {
828
- chat: ChatRuleInfoType;
829
- sender: SenderRuleInfoType;
830
- message: MessageRuleInfoType['message'];
831
- reaction: Pick<
832
- Tables<'tbl_chat_reactions'>,
833
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
834
- >;
835
- };
836
-
837
- export type TicketRuleInfoType = {
838
- chat: ChatRuleInfoType;
839
- sender: SenderRuleInfoType;
840
- ticket: Merge<
841
- Pick<
842
- Tables<'tbl_chat_tickets'>,
843
- | 'org_id'
844
- | 'status'
845
- | 'chat_id'
846
- | 'subject'
847
- | 'assignee'
848
- | 'due_date'
849
- | 'priority'
850
- | 'raised_by'
851
- | 'ticket_id'
852
- | 'created_at'
853
- | 'is_deleted'
854
- >,
855
- {
856
- labels: string[] | null;
857
- custom_properties: { [key: string]: string } | null;
858
- }
859
- >;
860
- message: MessageRuleInfoType['message'];
861
- };
862
- export type FeatureFlagReturnType = Record<string, boolean>;
863
-
864
- export type RuleLogsType = OverrideProperties<
865
- Tables<'tbl_rules_logs'>,
866
- {
867
- actions_progress: {
868
- action_id: string;
869
- action_type: Rule['actions'][number]['type'];
870
- action_delay: Rule['actions'][number]['delay'];
871
- ran_at: string | null;
872
- action_status: 'success' | 'failed' | 'pending';
873
- action_response: {
874
- success: boolean;
875
- data: Record<string, unknown> | null;
876
- error: {
877
- message: string;
878
- name: string;
879
- stack?: string;
880
- _error?: Error | Record<string, unknown>;
881
- } | null;
882
- };
883
- }[];
884
- metadata: {
885
- conditions: Rule['conditions'];
886
- actions: Rule['actions'];
887
- rule_metadata: Pick<
888
- Rule,
889
- 'rule_name' | 'last_updated_at' | 'last_updated_by'
890
- >;
891
- data: Record<string, unknown>;
892
- };
893
- conditions_progress: {
894
- is_valid: boolean;
895
- validation_progress: Record<
896
- string,
897
- {
898
- res: boolean;
899
- filter: Filter;
900
- value: unknown;
901
- }
902
- >;
903
- checked_at: string | null;
904
- };
905
- }
906
- >;
907
-
908
- /************************** TASKS ***************************/
909
-
910
- export type TaskType = OverrideProperties<
911
- Tables<'tbl_org_tasks'>,
912
- {
913
- reminder_setting: {
914
- remind_in:
915
- | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
916
- | string
917
- | null;
918
- repeat?: {
919
- frequency: number;
920
- interval: 'days' | 'weeks' | 'months' | 'years';
921
- end: 'never' | 'after' | 'on';
922
- on?: string;
923
- };
924
- } | null;
925
- associated_object_metadata:
926
- | {
927
- type: 'chat';
928
- index: 'chat_id';
929
- id: string;
930
- object: ChatType;
931
- }
932
- | {
933
- type: 'message';
934
- index: 'message_id';
935
- id: string;
936
- object: MessageType;
937
- }
938
- | {
939
- type: 'ticket';
940
- index: 'ticket_id';
941
- id: string;
942
- object: TicketType;
943
- }
944
- | null;
945
- status: 'open' | 'inprogress' | 'closed';
946
- priority: 1 | 2 | 3;
947
- completed_metadata?: {
948
- completed_at: string;
949
- completed_by: string;
950
- } | null;
951
- type: 'todo' | 'chat' | 'message' | 'ticket';
952
- }
953
- >;
954
-
955
- type Choice = {
956
- id: number;
957
- label: string;
958
- value: string;
959
- position: number;
960
- };
961
-
962
- export type FreshdeskCustomFieldType = {
963
- id: number;
964
- name: string;
965
- label: string;
966
- position: number;
967
- required_for_agents: boolean;
968
- archived: boolean;
969
- customers_can_edit: boolean;
970
- label_for_customers: string;
971
- required_for_customers: boolean;
972
- customers_can_filter: boolean;
973
- required_for_closure: boolean;
974
- displayed_to_customers: boolean;
975
- type: string;
976
- default: boolean;
977
- created_at: string;
978
- updated_at: string;
979
- choices?: Choice[];
980
- };
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 OrgMetadata = {
82
+ phone_number: string;
83
+ ticket_prefix: string;
84
+ referralSource?: string;
85
+ surveyData?: MicrosurveyData;
86
+ preferences?: OrgPreferences;
87
+ hubspot: {
88
+ hubspot_pipelines?: {
89
+ id: string;
90
+ label: string;
91
+ default_stage: { id: string; label: string };
92
+ }[];
93
+ hubspot_hidden_fields?: string[];
94
+ };
95
+ partition?: boolean;
96
+ tickets: {
97
+ prefix?: string;
98
+ emoji_ticketing: {
99
+ is_enabled?: boolean;
100
+ is_message_enabled?: boolean;
101
+ message_template?: string;
102
+ };
103
+ };
104
+ attribution?: Object;
105
+ affiliate_id?: string;
106
+ custom_properties?: {
107
+ chats_order?: {
108
+ [id: string]: number;
109
+ };
110
+ tickets_order?: {
111
+ [id: string]: number;
112
+ };
113
+ };
114
+ rules?: {
115
+ limit?: number;
116
+ };
117
+ ai?: {
118
+ flag_prompt?: string;
119
+ };
120
+ display_language?: string;
121
+ };
122
+
123
+ type AccessScopes = {
124
+ feature_flags: Record<string, boolean>;
125
+ integrations: boolean;
126
+ rules: boolean;
127
+ exports: boolean;
128
+ };
129
+
130
+ export type OrgType = OverrideProperties<
131
+ Merge<
132
+ Tables<'tbl_org'>,
133
+ {
134
+ user: Tables<'tbl_org_members'>;
135
+ members: Tables<'tbl_org_members'>[];
136
+ phones: Tables<'tbl_org_phones'>[];
137
+ labels: Tables<'tbl_org_labels'>[];
138
+ quick_replies: Tables<'tbl_quick_replies'>[];
139
+ custom_properties: Tables<'tbl_custom_properties'>[];
140
+ subscription_status: 'active' | 'inactive' | 'unpaid';
141
+ is_enterprise: boolean;
142
+ is_free_trial: boolean;
143
+ is_hubspot_connected: boolean;
144
+ is_freshdesk_connected: boolean;
145
+ is_zohodesk_connected: boolean;
146
+ access_scopes: AccessScopes;
147
+ rules: Rule[];
148
+ }
149
+ >,
150
+ {
151
+ org_plan: OrgPlan<AllPlans | Enterprise>;
152
+ stripe_customer_details: _Stripe.Customer | null;
153
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
154
+ stripe_customer_id: _Stripe.Customer['id'] | null;
155
+ org_metadata: OrgMetadata;
156
+ }
157
+ >;
158
+
159
+ export type ChatMemberType = Merge<
160
+ Tables<'tbl_chat_participants'>,
161
+ Tables<'tbl_contacts'>
162
+ >;
163
+
164
+ export type ChatType = Merge<
165
+ Tables<'view_chats'>,
166
+ {
167
+ chat_id: string;
168
+ latest_message: MessageType | null;
169
+ latest_message_timestamp: number | null;
170
+ members: { [key: string]: ChatMemberType } | null;
171
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
172
+ chat_access: { [key: string]: boolean };
173
+ label_ids: { [key: string]: boolean };
174
+ chat_org_phones?: string[];
175
+ message_unread_count: number | null;
176
+ hubspot_metadata: {
177
+ id: string;
178
+ type: string;
179
+ hubId: string;
180
+ object_data: HubspotObjectDataType;
181
+ } | null;
182
+ info_admins_only: boolean;
183
+ messages_admins_only: boolean;
184
+ unread_count?: { [key: string]: number };
185
+ active_phone: string | null;
186
+ flag_count_map?: { [key: string]: number };
187
+ is_archived?: boolean;
188
+ is_pinned?: boolean;
189
+ closed_at?: number | null;
190
+ common_chats?: string[];
191
+ freshdesk_metadata?: Record<string, any>;
192
+ zohodesk_metadata?: Record<string, any>;
193
+ pinned_messages?: {
194
+ message_id: string;
195
+ pinned_at: number;
196
+ expires_at: number;
197
+ }[];
198
+ }
199
+ >;
200
+
201
+ /* -------------------------------------------------------------------------- */
202
+ /* MESSAGE */
203
+ /* -------------------------------------------------------------------------- */
204
+
205
+ export type MediaType = {
206
+ path?: string;
207
+ mimetype?: string;
208
+ filename?: string;
209
+ dimensions?: { width: number; height: number; ar: number };
210
+ size?: number;
211
+ thumbnail?: string;
212
+ filedata?: string;
213
+ compress?: boolean;
214
+ };
215
+
216
+ export type MessageType = Merge<
217
+ OverrideProperties<
218
+ TablesInsert<'tbl_chat_messages'>,
219
+ {
220
+ message_id: string;
221
+ org_id: string;
222
+ org_phone: string;
223
+ chat_id: string;
224
+ message_type: (typeof SUPPORTED_TYPES)[number];
225
+ media: MediaType | null;
226
+ flag_metadata?: MessageFlagType | null;
227
+ poll_info?: PollSendType | null;
228
+ poll_results?: PollResultType | null;
229
+ delivery_info?: DeliveryInfoType | null;
230
+ raw_data?: {
231
+ translations?: Record<string, string>;
232
+ [key: string]: unknown;
233
+ } | null;
234
+ }
235
+ >,
236
+ {
237
+ reactions?: ReactionType[];
238
+ message_payload?: SingleMessagePayload;
239
+ highlight?: number;
240
+ is_private_note?: boolean;
241
+ }
242
+ >;
243
+
244
+ export type MessageFlagType = {
245
+ status: boolean;
246
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
247
+ response_id?: string;
248
+ response_timestamp?: string;
249
+ response_email?: string;
250
+ };
251
+
252
+ /* -------------------------------------------------------------------------- */
253
+
254
+ export type TicketType = OverrideProperties<
255
+ Tables<'tbl_chat_tickets'>,
256
+ {
257
+ label_ids: { [key: string]: boolean };
258
+ hubspot_metadata: {
259
+ id?: string;
260
+ type?: string;
261
+ hubId?: string;
262
+ pipeline: {
263
+ id: string;
264
+ label: string;
265
+ };
266
+ object_data?: HubspotObjectDataType;
267
+ } | null;
268
+ freshdesk_metadata: Record<string, string>;
269
+ close_ticket_metadata?:
270
+ | {
271
+ closed_by: string;
272
+ closed_at: string;
273
+ closed_message?: string | null;
274
+ send_reply_message_id?: string | null;
275
+ }
276
+ | any;
277
+ }
278
+ >;
279
+
280
+ export type ContactType = Merge<
281
+ Tables<'tbl_contacts'>,
282
+ {
283
+ chats: ChatType[] | null;
284
+ chat_ids?: string[];
285
+ }
286
+ >;
287
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
288
+
289
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
290
+
291
+ export type ChatAccessType = Merge<
292
+ TablesUpdate<'tbl_org_members'>,
293
+ {
294
+ has_access?: boolean;
295
+ email: string | null;
296
+ }
297
+ >;
298
+
299
+ export type PhoneQueueStatusType = {
300
+ active: number;
301
+ failed: number;
302
+ completed: number;
303
+ is_running: boolean;
304
+ pending: number;
305
+ };
306
+
307
+ export type PhoneType = OverrideProperties<
308
+ Tables<'tbl_org_phones'>,
309
+ {
310
+ queue_status: {
311
+ [key: string]: PhoneQueueStatusType;
312
+ };
313
+ }
314
+ >;
315
+
316
+ /* -------------------------------- CONSTANTS ------------------------------- */
317
+
318
+ export const labelColors = [
319
+ '#9333EA',
320
+ '#0D9488',
321
+ '#DB2777',
322
+ '#2563EB',
323
+ '#F97316',
324
+ ];
325
+
326
+ export const enumChatColors = [
327
+ '#B4876E',
328
+ '#A5B337',
329
+ '#06CF9C',
330
+ '#25D366',
331
+ '#02A698',
332
+ '#7D9EF1',
333
+ '#007BFC',
334
+ '#5E47DE',
335
+ '#7F66FF',
336
+ '#9333EA',
337
+ '#FA6533',
338
+ '#C4532D',
339
+ '#DC2626',
340
+ '#FF2E74',
341
+ '#DB2777',
342
+ ] as const;
343
+
344
+ export type RepeatDaysType =
345
+ | 'monday'
346
+ | 'tuesday'
347
+ | 'wednesday'
348
+ | 'thursday'
349
+ | 'friday'
350
+ | 'saturday'
351
+ | 'sunday';
352
+ export type RepeatIntervalType = 'day' | 'week' | 'month';
353
+
354
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
355
+
356
+ export const SUPPORTED_TYPES = [
357
+ 'chat',
358
+ 'sticker',
359
+ 'image',
360
+ 'video',
361
+ 'document',
362
+ 'vcard',
363
+ 'multi_vcard',
364
+ 'audio',
365
+ 'ptt',
366
+ 'poll_creation',
367
+ 'location',
368
+ 'ciphertext',
369
+ ] as const;
370
+
371
+ export type SendMessageContent = {
372
+ message_type?: (typeof SUPPORTED_TYPES)[number];
373
+ body?: string;
374
+ media?: MediaType;
375
+ contact_ids?: string[];
376
+ location?: {
377
+ latitude: string;
378
+ longitude: string;
379
+ options?: { name?: string; address?: string; url?: string };
380
+ };
381
+ poll?: PollSendType;
382
+ quoted_message_id?: string;
383
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
384
+ broadcast_id?: string;
385
+ performed_by?: string;
386
+ };
387
+
388
+ export type QuickReplyContent = Omit<
389
+ SendMessageContent,
390
+ 'broadcast_id' | 'variables'
391
+ >;
392
+
393
+ export type ScheduleMessagePayload = {
394
+ scheduled_id?: string;
395
+ is_repeat?: boolean | null;
396
+ scheduled_at: string;
397
+ repeat_config?: {
398
+ repeat_ends?: string;
399
+ repeat_interval?: RepeatIntervalType;
400
+ repeat_value?: number;
401
+ repeat_days?: RepeatDaysType[];
402
+ };
403
+ };
404
+
405
+ export type BroadcastVariableType = {
406
+ chat_id: string;
407
+ values: { [key: string]: string };
408
+ };
409
+
410
+ export type BroadcastMessagePayload = SendMessageContent & {
411
+ chat_ids: string[];
412
+ broadcast_id?: string;
413
+ variables?: BroadcastVariableType[];
414
+ delay?: number;
415
+ };
416
+
417
+ export type SingleMessagePayload = SendMessageContent & {
418
+ chat_id: string;
419
+ job_id?: string;
420
+ priority?: number;
421
+ };
422
+
423
+ export type MessageAttachmentFileTypes =
424
+ | 'image'
425
+ | 'audio'
426
+ | 'document'
427
+ | 'video';
428
+
429
+ export type AttachmentFileType = {
430
+ result: string;
431
+ file: File | null;
432
+ type: MessageAttachmentFileTypes;
433
+ localFileURL?: string;
434
+ };
435
+
436
+ export type AttachmentLinkType = {
437
+ link: {
438
+ url: string;
439
+ type: MessageAttachmentFileTypes;
440
+ name: string;
441
+ mimetype?: string;
442
+ };
443
+ };
444
+
445
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
446
+
447
+ /* -------------------------------- BROADCAST ------------------------------- */
448
+
449
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
450
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
451
+ } & {
452
+ chats: ChatType[];
453
+ };
454
+
455
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
456
+
457
+ export type ChatLogType = {
458
+ log: Tables<'view_chat_logs'>;
459
+ operations: Tables<'tbl_chat_logs'>[];
460
+ };
461
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
462
+
463
+ export type ChatParticipantOperationPayload = {
464
+ participant_ids: string[];
465
+ chat_ids: string[];
466
+ performed_by: string;
467
+ };
468
+
469
+ export type ChatOperationReturn = {
470
+ [participant_id: string]: {
471
+ is_success: boolean;
472
+ message?: string;
473
+ code?: number;
474
+ isInviteV4Sent?: boolean;
475
+ };
476
+ };
477
+
478
+ /* ----------------------- BILLING - STRIPE ----------------------- */
479
+
480
+ export type StripeSubscription = _Stripe.Subscription;
481
+ export type StripeCustomer = _Stripe.Customer;
482
+ export type StripeCoupon = _Stripe.Coupon;
483
+ export type StripePrice = _Stripe.Price;
484
+ export type Stripe = _Stripe;
485
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
486
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
487
+
488
+ /* -------------------------------- REALTIME -------------------------------- */
489
+
490
+ export type PhoneStateType = {
491
+ loading: boolean;
492
+ state: string;
493
+ sync: number;
494
+ percent: number | null;
495
+ message?: string;
496
+ error?: string;
497
+ };
498
+
499
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
500
+
501
+ export type ChatInfoType = Merge<
502
+ ChatType,
503
+ {
504
+ members: {
505
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
506
+ } | null;
507
+ chat_labels: string | null;
508
+ custom_properties: { [key: string]: string } | null;
509
+ }
510
+ >;
511
+
512
+ export type TicketInfoType = {
513
+ chat: ChatInfoType;
514
+ message: {
515
+ body: string;
516
+ chat_id: string;
517
+ org_phone: string;
518
+ timestamp: string;
519
+ media_path: string;
520
+ message_id: string;
521
+ sender_name: string;
522
+ performed_by: string;
523
+ sender_phone: string;
524
+ };
525
+ ticket: {
526
+ org_id: string;
527
+ status: string;
528
+ subject: string;
529
+ assignee: string;
530
+ due_date: string;
531
+ priority: 0 | 1 | 2 | 3 | 4;
532
+ raised_by: string;
533
+ ticket_id: string;
534
+ created_at: string;
535
+ assigned_by: string;
536
+ ticket_labels: string;
537
+ quoted_message_id: string;
538
+ ticket_custom_properties: { [key: string]: string } | null;
539
+ };
540
+ attached_messages: {
541
+ body: string;
542
+ chat_id: string;
543
+ org_phone: string;
544
+ timestamp: string;
545
+ media_path: string;
546
+ message_id: string;
547
+ sender_name: string;
548
+ performed_by: string;
549
+ sender_phone: string;
550
+ }[];
551
+ };
552
+
553
+ export type IntegrationLogObjectType =
554
+ | 'chat'
555
+ | 'message'
556
+ | 'reaction'
557
+ | 'ticket';
558
+
559
+ export enum IntegrationLogType {
560
+ NEW_CHAT = 'chat.created',
561
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
562
+ NEW_MESSAGE = 'message.created',
563
+ MESSAGE_UPDATED = 'message.updated',
564
+ MESSAGE_DELETED = 'message.deleted',
565
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
566
+ REACTION_CREATED = 'reaction.created',
567
+ REACTION_UPDATED = 'reaction.updated',
568
+ NEW_TICKET = 'ticket.created',
569
+ TICKET_UPDATED = 'ticket.updated',
570
+ TICKET_DELETED = 'ticket.deleted',
571
+ MESSAGE_FLAGGED = 'message.flagged',
572
+ MESSAGE_UNFLAGGED = 'message.unflagged',
573
+ }
574
+
575
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
576
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
577
+ ? TicketInfoType
578
+ : T extends IntegrationLogType.NEW_CHAT
579
+ ? Tables<'tbl_chats'>
580
+ : T extends
581
+ | IntegrationLogType.NEW_MESSAGE
582
+ | IntegrationLogType.MESSAGE_UPDATED
583
+ | IntegrationLogType.MESSAGE_DELETED
584
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
585
+ | IntegrationLogType.MESSAGE_FLAGGED
586
+ | IntegrationLogType.MESSAGE_UNFLAGGED
587
+ ? Tables<'tbl_chat_messages'>
588
+ : T extends
589
+ | IntegrationLogType.REACTION_CREATED
590
+ | IntegrationLogType.REACTION_UPDATED
591
+ ? Tables<'tbl_chat_reactions'>
592
+ : {
593
+ [key: string]: unknown;
594
+ };
595
+
596
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
597
+ OverrideProperties<
598
+ Tables<'tbl_integration_logs'>,
599
+ {
600
+ integration_name: T;
601
+ metadata: {
602
+ event: IntegrationLogMetadataType<T> & {
603
+ event_type: string;
604
+ org_id: string;
605
+ previous_attributes: {
606
+ [key: string]: unknown;
607
+ };
608
+ };
609
+ hook_id: string;
610
+ name: string;
611
+ };
612
+ }
613
+ >;
614
+
615
+ export type APIAuthDetails = {
616
+ org_details: Tables<'view_org'> | null;
617
+ phone_details: Tables<'tbl_org_phones'> | null;
618
+ token_details: Tables<'tbl_integration_tokens'> | null;
619
+ };
620
+
621
+ export type WebhookDataType = OverrideProperties<
622
+ Tables<'tbl_integration_hooks'>,
623
+ {
624
+ integration_name: string[];
625
+ }
626
+ >;
627
+
628
+ export type HubspotObjectDataType = {
629
+ createdAt: string;
630
+ archived: boolean;
631
+ id: string;
632
+ type: 'contacts' | 'tickets' | 'companies';
633
+ properties: Record<
634
+ string,
635
+ {
636
+ groupLabel: string;
637
+ groupName: string;
638
+ propertyKeyName: string;
639
+ propertyKey: string;
640
+ propertyInternalValue: string;
641
+ propertyValue: string;
642
+ propertyType: string;
643
+ propertyFieldType: string;
644
+ }[]
645
+ >;
646
+ };
647
+
648
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
649
+
650
+ export type UserPreferences = {
651
+ theme: 'light' | 'dark';
652
+ language: 'en' | 'es';
653
+ left_sidebar_open: boolean;
654
+ right_sidepanel_open: boolean;
655
+ sync_wa_unread_count: boolean;
656
+ pinned_chats: string[];
657
+ archived_chats: string[];
658
+ closed_chats: Record<string, number>;
659
+ periskope_chat_limit: number;
660
+ notifications: Record<string, boolean>;
661
+ };
662
+
663
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
664
+
665
+ export type PollSendType = {
666
+ pollName: string;
667
+ pollOptions: string[];
668
+ options?: {
669
+ allowMultipleAnswers?: boolean;
670
+ messageSecret?: number[] | null;
671
+ pollId?: string;
672
+ };
673
+ };
674
+
675
+ export type PollResultType = {
676
+ [name: string]: Record<string, string>;
677
+ };
678
+
679
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
680
+
681
+ export type CreateGroupOptions = {
682
+ messagesAdminsOnly?: boolean;
683
+ infoAdminsOnly?: boolean;
684
+ addMembersAdminsOnly?: boolean;
685
+ image?: string;
686
+ name?: string;
687
+ description?: string;
688
+ initiated_by?: string;
689
+ admins?: string[];
690
+ };
691
+
692
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
693
+
694
+ export type DeliveryInfoType = {
695
+ delivered: Record<string, number | undefined>;
696
+ read: Record<string, number | undefined>;
697
+ pending: string[];
698
+ read_count: number;
699
+ delivered_count: number;
700
+ };
701
+
702
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
703
+
704
+ export type OrgCreditsType = {
705
+ org_id: string;
706
+ recurring_allowance: number; // recurring credits replenished every month
707
+ recurring_balance: number; // recurring credits remaining in current month
708
+ topup_balance: number; // topup credits remaining
709
+ total_credits_used: number; // total credits used in current month
710
+ next_renewal_date: string;
711
+ };
712
+
713
+ /* --------------------------------- RULE INFO TYPE -------------------------------- */
714
+
715
+ export type ChatRuleInfoType = Merge<
716
+ Pick<
717
+ Tables<'view_chats'>,
718
+ | 'assigned_to'
719
+ | 'chat_id'
720
+ | 'chat_name'
721
+ | 'chat_type'
722
+ | 'created_at'
723
+ | 'group_description'
724
+ | 'info_admins_only'
725
+ | 'org_id'
726
+ | 'org_phone'
727
+ | 'chat_org_phones'
728
+ | 'messages_admins_only'
729
+ | 'custom_properties'
730
+ | 'initiated_by'
731
+ >,
732
+ {
733
+ has_flagged_messages: boolean;
734
+ labels: string[];
735
+ members: string[];
736
+ custom_properties: { [key: string]: string } | null;
737
+ }
738
+ >;
739
+
740
+ export type SenderRuleInfoType = Merge<
741
+ Omit<
742
+ Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
743
+ | 'verified_name'
744
+ | 'verified_level'
745
+ | 'updated_at'
746
+ | 'short_name'
747
+ | 'pushname'
748
+ | 'periskope_name'
749
+ | 'org_phone'
750
+ | 'number'
751
+ | 'name'
752
+ | 'label_ids'
753
+ | 'is_wa_contact'
754
+ | 'is_user'
755
+ | 'is_my_contact'
756
+ | 'is_me'
757
+ | 'is_imported'
758
+ | 'is_group'
759
+ | 'is_blocked'
760
+ | 'contact_color'
761
+ | 'business_profile'
762
+ | 'id'
763
+ | 'contact_image'
764
+ | 'contact_type'
765
+ | 'chat_id'
766
+ | 'is_business'
767
+ | 'is_enterprise'
768
+ | 'is_super_admin'
769
+ >,
770
+ {
771
+ is_internal: boolean;
772
+ labels: string[] | null;
773
+ }
774
+ >;
775
+
776
+ export type MessageRuleInfoType = {
777
+ chat: ChatRuleInfoType;
778
+ sender: SenderRuleInfoType;
779
+ message: OverrideProperties<
780
+ Omit<
781
+ Tables<'tbl_chat_messages'>,
782
+ | 'vcards'
783
+ | 'updated_at'
784
+ | 'unique_id'
785
+ | 'token'
786
+ | 'to'
787
+ | 'sent_message_id'
788
+ | 'raw_data'
789
+ | 'delivery_info'
790
+ | 'poll_results'
791
+ | 'poll_info'
792
+ | 'order_id'
793
+ | 'mentioned_ids'
794
+ | 'media_key'
795
+ | 'location'
796
+ | 'links'
797
+ | 'is_status'
798
+ | 'is_starred'
799
+ | 'is_gif'
800
+ | 'is_forwarded'
801
+ | 'is_ephemeral'
802
+ | 'is_deleted'
803
+ | 'fts'
804
+ | 'quoted_message_id'
805
+ | 'invite_v4'
806
+ | 'id'
807
+ | 'has_reaction'
808
+ | 'has_media'
809
+ | 'duration'
810
+ | 'broadcast'
811
+ | 'broadcast_id'
812
+ | 'device_type'
813
+ | 'forwarding_score'
814
+ | 'from'
815
+ | 'from_me'
816
+ | 'prev_body'
817
+ | 'flag_response_time'
818
+ | 'flag_metadata'
819
+ | 'ack'
820
+ >,
821
+ {
822
+ media: MediaType | null;
823
+ }
824
+ >;
825
+ };
826
+
827
+ export type ReactionRuleInfoType = {
828
+ chat: ChatRuleInfoType;
829
+ sender: SenderRuleInfoType;
830
+ message: MessageRuleInfoType['message'];
831
+ reaction: Pick<
832
+ Tables<'tbl_chat_reactions'>,
833
+ 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
834
+ >;
835
+ };
836
+
837
+ export type TicketRuleInfoType = {
838
+ chat: ChatRuleInfoType;
839
+ sender: SenderRuleInfoType;
840
+ ticket: Merge<
841
+ Pick<
842
+ Tables<'tbl_chat_tickets'>,
843
+ | 'org_id'
844
+ | 'status'
845
+ | 'chat_id'
846
+ | 'subject'
847
+ | 'assignee'
848
+ | 'due_date'
849
+ | 'priority'
850
+ | 'raised_by'
851
+ | 'ticket_id'
852
+ | 'created_at'
853
+ | 'is_deleted'
854
+ >,
855
+ {
856
+ labels: string[] | null;
857
+ custom_properties: { [key: string]: string } | null;
858
+ }
859
+ >;
860
+ message: MessageRuleInfoType['message'];
861
+ };
862
+ export type FeatureFlagReturnType = Record<string, boolean>;
863
+
864
+ export type RuleLogsType = OverrideProperties<
865
+ Tables<'tbl_rules_logs'>,
866
+ {
867
+ actions_progress: {
868
+ action_id: string;
869
+ action_type: Rule['actions'][number]['type'];
870
+ action_delay: Rule['actions'][number]['delay'];
871
+ ran_at: string | null;
872
+ action_status: 'success' | 'failed' | 'pending';
873
+ action_response: {
874
+ success: boolean;
875
+ data: Record<string, unknown> | null;
876
+ error: {
877
+ message: string;
878
+ name: string;
879
+ stack?: string;
880
+ _error?: Error | Record<string, unknown>;
881
+ } | null;
882
+ };
883
+ }[];
884
+ metadata: {
885
+ conditions: Rule['conditions'];
886
+ actions: Rule['actions'];
887
+ rule_metadata: Pick<
888
+ Rule,
889
+ 'rule_name' | 'last_updated_at' | 'last_updated_by'
890
+ >;
891
+ data: Record<string, unknown>;
892
+ };
893
+ conditions_progress: {
894
+ is_valid: boolean;
895
+ validation_progress: Record<
896
+ string,
897
+ {
898
+ res: boolean;
899
+ filter: Filter;
900
+ value: unknown;
901
+ }
902
+ >;
903
+ checked_at: string | null;
904
+ };
905
+ }
906
+ >;
907
+
908
+ /************************** TASKS ***************************/
909
+
910
+ export type TaskType = OverrideProperties<
911
+ Tables<'tbl_org_tasks'>,
912
+ {
913
+ reminder_setting: {
914
+ remind_in:
915
+ | `${number} ${'minutes' | 'hours' | 'days'} ${'before' | 'after'}`
916
+ | string
917
+ | null;
918
+ repeat?: {
919
+ frequency: number;
920
+ interval: 'days' | 'weeks' | 'months' | 'years';
921
+ end: 'never' | 'after' | 'on';
922
+ on?: string;
923
+ };
924
+ } | null;
925
+ associated_object_metadata:
926
+ | {
927
+ type: 'chat';
928
+ index: 'chat_id';
929
+ id: string;
930
+ object: ChatType;
931
+ }
932
+ | {
933
+ type: 'message';
934
+ index: 'message_id';
935
+ id: string;
936
+ object: MessageType;
937
+ }
938
+ | {
939
+ type: 'ticket';
940
+ index: 'ticket_id';
941
+ id: string;
942
+ object: TicketType;
943
+ }
944
+ | null;
945
+ status: 'open' | 'inprogress' | 'closed';
946
+ priority: 1 | 2 | 3;
947
+ completed_metadata?: {
948
+ completed_at: string;
949
+ completed_by: string;
950
+ } | null;
951
+ type: 'todo' | 'chat' | 'message' | 'ticket';
952
+ }
953
+ >;
954
+
955
+ type Choice = {
956
+ id: number;
957
+ label: string;
958
+ value: string;
959
+ position: number;
960
+ };
961
+
962
+ export type FreshdeskCustomFieldType = {
963
+ id: number;
964
+ name: string;
965
+ label: string;
966
+ position: number;
967
+ required_for_agents: boolean;
968
+ archived: boolean;
969
+ customers_can_edit: boolean;
970
+ label_for_customers: string;
971
+ required_for_customers: boolean;
972
+ customers_can_filter: boolean;
973
+ required_for_closure: boolean;
974
+ displayed_to_customers: boolean;
975
+ type: string;
976
+ default: boolean;
977
+ created_at: string;
978
+ updated_at: string;
979
+ choices?: Choice[];
980
+ };