simploxide_api_types/
commands.rs

1use super::*;
2use crate::utils::CommandSyntax;
3
4/// ### Address commands
5///
6/// Bots can use these commands to automatically check and create address when initialized
7///
8/// ----
9///
10/// Create bot address.
11///
12/// *Network usage*: interactive.
13///
14/// *Syntax:*
15///
16/// ```
17/// /_address <userId>
18/// ```
19#[derive(Debug, Clone, PartialEq)]
20#[cfg_attr(feature = "bon", derive(::bon::Builder))]
21pub struct ApiCreateMyAddress {
22    pub user_id: i64,
23}
24
25impl CommandSyntax for ApiCreateMyAddress {
26    fn interpret(&self) -> String {
27        let mut buf = String::with_capacity(64);
28        buf.push_str("/_address ");
29        buf.push_str(&self.user_id.to_string());
30        buf
31    }
32}
33
34/// ### Address commands
35///
36/// Bots can use these commands to automatically check and create address when initialized
37///
38/// ----
39///
40/// Delete bot address.
41///
42/// *Network usage*: background.
43///
44/// *Syntax:*
45///
46/// ```
47/// /_delete_address <userId>
48/// ```
49#[derive(Debug, Clone, PartialEq)]
50#[cfg_attr(feature = "bon", derive(::bon::Builder))]
51pub struct ApiDeleteMyAddress {
52    pub user_id: i64,
53}
54
55impl CommandSyntax for ApiDeleteMyAddress {
56    fn interpret(&self) -> String {
57        let mut buf = String::with_capacity(64);
58        buf.push_str("/_delete_address ");
59        buf.push_str(&self.user_id.to_string());
60        buf
61    }
62}
63
64/// ### Address commands
65///
66/// Bots can use these commands to automatically check and create address when initialized
67///
68/// ----
69///
70/// Get bot address and settings.
71///
72/// *Network usage*: no.
73///
74/// *Syntax:*
75///
76/// ```
77/// /_show_address <userId>
78/// ```
79#[derive(Debug, Clone, PartialEq)]
80#[cfg_attr(feature = "bon", derive(::bon::Builder))]
81pub struct ApiShowMyAddress {
82    pub user_id: i64,
83}
84
85impl CommandSyntax for ApiShowMyAddress {
86    fn interpret(&self) -> String {
87        let mut buf = String::with_capacity(64);
88        buf.push_str("/_show_address ");
89        buf.push_str(&self.user_id.to_string());
90        buf
91    }
92}
93
94/// ### Address commands
95///
96/// Bots can use these commands to automatically check and create address when initialized
97///
98/// ----
99///
100/// Add address to bot profile.
101///
102/// *Network usage*: interactive.
103///
104/// *Syntax:*
105///
106/// ```
107/// /_profile_address <userId> on|off
108/// ```
109#[derive(Debug, Clone, PartialEq)]
110#[cfg_attr(feature = "bon", derive(::bon::Builder))]
111pub struct ApiSetProfileAddress {
112    pub user_id: i64,
113    pub enable: bool,
114}
115
116impl CommandSyntax for ApiSetProfileAddress {
117    fn interpret(&self) -> String {
118        let mut buf = String::with_capacity(64);
119        buf.push_str("/_profile_address ");
120        buf.push_str(&self.user_id.to_string());
121        buf.push(' ');
122        if self.enable {
123            buf.push_str("on");
124        } else {
125            buf.push_str("off");
126        }
127        buf
128    }
129}
130
131/// ### Address commands
132///
133/// Bots can use these commands to automatically check and create address when initialized
134///
135/// ----
136///
137/// Set bot address settings.
138///
139/// *Network usage*: interactive.
140///
141/// *Syntax:*
142///
143/// ```
144/// /_address_settings <userId> <json(settings)>
145/// ```
146#[derive(Debug, Clone, PartialEq)]
147#[cfg_attr(feature = "bon", derive(::bon::Builder))]
148pub struct ApiSetAddressSettings {
149    pub user_id: i64,
150    pub settings: AddressSettings,
151}
152
153impl CommandSyntax for ApiSetAddressSettings {
154    fn interpret(&self) -> String {
155        let mut buf = String::with_capacity(1024);
156        buf.push_str("/_address_settings ");
157        buf.push_str(&self.user_id.to_string());
158        buf.push(' ');
159        buf.push_str(&serde_json::to_string(&self.settings).unwrap());
160        buf
161    }
162}
163
164/// ### Message commands
165///
166/// Commands to send, update, delete, moderate messages and set message reactions
167///
168/// ----
169///
170/// Send messages.
171///
172/// *Network usage*: background.
173///
174/// *Syntax:*
175///
176/// ```
177/// /_send <str(sendRef)>[ live=on][ ttl=<ttl>] json <json(composedMessages)>
178/// ```
179#[derive(Debug, Clone, PartialEq)]
180#[cfg_attr(feature = "bon", derive(::bon::Builder))]
181pub struct ApiSendMessages {
182    pub send_ref: ChatRef,
183    pub live_message: bool,
184    pub ttl: Option<i32>,
185    pub composed_messages: Vec<ComposedMessage>,
186}
187
188impl CommandSyntax for ApiSendMessages {
189    fn interpret(&self) -> String {
190        let mut buf = String::with_capacity(1024);
191        buf.push_str("/_send ");
192        buf.push_str(&self.send_ref.interpret());
193        if self.live_message {
194            buf.push(' ');
195            buf.push_str("live=");
196            buf.push_str("on");
197        }
198        if let Some(ttl) = &self.ttl {
199            buf.push(' ');
200            buf.push_str("ttl=");
201            buf.push_str(&ttl.to_string());
202        }
203        buf.push(' ');
204        buf.push_str("json ");
205        buf.push_str(&serde_json::to_string(&self.composed_messages).unwrap());
206        buf
207    }
208}
209
210/// ### Message commands
211///
212/// Commands to send, update, delete, moderate messages and set message reactions
213///
214/// ----
215///
216/// Update message.
217///
218/// *Network usage*: background.
219///
220/// *Syntax:*
221///
222/// ```
223/// /_update item <str(chatRef)> <chatItemId>[ live=on] json <json(updatedMessage)>
224/// ```
225#[derive(Debug, Clone, PartialEq)]
226#[cfg_attr(feature = "bon", derive(::bon::Builder))]
227pub struct ApiUpdateChatItem {
228    pub chat_ref: ChatRef,
229    pub chat_item_id: i64,
230    pub live_message: bool,
231    pub updated_message: UpdatedMessage,
232}
233
234impl CommandSyntax for ApiUpdateChatItem {
235    fn interpret(&self) -> String {
236        let mut buf = String::with_capacity(1024);
237        buf.push_str("/_update ");
238        buf.push_str("item ");
239        buf.push_str(&self.chat_ref.interpret());
240        buf.push(' ');
241        buf.push_str(&self.chat_item_id.to_string());
242        if self.live_message {
243            buf.push(' ');
244            buf.push_str("live=");
245            buf.push_str("on");
246        }
247        buf.push(' ');
248        buf.push_str("json ");
249        buf.push_str(&serde_json::to_string(&self.updated_message).unwrap());
250        buf
251    }
252}
253
254/// ### Message commands
255///
256/// Commands to send, update, delete, moderate messages and set message reactions
257///
258/// ----
259///
260/// Delete message.
261///
262/// *Network usage*: background.
263///
264/// *Syntax:*
265///
266/// ```
267/// /_delete item <str(chatRef)> <chatItemIds[0]>[,<chatItemIds[1]>...] broadcast|internal|internalMark
268/// ```
269#[derive(Debug, Clone, PartialEq)]
270#[cfg_attr(feature = "bon", derive(::bon::Builder))]
271pub struct ApiDeleteChatItem {
272    pub chat_ref: ChatRef,
273    pub chat_item_ids: Vec<i64>,
274    pub delete_mode: CIDeleteMode,
275}
276
277impl CommandSyntax for ApiDeleteChatItem {
278    fn interpret(&self) -> String {
279        let mut buf = String::with_capacity(256);
280        buf.push_str("/_delete ");
281        buf.push_str("item ");
282        buf.push_str(&self.chat_ref.interpret());
283        buf.push(' ');
284        let mut iter = self.chat_item_ids.iter();
285        if let Some(el) = iter.next() {
286            buf.push_str(&el.to_string());
287        }
288        for el in iter {
289            buf.push(',');
290            buf.push_str(&el.to_string());
291        }
292        buf.push(' ');
293        match self.delete_mode {
294            CIDeleteMode::Broadcast => {
295                buf.push_str("broadcast");
296            }
297            CIDeleteMode::Internal => {
298                buf.push_str("internal");
299            }
300            CIDeleteMode::InternalMark => {
301                buf.push_str("internalMark");
302            }
303        }
304        buf
305    }
306}
307
308/// ### Message commands
309///
310/// Commands to send, update, delete, moderate messages and set message reactions
311///
312/// ----
313///
314/// Moderate message. Requires Moderator role (and higher than message author's).
315///
316/// *Network usage*: background.
317///
318/// *Syntax:*
319///
320/// ```
321/// /_delete member item #<groupId> <chatItemIds[0]>[,<chatItemIds[1]>...]
322/// ```
323#[derive(Debug, Clone, PartialEq)]
324#[cfg_attr(feature = "bon", derive(::bon::Builder))]
325pub struct ApiDeleteMemberChatItem {
326    pub group_id: i64,
327    pub chat_item_ids: Vec<i64>,
328}
329
330impl CommandSyntax for ApiDeleteMemberChatItem {
331    fn interpret(&self) -> String {
332        let mut buf = String::with_capacity(256);
333        buf.push_str("/_delete ");
334        buf.push_str("member ");
335        buf.push_str("item ");
336        buf.push('#');
337        buf.push_str(&self.group_id.to_string());
338        buf.push(' ');
339        let mut iter = self.chat_item_ids.iter();
340        if let Some(el) = iter.next() {
341            buf.push_str(&el.to_string());
342        }
343        for el in iter {
344            buf.push(',');
345            buf.push_str(&el.to_string());
346        }
347        buf
348    }
349}
350
351/// ### Message commands
352///
353/// Commands to send, update, delete, moderate messages and set message reactions
354///
355/// ----
356///
357/// Add/remove message reaction.
358///
359/// *Network usage*: background.
360///
361/// *Syntax:*
362///
363/// ```
364/// /_reaction <str(chatRef)> <chatItemId> on|off <json(reaction)>
365/// ```
366#[derive(Debug, Clone, PartialEq)]
367#[cfg_attr(feature = "bon", derive(::bon::Builder))]
368pub struct ApiChatItemReaction {
369    pub chat_ref: ChatRef,
370    pub chat_item_id: i64,
371    pub add: bool,
372    pub reaction: MsgReaction,
373}
374
375impl CommandSyntax for ApiChatItemReaction {
376    fn interpret(&self) -> String {
377        let mut buf = String::with_capacity(1024);
378        buf.push_str("/_reaction ");
379        buf.push_str(&self.chat_ref.interpret());
380        buf.push(' ');
381        buf.push_str(&self.chat_item_id.to_string());
382        buf.push(' ');
383        if self.add {
384            buf.push_str("on");
385        } else {
386            buf.push_str("off");
387        }
388        buf.push(' ');
389        buf.push_str(&serde_json::to_string(&self.reaction).unwrap());
390        buf
391    }
392}
393
394/// ### File commands
395///
396/// Commands to receive and to cancel files. Files are sent as part of the message, there are no separate commands to send files.
397///
398/// ----
399///
400/// Receive file.
401///
402/// *Network usage*: no.
403///
404/// *Syntax:*
405///
406/// ```
407/// /freceive <fileId>[ approved_relays=on][ encrypt=on|off][ inline=on|off][ <filePath>]
408/// ```
409#[derive(Debug, Clone, PartialEq)]
410#[cfg_attr(feature = "bon", derive(::bon::Builder))]
411pub struct ReceiveFile {
412    pub file_id: i64,
413    pub user_approved_relays: bool,
414    pub store_encrypted: Option<bool>,
415    pub file_inline: Option<bool>,
416    pub file_path: Option<String>,
417}
418
419impl CommandSyntax for ReceiveFile {
420    fn interpret(&self) -> String {
421        let mut buf = String::with_capacity(256);
422        buf.push_str("/freceive ");
423        buf.push_str(&self.file_id.to_string());
424        if self.user_approved_relays {
425            buf.push(' ');
426            buf.push_str("approved_relays=");
427            buf.push_str("on");
428        }
429        if let Some(store_encrypted) = &self.store_encrypted {
430            buf.push(' ');
431            buf.push_str("encrypt=");
432            if *store_encrypted {
433                buf.push_str("on");
434            } else {
435                buf.push_str("off");
436            }
437        }
438        if let Some(file_inline) = &self.file_inline {
439            buf.push(' ');
440            buf.push_str("inline=");
441            if *file_inline {
442                buf.push_str("on");
443            } else {
444                buf.push_str("off");
445            }
446        }
447        if let Some(file_path) = &self.file_path {
448            buf.push(' ');
449            buf.push_str(&file_path.to_string());
450        }
451        buf
452    }
453}
454
455/// ### File commands
456///
457/// Commands to receive and to cancel files. Files are sent as part of the message, there are no separate commands to send files.
458///
459/// ----
460///
461/// Cancel file.
462///
463/// *Network usage*: background.
464///
465/// *Syntax:*
466///
467/// ```
468/// /fcancel <fileId>
469/// ```
470#[derive(Debug, Clone, PartialEq)]
471#[cfg_attr(feature = "bon", derive(::bon::Builder))]
472pub struct CancelFile {
473    pub file_id: i64,
474}
475
476impl CommandSyntax for CancelFile {
477    fn interpret(&self) -> String {
478        let mut buf = String::with_capacity(64);
479        buf.push_str("/fcancel ");
480        buf.push_str(&self.file_id.to_string());
481        buf
482    }
483}
484
485/// ### Group commands
486///
487/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
488///
489/// ----
490///
491/// Add contact to group. Requires bot to have Admin role.
492///
493/// *Network usage*: interactive.
494///
495/// *Syntax:*
496///
497/// ```
498/// /_add #<groupId> <contactId> observer|author|member|moderator|admin|owner
499/// ```
500#[derive(Debug, Clone, PartialEq)]
501#[cfg_attr(feature = "bon", derive(::bon::Builder))]
502pub struct ApiAddMember {
503    pub group_id: i64,
504    pub contact_id: i64,
505    pub member_role: GroupMemberRole,
506}
507
508impl CommandSyntax for ApiAddMember {
509    fn interpret(&self) -> String {
510        let mut buf = String::with_capacity(256);
511        buf.push_str("/_add ");
512        buf.push('#');
513        buf.push_str(&self.group_id.to_string());
514        buf.push(' ');
515        buf.push_str(&self.contact_id.to_string());
516        buf.push(' ');
517        match self.member_role {
518            GroupMemberRole::Observer => {
519                buf.push_str("observer");
520            }
521            GroupMemberRole::Author => {
522                buf.push_str("author");
523            }
524            GroupMemberRole::Member => {
525                buf.push_str("member");
526            }
527            GroupMemberRole::Moderator => {
528                buf.push_str("moderator");
529            }
530            GroupMemberRole::Admin => {
531                buf.push_str("admin");
532            }
533            GroupMemberRole::Owner => {
534                buf.push_str("owner");
535            }
536        }
537        buf
538    }
539}
540
541/// ### Group commands
542///
543/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
544///
545/// ----
546///
547/// Join group.
548///
549/// *Network usage*: interactive.
550///
551/// *Syntax:*
552///
553/// ```
554/// /_join #<groupId>
555/// ```
556#[derive(Debug, Clone, PartialEq)]
557#[cfg_attr(feature = "bon", derive(::bon::Builder))]
558pub struct ApiJoinGroup {
559    pub group_id: i64,
560}
561
562impl CommandSyntax for ApiJoinGroup {
563    fn interpret(&self) -> String {
564        let mut buf = String::with_capacity(64);
565        buf.push_str("/_join ");
566        buf.push('#');
567        buf.push_str(&self.group_id.to_string());
568        buf
569    }
570}
571
572/// ### Group commands
573///
574/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
575///
576/// ----
577///
578/// Accept group member. Requires Admin role.
579///
580/// *Network usage*: background.
581///
582/// *Syntax:*
583///
584/// ```
585/// /_accept member #<groupId> <groupMemberId> observer|author|member|moderator|admin|owner
586/// ```
587#[derive(Debug, Clone, PartialEq)]
588#[cfg_attr(feature = "bon", derive(::bon::Builder))]
589pub struct ApiAcceptMember {
590    pub group_id: i64,
591    pub group_member_id: i64,
592    pub member_role: GroupMemberRole,
593}
594
595impl CommandSyntax for ApiAcceptMember {
596    fn interpret(&self) -> String {
597        let mut buf = String::with_capacity(256);
598        buf.push_str("/_accept ");
599        buf.push_str("member ");
600        buf.push('#');
601        buf.push_str(&self.group_id.to_string());
602        buf.push(' ');
603        buf.push_str(&self.group_member_id.to_string());
604        buf.push(' ');
605        match self.member_role {
606            GroupMemberRole::Observer => {
607                buf.push_str("observer");
608            }
609            GroupMemberRole::Author => {
610                buf.push_str("author");
611            }
612            GroupMemberRole::Member => {
613                buf.push_str("member");
614            }
615            GroupMemberRole::Moderator => {
616                buf.push_str("moderator");
617            }
618            GroupMemberRole::Admin => {
619                buf.push_str("admin");
620            }
621            GroupMemberRole::Owner => {
622                buf.push_str("owner");
623            }
624        }
625        buf
626    }
627}
628
629/// ### Group commands
630///
631/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
632///
633/// ----
634///
635/// Set members role. Requires Admin role.
636///
637/// *Network usage*: background.
638///
639/// *Syntax:*
640///
641/// ```
642/// /_member role #<groupId> <groupMemberIds[0]>[,<groupMemberIds[1]>...] observer|author|member|moderator|admin|owner
643/// ```
644#[derive(Debug, Clone, PartialEq)]
645#[cfg_attr(feature = "bon", derive(::bon::Builder))]
646pub struct ApiMembersRole {
647    pub group_id: i64,
648    pub group_member_ids: Vec<i64>,
649    pub member_role: GroupMemberRole,
650}
651
652impl CommandSyntax for ApiMembersRole {
653    fn interpret(&self) -> String {
654        let mut buf = String::with_capacity(256);
655        buf.push_str("/_member ");
656        buf.push_str("role ");
657        buf.push('#');
658        buf.push_str(&self.group_id.to_string());
659        buf.push(' ');
660        let mut iter = self.group_member_ids.iter();
661        if let Some(el) = iter.next() {
662            buf.push_str(&el.to_string());
663        }
664        for el in iter {
665            buf.push(',');
666            buf.push_str(&el.to_string());
667        }
668        buf.push(' ');
669        match self.member_role {
670            GroupMemberRole::Observer => {
671                buf.push_str("observer");
672            }
673            GroupMemberRole::Author => {
674                buf.push_str("author");
675            }
676            GroupMemberRole::Member => {
677                buf.push_str("member");
678            }
679            GroupMemberRole::Moderator => {
680                buf.push_str("moderator");
681            }
682            GroupMemberRole::Admin => {
683                buf.push_str("admin");
684            }
685            GroupMemberRole::Owner => {
686                buf.push_str("owner");
687            }
688        }
689        buf
690    }
691}
692
693/// ### Group commands
694///
695/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
696///
697/// ----
698///
699/// Block members. Requires Moderator role.
700///
701/// *Network usage*: background.
702///
703/// *Syntax:*
704///
705/// ```
706/// /_block #<groupId> <groupMemberIds[0]>[,<groupMemberIds[1]>...] blocked=on|off
707/// ```
708#[derive(Debug, Clone, PartialEq)]
709#[cfg_attr(feature = "bon", derive(::bon::Builder))]
710pub struct ApiBlockMembersForAll {
711    pub group_id: i64,
712    pub group_member_ids: Vec<i64>,
713    pub blocked: bool,
714}
715
716impl CommandSyntax for ApiBlockMembersForAll {
717    fn interpret(&self) -> String {
718        let mut buf = String::with_capacity(256);
719        buf.push_str("/_block ");
720        buf.push('#');
721        buf.push_str(&self.group_id.to_string());
722        buf.push(' ');
723        let mut iter = self.group_member_ids.iter();
724        if let Some(el) = iter.next() {
725            buf.push_str(&el.to_string());
726        }
727        for el in iter {
728            buf.push(',');
729            buf.push_str(&el.to_string());
730        }
731        buf.push(' ');
732        buf.push_str("blocked=");
733        if self.blocked {
734            buf.push_str("on");
735        } else {
736            buf.push_str("off");
737        }
738        buf
739    }
740}
741
742/// ### Group commands
743///
744/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
745///
746/// ----
747///
748/// Remove members. Requires Admin role.
749///
750/// *Network usage*: background.
751///
752/// *Syntax:*
753///
754/// ```
755/// /_remove #<groupId> <groupMemberIds[0]>[,<groupMemberIds[1]>...][ messages=on]
756/// ```
757#[derive(Debug, Clone, PartialEq)]
758#[cfg_attr(feature = "bon", derive(::bon::Builder))]
759pub struct ApiRemoveMembers {
760    pub group_id: i64,
761    pub group_member_ids: Vec<i64>,
762    pub with_messages: bool,
763}
764
765impl CommandSyntax for ApiRemoveMembers {
766    fn interpret(&self) -> String {
767        let mut buf = String::with_capacity(256);
768        buf.push_str("/_remove ");
769        buf.push('#');
770        buf.push_str(&self.group_id.to_string());
771        buf.push(' ');
772        let mut iter = self.group_member_ids.iter();
773        if let Some(el) = iter.next() {
774            buf.push_str(&el.to_string());
775        }
776        for el in iter {
777            buf.push(',');
778            buf.push_str(&el.to_string());
779        }
780        if self.with_messages {
781            buf.push(' ');
782            buf.push_str("messages=");
783            buf.push_str("on");
784        }
785        buf
786    }
787}
788
789/// ### Group commands
790///
791/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
792///
793/// ----
794///
795/// Leave group.
796///
797/// *Network usage*: background.
798///
799/// *Syntax:*
800///
801/// ```
802/// /_leave #<groupId>
803/// ```
804#[derive(Debug, Clone, PartialEq)]
805#[cfg_attr(feature = "bon", derive(::bon::Builder))]
806pub struct ApiLeaveGroup {
807    pub group_id: i64,
808}
809
810impl CommandSyntax for ApiLeaveGroup {
811    fn interpret(&self) -> String {
812        let mut buf = String::with_capacity(64);
813        buf.push_str("/_leave ");
814        buf.push('#');
815        buf.push_str(&self.group_id.to_string());
816        buf
817    }
818}
819
820/// ### Group commands
821///
822/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
823///
824/// ----
825///
826/// Get group members.
827///
828/// *Network usage*: no.
829///
830/// *Syntax:*
831///
832/// ```
833/// /_members #<groupId>
834/// ```
835#[derive(Debug, Clone, PartialEq)]
836#[cfg_attr(feature = "bon", derive(::bon::Builder))]
837pub struct ApiListMembers {
838    pub group_id: i64,
839}
840
841impl CommandSyntax for ApiListMembers {
842    fn interpret(&self) -> String {
843        let mut buf = String::with_capacity(64);
844        buf.push_str("/_members ");
845        buf.push('#');
846        buf.push_str(&self.group_id.to_string());
847        buf
848    }
849}
850
851/// ### Group commands
852///
853/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
854///
855/// ----
856///
857/// Create group.
858///
859/// *Network usage*: no.
860///
861/// *Syntax:*
862///
863/// ```
864/// /_group <userId>[ incognito=on] <json(groupProfile)>
865/// ```
866#[derive(Debug, Clone, PartialEq)]
867#[cfg_attr(feature = "bon", derive(::bon::Builder))]
868pub struct ApiNewGroup {
869    pub user_id: i64,
870    pub incognito: bool,
871    pub group_profile: GroupProfile,
872}
873
874impl CommandSyntax for ApiNewGroup {
875    fn interpret(&self) -> String {
876        let mut buf = String::with_capacity(1024);
877        buf.push_str("/_group ");
878        buf.push_str(&self.user_id.to_string());
879        if self.incognito {
880            buf.push(' ');
881            buf.push_str("incognito=");
882            buf.push_str("on");
883        }
884        buf.push(' ');
885        buf.push_str(&serde_json::to_string(&self.group_profile).unwrap());
886        buf
887    }
888}
889
890/// ### Group commands
891///
892/// Commands to manage and moderate groups. These commands can be used with business chats as well - they are groups. E.g., a common scenario would be to add human agents to business chat with the customer who connected via business address.
893///
894/// ----
895///
896/// Update group profile.
897///
898/// *Network usage*: background.
899///
900/// *Syntax:*
901///
902/// ```
903/// /_group_profile #<groupId> <json(groupProfile)>
904/// ```
905#[derive(Debug, Clone, PartialEq)]
906#[cfg_attr(feature = "bon", derive(::bon::Builder))]
907pub struct ApiUpdateGroupProfile {
908    pub group_id: i64,
909    pub group_profile: GroupProfile,
910}
911
912impl CommandSyntax for ApiUpdateGroupProfile {
913    fn interpret(&self) -> String {
914        let mut buf = String::with_capacity(1024);
915        buf.push_str("/_group_profile ");
916        buf.push('#');
917        buf.push_str(&self.group_id.to_string());
918        buf.push(' ');
919        buf.push_str(&serde_json::to_string(&self.group_profile).unwrap());
920        buf
921    }
922}
923
924/// ### Group link commands
925///
926/// These commands can be used by bots that manage multiple public groups
927///
928/// ----
929///
930/// Create group link.
931///
932/// *Network usage*: interactive.
933///
934/// *Syntax:*
935///
936/// ```
937/// /_create link #<groupId> observer|author|member|moderator|admin|owner
938/// ```
939#[derive(Debug, Clone, PartialEq)]
940#[cfg_attr(feature = "bon", derive(::bon::Builder))]
941pub struct ApiCreateGroupLink {
942    pub group_id: i64,
943    pub member_role: GroupMemberRole,
944}
945
946impl CommandSyntax for ApiCreateGroupLink {
947    fn interpret(&self) -> String {
948        let mut buf = String::with_capacity(64);
949        buf.push_str("/_create ");
950        buf.push_str("link ");
951        buf.push('#');
952        buf.push_str(&self.group_id.to_string());
953        buf.push(' ');
954        match self.member_role {
955            GroupMemberRole::Observer => {
956                buf.push_str("observer");
957            }
958            GroupMemberRole::Author => {
959                buf.push_str("author");
960            }
961            GroupMemberRole::Member => {
962                buf.push_str("member");
963            }
964            GroupMemberRole::Moderator => {
965                buf.push_str("moderator");
966            }
967            GroupMemberRole::Admin => {
968                buf.push_str("admin");
969            }
970            GroupMemberRole::Owner => {
971                buf.push_str("owner");
972            }
973        }
974        buf
975    }
976}
977
978/// ### Group link commands
979///
980/// These commands can be used by bots that manage multiple public groups
981///
982/// ----
983///
984/// Set member role for group link.
985///
986/// *Network usage*: no.
987///
988/// *Syntax:*
989///
990/// ```
991/// /_set link role #<groupId> observer|author|member|moderator|admin|owner
992/// ```
993#[derive(Debug, Clone, PartialEq)]
994#[cfg_attr(feature = "bon", derive(::bon::Builder))]
995pub struct ApiGroupLinkMemberRole {
996    pub group_id: i64,
997    pub member_role: GroupMemberRole,
998}
999
1000impl CommandSyntax for ApiGroupLinkMemberRole {
1001    fn interpret(&self) -> String {
1002        let mut buf = String::with_capacity(64);
1003        buf.push_str("/_set ");
1004        buf.push_str("link ");
1005        buf.push_str("role ");
1006        buf.push('#');
1007        buf.push_str(&self.group_id.to_string());
1008        buf.push(' ');
1009        match self.member_role {
1010            GroupMemberRole::Observer => {
1011                buf.push_str("observer");
1012            }
1013            GroupMemberRole::Author => {
1014                buf.push_str("author");
1015            }
1016            GroupMemberRole::Member => {
1017                buf.push_str("member");
1018            }
1019            GroupMemberRole::Moderator => {
1020                buf.push_str("moderator");
1021            }
1022            GroupMemberRole::Admin => {
1023                buf.push_str("admin");
1024            }
1025            GroupMemberRole::Owner => {
1026                buf.push_str("owner");
1027            }
1028        }
1029        buf
1030    }
1031}
1032
1033/// ### Group link commands
1034///
1035/// These commands can be used by bots that manage multiple public groups
1036///
1037/// ----
1038///
1039/// Delete group link.
1040///
1041/// *Network usage*: background.
1042///
1043/// *Syntax:*
1044///
1045/// ```
1046/// /_delete link #<groupId>
1047/// ```
1048#[derive(Debug, Clone, PartialEq)]
1049#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1050pub struct ApiDeleteGroupLink {
1051    pub group_id: i64,
1052}
1053
1054impl CommandSyntax for ApiDeleteGroupLink {
1055    fn interpret(&self) -> String {
1056        let mut buf = String::with_capacity(64);
1057        buf.push_str("/_delete ");
1058        buf.push_str("link ");
1059        buf.push('#');
1060        buf.push_str(&self.group_id.to_string());
1061        buf
1062    }
1063}
1064
1065/// ### Group link commands
1066///
1067/// These commands can be used by bots that manage multiple public groups
1068///
1069/// ----
1070///
1071/// Get group link.
1072///
1073/// *Network usage*: no.
1074///
1075/// *Syntax:*
1076///
1077/// ```
1078/// /_get link #<groupId>
1079/// ```
1080#[derive(Debug, Clone, PartialEq)]
1081#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1082pub struct ApiGetGroupLink {
1083    pub group_id: i64,
1084}
1085
1086impl CommandSyntax for ApiGetGroupLink {
1087    fn interpret(&self) -> String {
1088        let mut buf = String::with_capacity(64);
1089        buf.push_str("/_get ");
1090        buf.push_str("link ");
1091        buf.push('#');
1092        buf.push_str(&self.group_id.to_string());
1093        buf
1094    }
1095}
1096
1097/// ### Connection commands
1098///
1099/// These commands may be used to create connections. Most bots do not need to use them - bot users will connect via bot address with auto-accept enabled.
1100///
1101/// ----
1102///
1103/// Create 1-time invitation link.
1104///
1105/// *Network usage*: interactive.
1106///
1107/// *Syntax:*
1108///
1109/// ```
1110/// /_connect <userId>[ incognito=on]
1111/// ```
1112#[derive(Debug, Clone, PartialEq)]
1113#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1114pub struct ApiAddContact {
1115    pub user_id: i64,
1116    pub incognito: bool,
1117}
1118
1119impl CommandSyntax for ApiAddContact {
1120    fn interpret(&self) -> String {
1121        let mut buf = String::with_capacity(64);
1122        buf.push_str("/_connect ");
1123        buf.push_str(&self.user_id.to_string());
1124        if self.incognito {
1125            buf.push(' ');
1126            buf.push_str("incognito=");
1127            buf.push_str("on");
1128        }
1129        buf
1130    }
1131}
1132
1133/// ### Connection commands
1134///
1135/// These commands may be used to create connections. Most bots do not need to use them - bot users will connect via bot address with auto-accept enabled.
1136///
1137/// ----
1138///
1139/// Determine SimpleX link type and if the bot is already connected via this link.
1140///
1141/// *Network usage*: interactive.
1142///
1143/// *Syntax:*
1144///
1145/// ```
1146/// /_connect plan <userId> <connectionLink>
1147/// ```
1148#[derive(Debug, Clone, PartialEq)]
1149#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1150pub struct ApiConnectPlan {
1151    pub user_id: i64,
1152    pub connection_link: Option<String>,
1153}
1154
1155impl CommandSyntax for ApiConnectPlan {
1156    fn interpret(&self) -> String {
1157        let mut buf = String::with_capacity(64);
1158        buf.push_str("/_connect ");
1159        buf.push_str("plan ");
1160        buf.push_str(&self.user_id.to_string());
1161        buf.push(' ');
1162        buf.push_str(
1163            &self
1164                .connection_link
1165                .as_deref()
1166                .unwrap_or_default()
1167                .to_string(),
1168        );
1169        buf
1170    }
1171}
1172
1173/// ### Connection commands
1174///
1175/// These commands may be used to create connections. Most bots do not need to use them - bot users will connect via bot address with auto-accept enabled.
1176///
1177/// ----
1178///
1179/// Connect via prepared SimpleX link. The link can be 1-time invitation link, contact address or group link
1180///
1181/// *Network usage*: interactive.
1182///
1183/// *Syntax:*
1184///
1185/// ```
1186/// /_connect <userId>[ <str(preparedLink_)>]
1187/// ```
1188#[derive(Debug, Clone, PartialEq)]
1189#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1190pub struct ApiConnect {
1191    pub user_id: i64,
1192    pub incognito: bool,
1193    pub prepared_link: Option<CreatedConnLink>,
1194}
1195
1196impl CommandSyntax for ApiConnect {
1197    fn interpret(&self) -> String {
1198        let mut buf = String::with_capacity(256);
1199        buf.push_str("/_connect ");
1200        buf.push_str(&self.user_id.to_string());
1201        if let Some(prepared_link) = &self.prepared_link {
1202            buf.push(' ');
1203            buf.push_str(&prepared_link.interpret());
1204        }
1205        buf
1206    }
1207}
1208
1209/// ### Connection commands
1210///
1211/// These commands may be used to create connections. Most bots do not need to use them - bot users will connect via bot address with auto-accept enabled.
1212///
1213/// ----
1214///
1215/// Connect via SimpleX link as string in the active user profile.
1216///
1217/// *Network usage*: interactive.
1218///
1219/// *Syntax:*
1220///
1221/// ```
1222/// /connect[ <connLink_>]
1223/// ```
1224#[derive(Debug, Clone, PartialEq)]
1225#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1226pub struct Connect {
1227    pub incognito: bool,
1228    pub conn_link: Option<String>,
1229}
1230
1231impl CommandSyntax for Connect {
1232    fn interpret(&self) -> String {
1233        let mut buf = String::with_capacity(64);
1234        buf.push_str("/connect");
1235        if let Some(conn_link) = &self.conn_link {
1236            buf.push(' ');
1237            buf.push_str(&conn_link.to_string());
1238        }
1239        buf
1240    }
1241}
1242
1243/// ### Connection commands
1244///
1245/// These commands may be used to create connections. Most bots do not need to use them - bot users will connect via bot address with auto-accept enabled.
1246///
1247/// ----
1248///
1249/// Accept contact request.
1250///
1251/// *Network usage*: interactive.
1252///
1253/// *Syntax:*
1254///
1255/// ```
1256/// /_accept <contactReqId>
1257/// ```
1258#[derive(Debug, Clone, PartialEq)]
1259#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1260pub struct ApiAcceptContact {
1261    pub contact_req_id: i64,
1262}
1263
1264impl CommandSyntax for ApiAcceptContact {
1265    fn interpret(&self) -> String {
1266        let mut buf = String::with_capacity(64);
1267        buf.push_str("/_accept ");
1268        buf.push_str(&self.contact_req_id.to_string());
1269        buf
1270    }
1271}
1272
1273/// ### Connection commands
1274///
1275/// These commands may be used to create connections. Most bots do not need to use them - bot users will connect via bot address with auto-accept enabled.
1276///
1277/// ----
1278///
1279/// Reject contact request. The user who sent the request is **not notified**.
1280///
1281/// *Network usage*: no.
1282///
1283/// *Syntax:*
1284///
1285/// ```
1286/// /_reject <contactReqId>
1287/// ```
1288#[derive(Debug, Clone, PartialEq)]
1289#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1290pub struct ApiRejectContact {
1291    pub contact_req_id: i64,
1292}
1293
1294impl CommandSyntax for ApiRejectContact {
1295    fn interpret(&self) -> String {
1296        let mut buf = String::with_capacity(64);
1297        buf.push_str("/_reject ");
1298        buf.push_str(&self.contact_req_id.to_string());
1299        buf
1300    }
1301}
1302
1303/// ### Chat commands
1304///
1305/// Commands to list and delete conversations.
1306///
1307/// ----
1308///
1309/// Get contacts.
1310///
1311/// *Network usage*: no.
1312///
1313/// *Syntax:*
1314///
1315/// ```
1316/// /_contacts <userId>
1317/// ```
1318#[derive(Debug, Clone, PartialEq)]
1319#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1320pub struct ApiListContacts {
1321    pub user_id: i64,
1322}
1323
1324impl CommandSyntax for ApiListContacts {
1325    fn interpret(&self) -> String {
1326        let mut buf = String::with_capacity(64);
1327        buf.push_str("/_contacts ");
1328        buf.push_str(&self.user_id.to_string());
1329        buf
1330    }
1331}
1332
1333/// ### Chat commands
1334///
1335/// Commands to list and delete conversations.
1336///
1337/// ----
1338///
1339/// Get groups.
1340///
1341/// *Network usage*: no.
1342///
1343/// *Syntax:*
1344///
1345/// ```
1346/// /_groups <userId>[ @<contactId_>][ <search>]
1347/// ```
1348#[derive(Debug, Clone, PartialEq)]
1349#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1350pub struct ApiListGroups {
1351    pub user_id: i64,
1352    pub contact_id: Option<i64>,
1353    pub search: Option<String>,
1354}
1355
1356impl CommandSyntax for ApiListGroups {
1357    fn interpret(&self) -> String {
1358        let mut buf = String::with_capacity(256);
1359        buf.push_str("/_groups ");
1360        buf.push_str(&self.user_id.to_string());
1361        if let Some(contact_id) = &self.contact_id {
1362            buf.push(' ');
1363            buf.push('@');
1364            buf.push_str(&contact_id.to_string());
1365        }
1366        if let Some(search) = &self.search {
1367            buf.push(' ');
1368            buf.push_str(&search.to_string());
1369        }
1370        buf
1371    }
1372}
1373
1374/// ### Chat commands
1375///
1376/// Commands to list and delete conversations.
1377///
1378/// ----
1379///
1380/// Delete chat.
1381///
1382/// *Network usage*: background.
1383///
1384/// *Syntax:*
1385///
1386/// ```
1387/// /_delete <str(chatRef)> <str(chatDeleteMode)>
1388/// ```
1389#[derive(Debug, Clone, PartialEq)]
1390#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1391pub struct ApiDeleteChat {
1392    pub chat_ref: ChatRef,
1393    pub chat_delete_mode: ChatDeleteMode,
1394}
1395
1396impl CommandSyntax for ApiDeleteChat {
1397    fn interpret(&self) -> String {
1398        let mut buf = String::with_capacity(64);
1399        buf.push_str("/_delete ");
1400        buf.push_str(&self.chat_ref.interpret());
1401        buf.push(' ');
1402        buf.push_str(&self.chat_delete_mode.interpret());
1403        buf
1404    }
1405}
1406
1407/// ### User profile commands
1408///
1409/// Most bots don't need to use these commands, as bot profile can be configured manually via CLI or desktop client. These commands can be used by bots that need to manage multiple user profiles (e.g., the profiles of support agents).
1410///
1411/// ----
1412///
1413/// Get active user profile
1414///
1415/// *Network usage*: no.
1416///
1417/// *Syntax:*
1418///
1419/// ```
1420/// /user
1421/// ```
1422#[derive(Debug, Clone, PartialEq)]
1423#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1424pub struct ShowActiveUser {}
1425
1426impl CommandSyntax for ShowActiveUser {
1427    fn interpret(&self) -> String {
1428        let mut buf = String::new();
1429        buf.push_str("/user");
1430        buf
1431    }
1432}
1433
1434/// ### User profile commands
1435///
1436/// Most bots don't need to use these commands, as bot profile can be configured manually via CLI or desktop client. These commands can be used by bots that need to manage multiple user profiles (e.g., the profiles of support agents).
1437///
1438/// ----
1439///
1440/// Create new user profile
1441///
1442/// *Network usage*: no.
1443///
1444/// *Syntax:*
1445///
1446/// ```
1447/// /_create user <json(newUser)>
1448/// ```
1449#[derive(Debug, Clone, PartialEq)]
1450#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1451pub struct CreateActiveUser {
1452    pub new_user: NewUser,
1453}
1454
1455impl CommandSyntax for CreateActiveUser {
1456    fn interpret(&self) -> String {
1457        let mut buf = String::with_capacity(1024);
1458        buf.push_str("/_create ");
1459        buf.push_str("user ");
1460        buf.push_str(&serde_json::to_string(&self.new_user).unwrap());
1461        buf
1462    }
1463}
1464
1465/// ### User profile commands
1466///
1467/// Most bots don't need to use these commands, as bot profile can be configured manually via CLI or desktop client. These commands can be used by bots that need to manage multiple user profiles (e.g., the profiles of support agents).
1468///
1469/// ----
1470///
1471/// Get all user profiles
1472///
1473/// *Network usage*: no.
1474///
1475/// *Syntax:*
1476///
1477/// ```
1478/// /users
1479/// ```
1480#[derive(Debug, Clone, PartialEq)]
1481#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1482pub struct ListUsers {}
1483
1484impl CommandSyntax for ListUsers {
1485    fn interpret(&self) -> String {
1486        let mut buf = String::new();
1487        buf.push_str("/users");
1488        buf
1489    }
1490}
1491
1492/// ### User profile commands
1493///
1494/// Most bots don't need to use these commands, as bot profile can be configured manually via CLI or desktop client. These commands can be used by bots that need to manage multiple user profiles (e.g., the profiles of support agents).
1495///
1496/// ----
1497///
1498/// Set active user profile
1499///
1500/// *Network usage*: no.
1501///
1502/// *Syntax:*
1503///
1504/// ```
1505/// /_user <userId>[ <json(viewPwd)>]
1506/// ```
1507#[derive(Debug, Clone, PartialEq)]
1508#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1509pub struct ApiSetActiveUser {
1510    pub user_id: i64,
1511    pub view_pwd: Option<String>,
1512}
1513
1514impl CommandSyntax for ApiSetActiveUser {
1515    fn interpret(&self) -> String {
1516        let mut buf = String::with_capacity(1024);
1517        buf.push_str("/_user ");
1518        buf.push_str(&self.user_id.to_string());
1519        if let Some(view_pwd) = &self.view_pwd {
1520            buf.push(' ');
1521            buf.push_str(&serde_json::to_string(&view_pwd).unwrap());
1522        }
1523        buf
1524    }
1525}
1526
1527/// ### User profile commands
1528///
1529/// Most bots don't need to use these commands, as bot profile can be configured manually via CLI or desktop client. These commands can be used by bots that need to manage multiple user profiles (e.g., the profiles of support agents).
1530///
1531/// ----
1532///
1533/// Delete user profile.
1534///
1535/// *Network usage*: background.
1536///
1537/// *Syntax:*
1538///
1539/// ```
1540/// /_delete user <userId> del_smp=on|off[ <json(viewPwd)>]
1541/// ```
1542#[derive(Debug, Clone, PartialEq)]
1543#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1544pub struct ApiDeleteUser {
1545    pub user_id: i64,
1546    pub del_smp_queues: bool,
1547    pub view_pwd: Option<String>,
1548}
1549
1550impl CommandSyntax for ApiDeleteUser {
1551    fn interpret(&self) -> String {
1552        let mut buf = String::with_capacity(1024);
1553        buf.push_str("/_delete ");
1554        buf.push_str("user ");
1555        buf.push_str(&self.user_id.to_string());
1556        buf.push(' ');
1557        buf.push_str("del_smp=");
1558        if self.del_smp_queues {
1559            buf.push_str("on");
1560        } else {
1561            buf.push_str("off");
1562        }
1563        if let Some(view_pwd) = &self.view_pwd {
1564            buf.push(' ');
1565            buf.push_str(&serde_json::to_string(&view_pwd).unwrap());
1566        }
1567        buf
1568    }
1569}
1570
1571/// ### User profile commands
1572///
1573/// Most bots don't need to use these commands, as bot profile can be configured manually via CLI or desktop client. These commands can be used by bots that need to manage multiple user profiles (e.g., the profiles of support agents).
1574///
1575/// ----
1576///
1577/// Update user profile.
1578///
1579/// *Network usage*: background.
1580///
1581/// *Syntax:*
1582///
1583/// ```
1584/// /_profile <userId> <json(profile)>
1585/// ```
1586#[derive(Debug, Clone, PartialEq)]
1587#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1588pub struct ApiUpdateProfile {
1589    pub user_id: i64,
1590    pub profile: Profile,
1591}
1592
1593impl CommandSyntax for ApiUpdateProfile {
1594    fn interpret(&self) -> String {
1595        let mut buf = String::with_capacity(1024);
1596        buf.push_str("/_profile ");
1597        buf.push_str(&self.user_id.to_string());
1598        buf.push(' ');
1599        buf.push_str(&serde_json::to_string(&self.profile).unwrap());
1600        buf
1601    }
1602}
1603
1604/// ### User profile commands
1605///
1606/// Most bots don't need to use these commands, as bot profile can be configured manually via CLI or desktop client. These commands can be used by bots that need to manage multiple user profiles (e.g., the profiles of support agents).
1607///
1608/// ----
1609///
1610/// Configure chat preference overrides for the contact.
1611///
1612/// *Network usage*: background.
1613///
1614/// *Syntax:*
1615///
1616/// ```
1617/// /_set prefs @<contactId> <json(preferences)>
1618/// ```
1619#[derive(Debug, Clone, PartialEq)]
1620#[cfg_attr(feature = "bon", derive(::bon::Builder))]
1621pub struct ApiSetContactPrefs {
1622    pub contact_id: i64,
1623    pub preferences: Preferences,
1624}
1625
1626impl CommandSyntax for ApiSetContactPrefs {
1627    fn interpret(&self) -> String {
1628        let mut buf = String::with_capacity(1024);
1629        buf.push_str("/_set ");
1630        buf.push_str("prefs ");
1631        buf.push('@');
1632        buf.push_str(&self.contact_id.to_string());
1633        buf.push(' ');
1634        buf.push_str(&serde_json::to_string(&self.preferences).unwrap());
1635        buf
1636    }
1637}