@periskope/types 0.6.169 → 0.6.170

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