ghl-sdk 0.5.2

Unofficial async Rust SDK for the GoHighLevel (HighLevel) API 2.0 — OAuth 2.0, Private Integration Tokens, rate-limit-aware retries, paginated streams
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
// @generated by xtask/generate_services.py — do not edit by hand.
//! `conversations` — typed methods for all 25 API v3 operations
//! in this module.
//!
//! Access via [`Ghl::v3`](crate::Ghl::v3)`().conversations()`. These endpoints send `Version: v3`.
//!
//! Request and response types come from [`ghl_models::v3::conversations`](https://docs.rs/ghl-models/latest/ghl_models/v3/conversations/); every endpoint is also documented in the
//! [`conversations` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/conversations.md).
//!
//! Enable with `features = ["conversations"]`.

#![allow(clippy::too_many_arguments)]

use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v3::conversations as models;

/// Typed access to the `conversations` API v3 surface (25 operations). Obtained via
/// [`Ghl::v3`](crate::Ghl::v3)`().conversations()`.
#[derive(Debug, Clone)]
pub struct ConversationsService {
    pub(crate) client: Ghl,
}

impl ConversationsService {
    pub(crate) fn new(client: Ghl) -> Self {
        Self { client }
    }
}

/// Query parameters for [`ConversationsService::export_messages_by_location_id`].
#[derive(Debug, Clone, Default)]
pub struct ExportMessagesByLocationIdParams {
    /// Location ID to filter messages by
    /// Required by the API.
    pub location_id: String,
    /// Number of messages to return per page
    pub limit: Option<f64>,
    /// Cursor for pagination. Pass the nextCursor from previous response to get next page.
    pub cursor: Option<String>,
    /// Field to sort by
    /// Allowed values: `createdAt`, `updatedAt`.
    pub sort_by: Option<String>,
    /// Sort order
    /// Allowed values: `asc`, `desc`.
    pub sort_order: Option<String>,
    /// Filter messages by conversation ID
    pub conversation_id: Option<String>,
    /// Filter messages by contact ID
    pub contact_id: Option<String>,
    /// Filter by message channel. Optional - when not provided, all non-email message types
    /// will be returned including activity messages (opportunity updates, appointments,
    /// etc.). To fetch email messages, you must explicitly set channel=Email.
    /// Allowed values: `Call`, `SMS`, `Email`, `WhatsApp`, `Instagram`, `Facebook`.
    pub channel: Option<String>,
    /// Start date to filter messages by
    pub start_date: Option<String>,
    /// End date to filter messages by
    pub end_date: Option<String>,
}

impl ExportMessagesByLocationIdParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
            ..Default::default()
        }
    }

    /// Number of messages to return per page
    pub fn limit(mut self, v: f64) -> Self {
        self.limit = Some(v);
        self
    }

    /// Cursor for pagination. Pass the nextCursor from previous response to get next page.
    pub fn cursor(mut self, v: impl Into<String>) -> Self {
        self.cursor = Some(v.into());
        self
    }

    /// Field to sort by
    pub fn sort_by(mut self, v: impl Into<String>) -> Self {
        self.sort_by = Some(v.into());
        self
    }

    /// Sort order
    pub fn sort_order(mut self, v: impl Into<String>) -> Self {
        self.sort_order = Some(v.into());
        self
    }

    /// Filter messages by conversation ID
    pub fn conversation_id(mut self, v: impl Into<String>) -> Self {
        self.conversation_id = Some(v.into());
        self
    }

    /// Filter messages by contact ID
    pub fn contact_id(mut self, v: impl Into<String>) -> Self {
        self.contact_id = Some(v.into());
        self
    }

    /// Filter by message channel. Optional - when not provided, all non-email message types
    /// will be returned including activity messages (opportunity updates, appointments,
    /// etc.). To fetch email messages, you must explicitly set channel=Email.
    pub fn channel(mut self, v: impl Into<String>) -> Self {
        self.channel = Some(v.into());
        self
    }

    /// Start date to filter messages by
    pub fn start_date(mut self, v: impl Into<String>) -> Self {
        self.start_date = Some(v.into());
        self
    }

    /// End date to filter messages by
    pub fn end_date(mut self, v: impl Into<String>) -> Self {
        self.end_date = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
        if let Some(v) = &self.limit {
            q.push(("limit".into(), v.to_string()));
        }
        if let Some(v) = &self.cursor {
            q.push(("cursor".into(), v.to_string()));
        }
        if let Some(v) = &self.sort_by {
            q.push(("sortBy".into(), v.to_string()));
        }
        if let Some(v) = &self.sort_order {
            q.push(("sortOrder".into(), v.to_string()));
        }
        if let Some(v) = &self.conversation_id {
            q.push(("conversationId".into(), v.to_string()));
        }
        if let Some(v) = &self.contact_id {
            q.push(("contactId".into(), v.to_string()));
        }
        if let Some(v) = &self.channel {
            q.push(("channel".into(), v.to_string()));
        }
        if let Some(v) = &self.start_date {
            q.push(("startDate".into(), v.to_string()));
        }
        if let Some(v) = &self.end_date {
            q.push(("endDate".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`ConversationsService::search_conversations`].
#[derive(Debug, Clone, Default)]
pub struct SearchConversationsParams {
    /// Location Id
    /// Required by the API.
    pub location_id: String,
    /// Contact Id
    pub contact_id: Option<String>,
    /// User IDs that conversations are assigned to. Multiple IDs can be provided as
    /// comma-separated values. Use "unassigned" to fetch conversations not assigned to any
    /// user.
    pub assigned_to: Option<String>,
    /// User IDs of followers to filter conversations by. Multiple IDs can be provided as
    /// comma-separated values.
    pub followers: Option<String>,
    /// User Id of the mention. Multiple values are comma separated.
    pub mentions: Option<String>,
    /// Search paramater as a string
    pub query: Option<String>,
    /// Sort paramater - asc or desc
    /// Allowed values: `asc`, `desc`.
    pub sort: Option<String>,
    /// Search to begin after the specified date - should contain the sort value of the last
    /// document
    pub start_after_date: Option<String>,
    /// Id of the conversation
    pub id: Option<String>,
    /// Limit of conversations - Default is 20
    pub limit: Option<f64>,
    /// Type of the last message in the conversation as a string
    /// Allowed values: `TYPE_CALL`, `TYPE_SMS`, `TYPE_RCS`, `TYPE_EMAIL`,
    /// `TYPE_SMS_REVIEW_REQUEST`, `TYPE_WEBCHAT`, `TYPE_SMS_NO_SHOW_REQUEST`,
    /// `TYPE_CAMPAIGN_SMS`, `TYPE_CAMPAIGN_CALL`, `TYPE_CAMPAIGN_EMAIL`.
    pub last_message_type: Option<String>,
    /// Action of the last outbound message in the conversation as string.
    /// Allowed values: `automated`, `manual`.
    pub last_message_action: Option<String>,
    /// Direction of the last message in the conversation as string.
    /// Allowed values: `inbound`, `outbound`.
    pub last_message_direction: Option<String>,
    /// The status of the conversation to be filtered - all, read, unread, starred
    /// Allowed values: `all`, `read`, `unread`, `starred`, `recents`.
    pub status: Option<String>,
    /// The sorting of the conversation to be filtered as - manual messages or all messages
    /// Allowed values: `last_manual_message_date`, `last_message_date`, `score_profile`,
    /// `overdue_at`, `due_at`.
    pub sort_by: Option<String>,
    /// Id of score profile on which sortBy.ScoreProfile should sort on
    pub sort_score_profile: Option<String>,
    /// Id of score profile on which conversations should get filtered out, works with
    /// scoreProfileMin & scoreProfileMax
    pub score_profile: Option<String>,
    /// Minimum value for score
    pub score_profile_min: Option<f64>,
    /// Maximum value for score
    pub score_profile_max: Option<f64>,
    /// Start date filter for dateAdded field (Unix timestamp in milliseconds)
    pub start_date: Option<f64>,
    /// End date filter for dateAdded field (Unix timestamp in milliseconds)
    pub end_date: Option<f64>,
}

impl SearchConversationsParams {
    /// Start from the parameters the API requires.
    pub fn new(location_id: impl Into<String>) -> Self {
        Self {
            location_id: location_id.into(),
            ..Default::default()
        }
    }

    /// Contact Id
    pub fn contact_id(mut self, v: impl Into<String>) -> Self {
        self.contact_id = Some(v.into());
        self
    }

    /// User IDs that conversations are assigned to. Multiple IDs can be provided as
    /// comma-separated values. Use "unassigned" to fetch conversations not assigned to any
    /// user.
    pub fn assigned_to(mut self, v: impl Into<String>) -> Self {
        self.assigned_to = Some(v.into());
        self
    }

    /// User IDs of followers to filter conversations by. Multiple IDs can be provided as
    /// comma-separated values.
    pub fn followers(mut self, v: impl Into<String>) -> Self {
        self.followers = Some(v.into());
        self
    }

    /// User Id of the mention. Multiple values are comma separated.
    pub fn mentions(mut self, v: impl Into<String>) -> Self {
        self.mentions = Some(v.into());
        self
    }

    /// Search paramater as a string
    pub fn query(mut self, v: impl Into<String>) -> Self {
        self.query = Some(v.into());
        self
    }

    /// Sort paramater - asc or desc
    pub fn sort(mut self, v: impl Into<String>) -> Self {
        self.sort = Some(v.into());
        self
    }

    /// Search to begin after the specified date - should contain the sort value of the last
    /// document
    pub fn start_after_date(mut self, v: impl Into<String>) -> Self {
        self.start_after_date = Some(v.into());
        self
    }

    /// Id of the conversation
    pub fn id(mut self, v: impl Into<String>) -> Self {
        self.id = Some(v.into());
        self
    }

    /// Limit of conversations - Default is 20
    pub fn limit(mut self, v: f64) -> Self {
        self.limit = Some(v);
        self
    }

    /// Type of the last message in the conversation as a string
    pub fn last_message_type(mut self, v: impl Into<String>) -> Self {
        self.last_message_type = Some(v.into());
        self
    }

    /// Action of the last outbound message in the conversation as string.
    pub fn last_message_action(mut self, v: impl Into<String>) -> Self {
        self.last_message_action = Some(v.into());
        self
    }

    /// Direction of the last message in the conversation as string.
    pub fn last_message_direction(mut self, v: impl Into<String>) -> Self {
        self.last_message_direction = Some(v.into());
        self
    }

    /// The status of the conversation to be filtered - all, read, unread, starred
    pub fn status(mut self, v: impl Into<String>) -> Self {
        self.status = Some(v.into());
        self
    }

    /// The sorting of the conversation to be filtered as - manual messages or all messages
    pub fn sort_by(mut self, v: impl Into<String>) -> Self {
        self.sort_by = Some(v.into());
        self
    }

    /// Id of score profile on which sortBy.ScoreProfile should sort on
    pub fn sort_score_profile(mut self, v: impl Into<String>) -> Self {
        self.sort_score_profile = Some(v.into());
        self
    }

    /// Id of score profile on which conversations should get filtered out, works with
    /// scoreProfileMin & scoreProfileMax
    pub fn score_profile(mut self, v: impl Into<String>) -> Self {
        self.score_profile = Some(v.into());
        self
    }

    /// Minimum value for score
    pub fn score_profile_min(mut self, v: f64) -> Self {
        self.score_profile_min = Some(v);
        self
    }

    /// Maximum value for score
    pub fn score_profile_max(mut self, v: f64) -> Self {
        self.score_profile_max = Some(v);
        self
    }

    /// Start date filter for dateAdded field (Unix timestamp in milliseconds)
    pub fn start_date(mut self, v: f64) -> Self {
        self.start_date = Some(v);
        self
    }

    /// End date filter for dateAdded field (Unix timestamp in milliseconds)
    pub fn end_date(mut self, v: f64) -> Self {
        self.end_date = Some(v);
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
        if let Some(v) = &self.contact_id {
            q.push(("contactId".into(), v.to_string()));
        }
        if let Some(v) = &self.assigned_to {
            q.push(("assignedTo".into(), v.to_string()));
        }
        if let Some(v) = &self.followers {
            q.push(("followers".into(), v.to_string()));
        }
        if let Some(v) = &self.mentions {
            q.push(("mentions".into(), v.to_string()));
        }
        if let Some(v) = &self.query {
            q.push(("query".into(), v.to_string()));
        }
        if let Some(v) = &self.sort {
            q.push(("sort".into(), v.to_string()));
        }
        if let Some(v) = &self.start_after_date {
            q.push(("startAfterDate".into(), v.to_string()));
        }
        if let Some(v) = &self.id {
            q.push(("id".into(), v.to_string()));
        }
        if let Some(v) = &self.limit {
            q.push(("limit".into(), v.to_string()));
        }
        if let Some(v) = &self.last_message_type {
            q.push(("lastMessageType".into(), v.to_string()));
        }
        if let Some(v) = &self.last_message_action {
            q.push(("lastMessageAction".into(), v.to_string()));
        }
        if let Some(v) = &self.last_message_direction {
            q.push(("lastMessageDirection".into(), v.to_string()));
        }
        if let Some(v) = &self.status {
            q.push(("status".into(), v.to_string()));
        }
        if let Some(v) = &self.sort_by {
            q.push(("sortBy".into(), v.to_string()));
        }
        if let Some(v) = &self.sort_score_profile {
            q.push(("sortScoreProfile".into(), v.to_string()));
        }
        if let Some(v) = &self.score_profile {
            q.push(("scoreProfile".into(), v.to_string()));
        }
        if let Some(v) = &self.score_profile_min {
            q.push(("scoreProfileMin".into(), v.to_string()));
        }
        if let Some(v) = &self.score_profile_max {
            q.push(("scoreProfileMax".into(), v.to_string()));
        }
        if let Some(v) = &self.start_date {
            q.push(("startDate".into(), v.to_string()));
        }
        if let Some(v) = &self.end_date {
            q.push(("endDate".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`ConversationsService::get_messages_by_conversation_id`].
#[derive(Debug, Clone, Default)]
pub struct GetMessagesByConversationIdParams {
    /// Message ID of the last message in the list as a string
    pub last_message_id: Option<String>,
    /// Number of messages to be fetched from the conversation. Default limit is 20
    pub limit: Option<f64>,
    /// Types of message to fetched separated with comma
    /// Allowed values: `TYPE_CALL`, `TYPE_SMS`, `TYPE_RCS`, `TYPE_EMAIL`, `TYPE_FACEBOOK`,
    /// `TYPE_GMB`, `TYPE_INSTAGRAM`, `TYPE_WHATSAPP`, `TYPE_ACTIVITY_APPOINTMENT`,
    /// `TYPE_ACTIVITY_CONTACT`.
    pub type_: Option<String>,
}

impl GetMessagesByConversationIdParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Message ID of the last message in the list as a string
    pub fn last_message_id(mut self, v: impl Into<String>) -> Self {
        self.last_message_id = Some(v.into());
        self
    }

    /// Number of messages to be fetched from the conversation. Default limit is 20
    pub fn limit(mut self, v: f64) -> Self {
        self.limit = Some(v);
        self
    }

    /// Types of message to fetched separated with comma
    pub fn type_(mut self, v: impl Into<String>) -> Self {
        self.type_ = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.last_message_id {
            q.push(("lastMessageId".into(), v.to_string()));
        }
        if let Some(v) = &self.limit {
            q.push(("limit".into(), v.to_string()));
        }
        if let Some(v) = &self.type_ {
            q.push(("type".into(), v.to_string()));
        }
        q
    }
}

impl ConversationsService {
    /// Create Conversation
    ///
    /// Creates a new conversation with the data provided
    ///
    /// `POST /conversations/`
    ///
    /// Requires scope: `conversations.write`.
    pub async fn create_conversation(
        &self,
        body: &models::CreateConversationDto,
    ) -> Result<models::CreateConversationSuccessResponse> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Get transcription by Message ID
    ///
    /// Get the recording transcription for a message by passing the message id
    ///
    /// `GET /conversations/locations/{locationId}/messages/{messageId}/transcription`
    ///
    /// Requires scope: `conversations/message.readonly`.
    pub async fn get_transcription_by_message_id(
        &self,
        location_id: &str,
        message_id: &str,
    ) -> Result<models::GetMessageTranscriptionResponseDto> {
        let path = format!(
            "/conversations/locations/{}/messages/{}/transcription",
            crate::services::encode(location_id),
            crate::services::encode(message_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Download transcription by Message ID
    ///
    /// Download the recording transcription for a message by passing the message id
    ///
    /// `GET /conversations/locations/{locationId}/messages/{messageId}/transcription/download`
    ///
    /// Requires scope: `conversations/message.readonly`.
    pub async fn download_transcription_by_message_id(
        &self,
        location_id: &str,
        message_id: &str,
    ) -> Result<serde_json::Value> {
        let path = format!(
            "/conversations/locations/{}/messages/{}/transcription/download",
            crate::services::encode(location_id),
            crate::services::encode(message_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Send a new message
    ///
    /// Post the necessary fields for the API to send a new message.
    ///
    /// `POST /conversations/messages`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn send_a_new_message(
        &self,
        body: &models::SendMessageBodyDto,
    ) -> Result<models::SendMessageResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/messages",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Cancel a scheduled email message.
    ///
    /// Post the messageId for the API to delete a scheduled email message.
    ///
    /// `DELETE /conversations/messages/email/{emailMessageId}/schedule`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn cancel_a_scheduled_email_message(
        &self,
        email_message_id: &str,
    ) -> Result<models::CancelScheduledResponseDto> {
        let path = format!(
            "/conversations/messages/email/{}/schedule",
            crate::services::encode(email_message_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Get email by Id
    ///
    /// `GET /conversations/messages/email/{id}`
    ///
    /// Requires scope: `conversations/message.readonly`.
    pub async fn get_email_by_id(&self, id: &str) -> Result<models::GetEmailMessageResponseDto> {
        let path = format!(
            "/conversations/messages/email/{}",
            crate::services::encode(id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Update email message status
    ///
    /// Update delivery events, per-recipient statuses, and the overall message status for
    /// an email sent via a custom conversation provider. ### Authorization - Requires the
    /// `conversations/message.write` OAuth scope. - The calling OAuth app must own the
    /// conversation provider that originally sent the email. - Attempts to update emails
    /// sent via LC Email or Mailgun will return `403 Forbidden`. ### Updatable Fields
    /// **`status`** is required on every request. You may also include **`events`** and/or
    /// **`recipients`**. **`events`** — Aggregate delivery event counters (integers).
    /// Counters are merged into the e
    ///
    /// `PUT /conversations/messages/email/{id}/status`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn update_email_message_status(
        &self,
        id: &str,
        body: &models::UpdateEmailMessageStatusDto,
    ) -> Result<models::UpdateEmailMessageStatusResponseDto> {
        let path = format!(
            "/conversations/messages/email/{}/status",
            crate::services::encode(id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
            .await
    }

    /// Export messages by location ID
    ///
    /// Export messages for a specific location with cursor-based pagination support.
    /// Response includes messageType (string), source, and subType fields. The channel
    /// parameter is optional - if not provided, all non-email message types will be
    /// returned including activity messages (opportunity updates, appointments, etc.).
    ///
    /// `GET /conversations/messages/export`
    ///
    /// Requires scope: `conversations/message.readonly`.
    pub async fn export_messages_by_location_id(
        &self,
        params: &ExportMessagesByLocationIdParams,
    ) -> Result<models::ExportMessagesResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/conversations/messages/export",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Add an inbound message
    ///
    /// Post the necessary fields for the API to add a new inbound message.
    ///
    /// `POST /conversations/messages/inbound`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn add_an_inbound_message(
        &self,
        body: &models::ProcessMessageBodyDto,
    ) -> Result<models::ProcessMessageResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/messages/inbound",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Add an external outbound call
    ///
    /// Post the necessary fields for the API to add a new outbound call.
    ///
    /// `POST /conversations/messages/outbound`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn add_an_external_outbound_call(
        &self,
        body: &models::ProcessOutboundMessageBodyDto,
    ) -> Result<models::ProcessMessageResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/messages/outbound",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Send a review reply to Google My Business
    ///
    /// Post a reply to a customer review on Google My Business This endpoint is
    /// internal-only and is not supported for OAuth or public API integrations. It will be
    /// removed from the public OpenAPI specification in a future release.
    ///
    /// `POST /conversations/messages/review-reply`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn send_a_review_reply_to_google_my_business(
        &self,
        body: &models::SendReviewReplyDto,
    ) -> Result<models::SendMessageResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/messages/review-reply",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Upload file attachments
    ///
    /// Post the necessary fields for the API to upload files. The files need to be a buffer
    /// with the key "fileAttachment". The allowed file types are: JPG JPEG PNG MP4 MPEG ZIP
    /// RAR PDF DOC DOCX TXT MP3 WAV The API will return an object with the URLs
    ///
    /// `POST /conversations/messages/upload`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn upload_file_attachments(
        &self,
        body: &serde_json::Value,
    ) -> Result<models::UploadFilesResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/messages/upload",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Complete file upload
    ///
    /// Validates the uploaded file in GCS and returns the public URL. Call this endpoint
    /// after successfully uploading the file to the signed URL. This endpoint is
    /// internal-only and is not supported for OAuth or public API integrations. It will be
    /// removed from the public OpenAPI specification in a future release.
    ///
    /// `POST /conversations/messages/upload/complete`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn complete_file_upload(
        &self,
        body: &models::CompleteFileUploadDto,
    ) -> Result<models::CompleteFileUploadResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/messages/upload/complete",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Initiate file upload to GCS
    ///
    /// Generates a signed URL for direct file upload to Google Cloud Storage. Returns a
    /// signed URL valid for 15 minutes. Upload file via PUT request, then call /complete to
    /// finalize. This endpoint is internal-only and is not supported for OAuth or public
    /// API integrations. It will be removed from the public OpenAPI specification in a
    /// future release.
    ///
    /// `POST /conversations/messages/upload/initiate`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn initiate_file_upload_to_gcs(
        &self,
        body: &models::InitiateFileUploadDto,
    ) -> Result<models::InitiateFileUploadResponseDto> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/messages/upload/initiate",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Get message by message id
    ///
    /// Get message by message id.
    ///
    /// `GET /conversations/messages/{id}`
    ///
    /// Requires scope: `conversations/message.readonly`.
    pub async fn get_message_by_message_id(
        &self,
        id: &str,
    ) -> Result<models::GetMessageResponseDto> {
        let path = format!("/conversations/messages/{}", crate::services::encode(id));
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Add message attachments
    ///
    /// Set attachments on an existing message (replaces existing). Maximum 5 URLs.
    /// Supported for TYPE_CUSTOM_CALL (34) and TYPE_CALL (1) with subType EXTERNAL_CALL.
    ///
    /// `PUT /conversations/messages/{messageId}/attachments`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn add_message_attachments(
        &self,
        message_id: &str,
        body: &models::AddMessageAttachmentsDto,
    ) -> Result<serde_json::Value> {
        let path = format!(
            "/conversations/messages/{}/attachments",
            crate::services::encode(message_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
            .await
    }

    /// Get Recording by Message ID
    ///
    /// Get the recording for a message by passing the message id
    ///
    /// `GET /conversations/messages/{messageId}/locations/{locationId}/recording`
    ///
    /// Requires scope: `conversations/message.readonly`.
    pub async fn get_recording_by_message_id(
        &self,
        message_id: &str,
        location_id: &str,
    ) -> Result<serde_json::Value> {
        let path = format!(
            "/conversations/messages/{}/locations/{}/recording",
            crate::services::encode(message_id),
            crate::services::encode(location_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Cancel a scheduled message.
    ///
    /// Post the messageId for the API to delete a scheduled message.
    ///
    /// `DELETE /conversations/messages/{messageId}/schedule`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn cancel_a_scheduled_message(
        &self,
        message_id: &str,
    ) -> Result<models::CancelScheduledResponseDto> {
        let path = format!(
            "/conversations/messages/{}/schedule",
            crate::services::encode(message_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Update message status
    ///
    /// Post the necessary fields for the API to update message status.
    ///
    /// `PUT /conversations/messages/{messageId}/status`
    ///
    /// Requires scope: `conversations/message.write`.
    pub async fn update_message_status(
        &self,
        message_id: &str,
        body: &models::UpdateMessageStatusDto,
    ) -> Result<models::SendMessageResponseDto> {
        let path = format!(
            "/conversations/messages/{}/status",
            crate::services::encode(message_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
            .await
    }

    /// Agent/Ai-Bot is typing a message indicator for live chat
    ///
    /// Agent/AI-Bot will call this when they are typing a message in live chat message
    ///
    /// `POST /conversations/providers/live-chat/typing`
    ///
    /// Requires scope: `conversations/livechat.write`.
    pub async fn agent_ai_bot_is_typing_a_message_indicator_for_live_chat(
        &self,
        body: &models::UserTypingBody,
    ) -> Result<models::CreateLiveChatMessageFeedbackResponse> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversations/providers/live-chat/typing",
                &query,
                Some(body),
                Some("v3"),
            )
            .await
    }

    /// Search Conversations
    ///
    /// Returns a list of all conversations matching the search criteria along with the sort
    /// and filter options selected.
    ///
    /// `GET /conversations/search`
    ///
    /// Requires scope: `conversations.readonly`.
    pub async fn search_conversations(
        &self,
        params: &SearchConversationsParams,
    ) -> Result<models::SendConversationResponseDto> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/conversations/search",
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Delete Conversation
    ///
    /// Delete the conversation details based on the conversation ID
    ///
    /// `DELETE /conversations/{conversationId}`
    ///
    /// Requires scope: `conversations.write`.
    pub async fn delete_conversation(
        &self,
        conversation_id: &str,
    ) -> Result<models::DeleteConversationSuccessfulResponse> {
        let path = format!(
            "/conversations/{}",
            crate::services::encode(conversation_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("v3"),
            )
            .await
    }

    /// Get Conversation
    ///
    /// Get the conversation details based on the conversation ID
    ///
    /// `GET /conversations/{conversationId}`
    ///
    /// Requires scope: `conversations.readonly`.
    pub async fn get_conversation(
        &self,
        conversation_id: &str,
    ) -> Result<models::GetConversationByIdResponse> {
        let path = format!(
            "/conversations/{}",
            crate::services::encode(conversation_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }

    /// Update Conversation
    ///
    /// Update the conversation details based on the conversation ID
    ///
    /// `PUT /conversations/{conversationId}`
    ///
    /// Requires scope: `conversations.write`.
    pub async fn update_conversation(
        &self,
        conversation_id: &str,
        body: &models::UpdateConversationDto,
    ) -> Result<models::GetConversationSuccessfulResponse> {
        let path = format!(
            "/conversations/{}",
            crate::services::encode(conversation_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(reqwest::Method::PUT, &path, &query, Some(body), Some("v3"))
            .await
    }

    /// Get messages by conversation id
    ///
    /// Get messages by conversation id.
    ///
    /// `GET /conversations/{conversationId}/messages`
    ///
    /// Requires scope: `conversations/message.readonly`.
    pub async fn get_messages_by_conversation_id(
        &self,
        conversation_id: &str,
        params: &GetMessagesByConversationIdParams,
    ) -> Result<models::GetMessagesByConversationResponseDto> {
        let path = format!(
            "/conversations/{}/messages",
            crate::services::encode(conversation_id)
        );
        let query = params.to_query();
        self.client
            .send_versioned(reqwest::Method::GET, &path, &query, None::<&()>, Some("v3"))
            .await
    }
}