simploxide_api_types/client_api.rs
1use crate::{commands::*, responses::*, utils::CommandSyntax, *};
2use std::future::Future;
3use std::sync::Arc;
4
5pub trait ClientApi: Sync {
6 type Error;
7
8 fn send_raw(
9 &self,
10 command: String,
11 ) -> impl Future<Output = Result<JsonObject, Self::Error>> + Send;
12
13 /// ### Address commands
14 ///
15 /// Bots can use these commands to automatically check and create address when initialized
16 ///
17 /// ----
18 ///
19 /// Create bot address.
20 ///
21 /// *Network usage*: interactive.
22 ///
23 /// *Syntax:*
24 ///
25 /// ```
26 /// /_address <userId>
27 /// ```
28 fn api_create_my_address(
29 &self,
30 user_id: i64,
31 ) -> impl Future<Output = Result<Arc<ApiCreateMyAddressResponse>, Self::Error>> + Send {
32 async move {
33 let command = ApiCreateMyAddress { user_id };
34 let response = self.send_raw(command.interpret()).await?;
35 // Safe to unwrap because unrecognized JSON goes to undocumented variant
36 Ok(serde_json::from_value(response).unwrap())
37 }
38 }
39
40 /// ### Address commands
41 ///
42 /// Bots can use these commands to automatically check and create address when initialized
43 ///
44 /// ----
45 ///
46 /// Delete bot address.
47 ///
48 /// *Network usage*: background.
49 ///
50 /// *Syntax:*
51 ///
52 /// ```
53 /// /_delete_address <userId>
54 /// ```
55 fn api_delete_my_address(
56 &self,
57 user_id: i64,
58 ) -> impl Future<Output = Result<Arc<ApiDeleteMyAddressResponse>, Self::Error>> + Send {
59 async move {
60 let command = ApiDeleteMyAddress { user_id };
61 let response = self.send_raw(command.interpret()).await?;
62 // Safe to unwrap because unrecognized JSON goes to undocumented variant
63 Ok(serde_json::from_value(response).unwrap())
64 }
65 }
66
67 /// ### Address commands
68 ///
69 /// Bots can use these commands to automatically check and create address when initialized
70 ///
71 /// ----
72 ///
73 /// Get bot address and settings.
74 ///
75 /// *Network usage*: no.
76 ///
77 /// *Syntax:*
78 ///
79 /// ```
80 /// /_show_address <userId>
81 /// ```
82 fn api_show_my_address(
83 &self,
84 user_id: i64,
85 ) -> impl Future<Output = Result<Arc<ApiShowMyAddressResponse>, Self::Error>> + Send {
86 async move {
87 let command = ApiShowMyAddress { user_id };
88 let response = self.send_raw(command.interpret()).await?;
89 // Safe to unwrap because unrecognized JSON goes to undocumented variant
90 Ok(serde_json::from_value(response).unwrap())
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 fn api_set_profile_address(
110 &self,
111 command: ApiSetProfileAddress,
112 ) -> impl Future<Output = Result<Arc<ApiSetProfileAddressResponse>, Self::Error>> + Send {
113 async move {
114 let response = self.send_raw(command.interpret()).await?;
115 // Safe to unwrap because unrecognized JSON goes to undocumented variant
116 Ok(serde_json::from_value(response).unwrap())
117 }
118 }
119
120 /// ### Address commands
121 ///
122 /// Bots can use these commands to automatically check and create address when initialized
123 ///
124 /// ----
125 ///
126 /// Set bot address settings.
127 ///
128 /// *Network usage*: interactive.
129 ///
130 /// *Syntax:*
131 ///
132 /// ```
133 /// /_address_settings <userId> <json(settings)>
134 /// ```
135 fn api_set_address_settings(
136 &self,
137 user_id: i64,
138 settings: AddressSettings,
139 ) -> impl Future<Output = Result<Arc<ApiSetAddressSettingsResponse>, Self::Error>> + Send {
140 async move {
141 let command = ApiSetAddressSettings { user_id, settings };
142 let response = self.send_raw(command.interpret()).await?;
143 // Safe to unwrap because unrecognized JSON goes to undocumented variant
144 Ok(serde_json::from_value(response).unwrap())
145 }
146 }
147
148 /// ### Message commands
149 ///
150 /// Commands to send, update, delete, moderate messages and set message reactions
151 ///
152 /// ----
153 ///
154 /// Send messages.
155 ///
156 /// *Network usage*: background.
157 ///
158 /// *Syntax:*
159 ///
160 /// ```
161 /// /_send <str(sendRef)>[ live=on][ ttl=<ttl>] json <json(composedMessages)>
162 /// ```
163 fn api_send_messages(
164 &self,
165 command: ApiSendMessages,
166 ) -> impl Future<Output = Result<Arc<ApiSendMessagesResponse>, Self::Error>> + Send {
167 async move {
168 let response = self.send_raw(command.interpret()).await?;
169 // Safe to unwrap because unrecognized JSON goes to undocumented variant
170 Ok(serde_json::from_value(response).unwrap())
171 }
172 }
173
174 /// ### Message commands
175 ///
176 /// Commands to send, update, delete, moderate messages and set message reactions
177 ///
178 /// ----
179 ///
180 /// Update message.
181 ///
182 /// *Network usage*: background.
183 ///
184 /// *Syntax:*
185 ///
186 /// ```
187 /// /_update item <str(chatRef)> <chatItemId>[ live=on] json <json(updatedMessage)>
188 /// ```
189 fn api_update_chat_item(
190 &self,
191 command: ApiUpdateChatItem,
192 ) -> impl Future<Output = Result<Arc<ApiUpdateChatItemResponse>, Self::Error>> + Send {
193 async move {
194 let response = self.send_raw(command.interpret()).await?;
195 // Safe to unwrap because unrecognized JSON goes to undocumented variant
196 Ok(serde_json::from_value(response).unwrap())
197 }
198 }
199
200 /// ### Message commands
201 ///
202 /// Commands to send, update, delete, moderate messages and set message reactions
203 ///
204 /// ----
205 ///
206 /// Delete message.
207 ///
208 /// *Network usage*: background.
209 ///
210 /// *Syntax:*
211 ///
212 /// ```
213 /// /_delete item <str(chatRef)> <chatItemIds[0]>[,<chatItemIds[1]>...] broadcast|internal|internalMark
214 /// ```
215 fn api_delete_chat_item(
216 &self,
217 chat_ref: ChatRef,
218 chat_item_ids: Vec<i64>,
219 delete_mode: CIDeleteMode,
220 ) -> impl Future<Output = Result<Arc<ApiDeleteChatItemResponse>, Self::Error>> + Send {
221 async move {
222 let command = ApiDeleteChatItem {
223 chat_ref,
224 chat_item_ids,
225 delete_mode,
226 };
227 let response = self.send_raw(command.interpret()).await?;
228 // Safe to unwrap because unrecognized JSON goes to undocumented variant
229 Ok(serde_json::from_value(response).unwrap())
230 }
231 }
232
233 /// ### Message commands
234 ///
235 /// Commands to send, update, delete, moderate messages and set message reactions
236 ///
237 /// ----
238 ///
239 /// Moderate message. Requires Moderator role (and higher than message author's).
240 ///
241 /// *Network usage*: background.
242 ///
243 /// *Syntax:*
244 ///
245 /// ```
246 /// /_delete member item #<groupId> <chatItemIds[0]>[,<chatItemIds[1]>...]
247 /// ```
248 fn api_delete_member_chat_item(
249 &self,
250 group_id: i64,
251 chat_item_ids: Vec<i64>,
252 ) -> impl Future<Output = Result<Arc<ApiDeleteMemberChatItemResponse>, Self::Error>> + Send
253 {
254 async move {
255 let command = ApiDeleteMemberChatItem {
256 group_id,
257 chat_item_ids,
258 };
259 let response = self.send_raw(command.interpret()).await?;
260 // Safe to unwrap because unrecognized JSON goes to undocumented variant
261 Ok(serde_json::from_value(response).unwrap())
262 }
263 }
264
265 /// ### Message commands
266 ///
267 /// Commands to send, update, delete, moderate messages and set message reactions
268 ///
269 /// ----
270 ///
271 /// Add/remove message reaction.
272 ///
273 /// *Network usage*: background.
274 ///
275 /// *Syntax:*
276 ///
277 /// ```
278 /// /_reaction <str(chatRef)> <chatItemId> on|off <json(reaction)>
279 /// ```
280 fn api_chat_item_reaction(
281 &self,
282 command: ApiChatItemReaction,
283 ) -> impl Future<Output = Result<Arc<ApiChatItemReactionResponse>, Self::Error>> + Send {
284 async move {
285 let response = self.send_raw(command.interpret()).await?;
286 // Safe to unwrap because unrecognized JSON goes to undocumented variant
287 Ok(serde_json::from_value(response).unwrap())
288 }
289 }
290
291 /// ### File commands
292 ///
293 /// Commands to receive and to cancel files. Files are sent as part of the message, there are no separate commands to send files.
294 ///
295 /// ----
296 ///
297 /// Receive file.
298 ///
299 /// *Network usage*: no.
300 ///
301 /// *Syntax:*
302 ///
303 /// ```
304 /// /freceive <fileId>[ approved_relays=on][ encrypt=on|off][ inline=on|off][ <filePath>]
305 /// ```
306 fn receive_file(
307 &self,
308 command: ReceiveFile,
309 ) -> impl Future<Output = Result<Arc<ReceiveFileResponse>, Self::Error>> + Send {
310 async move {
311 let response = self.send_raw(command.interpret()).await?;
312 // Safe to unwrap because unrecognized JSON goes to undocumented variant
313 Ok(serde_json::from_value(response).unwrap())
314 }
315 }
316
317 /// ### File commands
318 ///
319 /// Commands to receive and to cancel files. Files are sent as part of the message, there are no separate commands to send files.
320 ///
321 /// ----
322 ///
323 /// Cancel file.
324 ///
325 /// *Network usage*: background.
326 ///
327 /// *Syntax:*
328 ///
329 /// ```
330 /// /fcancel <fileId>
331 /// ```
332 fn cancel_file(
333 &self,
334 file_id: i64,
335 ) -> impl Future<Output = Result<Arc<CancelFileResponse>, Self::Error>> + Send {
336 async move {
337 let command = CancelFile { file_id };
338 let response = self.send_raw(command.interpret()).await?;
339 // Safe to unwrap because unrecognized JSON goes to undocumented variant
340 Ok(serde_json::from_value(response).unwrap())
341 }
342 }
343
344 /// ### Group commands
345 ///
346 /// 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.
347 ///
348 /// ----
349 ///
350 /// Add contact to group. Requires bot to have Admin role.
351 ///
352 /// *Network usage*: interactive.
353 ///
354 /// *Syntax:*
355 ///
356 /// ```
357 /// /_add #<groupId> <contactId> observer|author|member|moderator|admin|owner
358 /// ```
359 fn api_add_member(
360 &self,
361 group_id: i64,
362 contact_id: i64,
363 member_role: GroupMemberRole,
364 ) -> impl Future<Output = Result<Arc<ApiAddMemberResponse>, Self::Error>> + Send {
365 async move {
366 let command = ApiAddMember {
367 group_id,
368 contact_id,
369 member_role,
370 };
371 let response = self.send_raw(command.interpret()).await?;
372 // Safe to unwrap because unrecognized JSON goes to undocumented variant
373 Ok(serde_json::from_value(response).unwrap())
374 }
375 }
376
377 /// ### Group commands
378 ///
379 /// 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.
380 ///
381 /// ----
382 ///
383 /// Join group.
384 ///
385 /// *Network usage*: interactive.
386 ///
387 /// *Syntax:*
388 ///
389 /// ```
390 /// /_join #<groupId>
391 /// ```
392 fn api_join_group(
393 &self,
394 group_id: i64,
395 ) -> impl Future<Output = Result<Arc<ApiJoinGroupResponse>, Self::Error>> + Send {
396 async move {
397 let command = ApiJoinGroup { group_id };
398 let response = self.send_raw(command.interpret()).await?;
399 // Safe to unwrap because unrecognized JSON goes to undocumented variant
400 Ok(serde_json::from_value(response).unwrap())
401 }
402 }
403
404 /// ### Group commands
405 ///
406 /// 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.
407 ///
408 /// ----
409 ///
410 /// Accept group member. Requires Admin role.
411 ///
412 /// *Network usage*: background.
413 ///
414 /// *Syntax:*
415 ///
416 /// ```
417 /// /_accept member #<groupId> <groupMemberId> observer|author|member|moderator|admin|owner
418 /// ```
419 fn api_accept_member(
420 &self,
421 group_id: i64,
422 group_member_id: i64,
423 member_role: GroupMemberRole,
424 ) -> impl Future<Output = Result<Arc<ApiAcceptMemberResponse>, Self::Error>> + Send {
425 async move {
426 let command = ApiAcceptMember {
427 group_id,
428 group_member_id,
429 member_role,
430 };
431 let response = self.send_raw(command.interpret()).await?;
432 // Safe to unwrap because unrecognized JSON goes to undocumented variant
433 Ok(serde_json::from_value(response).unwrap())
434 }
435 }
436
437 /// ### Group commands
438 ///
439 /// 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.
440 ///
441 /// ----
442 ///
443 /// Set members role. Requires Admin role.
444 ///
445 /// *Network usage*: background.
446 ///
447 /// *Syntax:*
448 ///
449 /// ```
450 /// /_member role #<groupId> <groupMemberIds[0]>[,<groupMemberIds[1]>...] observer|author|member|moderator|admin|owner
451 /// ```
452 fn api_members_role(
453 &self,
454 group_id: i64,
455 group_member_ids: Vec<i64>,
456 member_role: GroupMemberRole,
457 ) -> impl Future<Output = Result<Arc<ApiMembersRoleResponse>, Self::Error>> + Send {
458 async move {
459 let command = ApiMembersRole {
460 group_id,
461 group_member_ids,
462 member_role,
463 };
464 let response = self.send_raw(command.interpret()).await?;
465 // Safe to unwrap because unrecognized JSON goes to undocumented variant
466 Ok(serde_json::from_value(response).unwrap())
467 }
468 }
469
470 /// ### Group commands
471 ///
472 /// 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.
473 ///
474 /// ----
475 ///
476 /// Block members. Requires Moderator role.
477 ///
478 /// *Network usage*: background.
479 ///
480 /// *Syntax:*
481 ///
482 /// ```
483 /// /_block #<groupId> <groupMemberIds[0]>[,<groupMemberIds[1]>...] blocked=on|off
484 /// ```
485 fn api_block_members_for_all(
486 &self,
487 command: ApiBlockMembersForAll,
488 ) -> impl Future<Output = Result<Arc<ApiBlockMembersForAllResponse>, Self::Error>> + Send {
489 async move {
490 let response = self.send_raw(command.interpret()).await?;
491 // Safe to unwrap because unrecognized JSON goes to undocumented variant
492 Ok(serde_json::from_value(response).unwrap())
493 }
494 }
495
496 /// ### Group commands
497 ///
498 /// 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.
499 ///
500 /// ----
501 ///
502 /// Remove members. Requires Admin role.
503 ///
504 /// *Network usage*: background.
505 ///
506 /// *Syntax:*
507 ///
508 /// ```
509 /// /_remove #<groupId> <groupMemberIds[0]>[,<groupMemberIds[1]>...][ messages=on]
510 /// ```
511 fn api_remove_members(
512 &self,
513 command: ApiRemoveMembers,
514 ) -> impl Future<Output = Result<Arc<ApiRemoveMembersResponse>, Self::Error>> + Send {
515 async move {
516 let response = self.send_raw(command.interpret()).await?;
517 // Safe to unwrap because unrecognized JSON goes to undocumented variant
518 Ok(serde_json::from_value(response).unwrap())
519 }
520 }
521
522 /// ### Group commands
523 ///
524 /// 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.
525 ///
526 /// ----
527 ///
528 /// Leave group.
529 ///
530 /// *Network usage*: background.
531 ///
532 /// *Syntax:*
533 ///
534 /// ```
535 /// /_leave #<groupId>
536 /// ```
537 fn api_leave_group(
538 &self,
539 group_id: i64,
540 ) -> impl Future<Output = Result<Arc<ApiLeaveGroupResponse>, Self::Error>> + Send {
541 async move {
542 let command = ApiLeaveGroup { group_id };
543 let response = self.send_raw(command.interpret()).await?;
544 // Safe to unwrap because unrecognized JSON goes to undocumented variant
545 Ok(serde_json::from_value(response).unwrap())
546 }
547 }
548
549 /// ### Group commands
550 ///
551 /// 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.
552 ///
553 /// ----
554 ///
555 /// Get group members.
556 ///
557 /// *Network usage*: no.
558 ///
559 /// *Syntax:*
560 ///
561 /// ```
562 /// /_members #<groupId>
563 /// ```
564 fn api_list_members(
565 &self,
566 group_id: i64,
567 ) -> impl Future<Output = Result<Arc<ApiListMembersResponse>, Self::Error>> + Send {
568 async move {
569 let command = ApiListMembers { group_id };
570 let response = self.send_raw(command.interpret()).await?;
571 // Safe to unwrap because unrecognized JSON goes to undocumented variant
572 Ok(serde_json::from_value(response).unwrap())
573 }
574 }
575
576 /// ### Group commands
577 ///
578 /// 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.
579 ///
580 /// ----
581 ///
582 /// Create group.
583 ///
584 /// *Network usage*: no.
585 ///
586 /// *Syntax:*
587 ///
588 /// ```
589 /// /_group <userId>[ incognito=on] <json(groupProfile)>
590 /// ```
591 fn api_new_group(
592 &self,
593 command: ApiNewGroup,
594 ) -> impl Future<Output = Result<Arc<ApiNewGroupResponse>, Self::Error>> + Send {
595 async move {
596 let response = self.send_raw(command.interpret()).await?;
597 // Safe to unwrap because unrecognized JSON goes to undocumented variant
598 Ok(serde_json::from_value(response).unwrap())
599 }
600 }
601
602 /// ### Group commands
603 ///
604 /// 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.
605 ///
606 /// ----
607 ///
608 /// Update group profile.
609 ///
610 /// *Network usage*: background.
611 ///
612 /// *Syntax:*
613 ///
614 /// ```
615 /// /_group_profile #<groupId> <json(groupProfile)>
616 /// ```
617 fn api_update_group_profile(
618 &self,
619 group_id: i64,
620 group_profile: GroupProfile,
621 ) -> impl Future<Output = Result<Arc<ApiUpdateGroupProfileResponse>, Self::Error>> + Send {
622 async move {
623 let command = ApiUpdateGroupProfile {
624 group_id,
625 group_profile,
626 };
627 let response = self.send_raw(command.interpret()).await?;
628 // Safe to unwrap because unrecognized JSON goes to undocumented variant
629 Ok(serde_json::from_value(response).unwrap())
630 }
631 }
632
633 /// ### Group link commands
634 ///
635 /// These commands can be used by bots that manage multiple public groups
636 ///
637 /// ----
638 ///
639 /// Create group link.
640 ///
641 /// *Network usage*: interactive.
642 ///
643 /// *Syntax:*
644 ///
645 /// ```
646 /// /_create link #<groupId> observer|author|member|moderator|admin|owner
647 /// ```
648 fn api_create_group_link(
649 &self,
650 group_id: i64,
651 member_role: GroupMemberRole,
652 ) -> impl Future<Output = Result<Arc<ApiCreateGroupLinkResponse>, Self::Error>> + Send {
653 async move {
654 let command = ApiCreateGroupLink {
655 group_id,
656 member_role,
657 };
658 let response = self.send_raw(command.interpret()).await?;
659 // Safe to unwrap because unrecognized JSON goes to undocumented variant
660 Ok(serde_json::from_value(response).unwrap())
661 }
662 }
663
664 /// ### Group link commands
665 ///
666 /// These commands can be used by bots that manage multiple public groups
667 ///
668 /// ----
669 ///
670 /// Set member role for group link.
671 ///
672 /// *Network usage*: no.
673 ///
674 /// *Syntax:*
675 ///
676 /// ```
677 /// /_set link role #<groupId> observer|author|member|moderator|admin|owner
678 /// ```
679 fn api_group_link_member_role(
680 &self,
681 group_id: i64,
682 member_role: GroupMemberRole,
683 ) -> impl Future<Output = Result<Arc<ApiGroupLinkMemberRoleResponse>, Self::Error>> + Send {
684 async move {
685 let command = ApiGroupLinkMemberRole {
686 group_id,
687 member_role,
688 };
689 let response = self.send_raw(command.interpret()).await?;
690 // Safe to unwrap because unrecognized JSON goes to undocumented variant
691 Ok(serde_json::from_value(response).unwrap())
692 }
693 }
694
695 /// ### Group link commands
696 ///
697 /// These commands can be used by bots that manage multiple public groups
698 ///
699 /// ----
700 ///
701 /// Delete group link.
702 ///
703 /// *Network usage*: background.
704 ///
705 /// *Syntax:*
706 ///
707 /// ```
708 /// /_delete link #<groupId>
709 /// ```
710 fn api_delete_group_link(
711 &self,
712 group_id: i64,
713 ) -> impl Future<Output = Result<Arc<ApiDeleteGroupLinkResponse>, Self::Error>> + Send {
714 async move {
715 let command = ApiDeleteGroupLink { group_id };
716 let response = self.send_raw(command.interpret()).await?;
717 // Safe to unwrap because unrecognized JSON goes to undocumented variant
718 Ok(serde_json::from_value(response).unwrap())
719 }
720 }
721
722 /// ### Group link commands
723 ///
724 /// These commands can be used by bots that manage multiple public groups
725 ///
726 /// ----
727 ///
728 /// Get group link.
729 ///
730 /// *Network usage*: no.
731 ///
732 /// *Syntax:*
733 ///
734 /// ```
735 /// /_get link #<groupId>
736 /// ```
737 fn api_get_group_link(
738 &self,
739 group_id: i64,
740 ) -> impl Future<Output = Result<Arc<ApiGetGroupLinkResponse>, Self::Error>> + Send {
741 async move {
742 let command = ApiGetGroupLink { group_id };
743 let response = self.send_raw(command.interpret()).await?;
744 // Safe to unwrap because unrecognized JSON goes to undocumented variant
745 Ok(serde_json::from_value(response).unwrap())
746 }
747 }
748
749 /// ### Connection commands
750 ///
751 /// 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.
752 ///
753 /// ----
754 ///
755 /// Create 1-time invitation link.
756 ///
757 /// *Network usage*: interactive.
758 ///
759 /// *Syntax:*
760 ///
761 /// ```
762 /// /_connect <userId>[ incognito=on]
763 /// ```
764 fn api_add_contact(
765 &self,
766 command: ApiAddContact,
767 ) -> impl Future<Output = Result<Arc<ApiAddContactResponse>, Self::Error>> + Send {
768 async move {
769 let response = self.send_raw(command.interpret()).await?;
770 // Safe to unwrap because unrecognized JSON goes to undocumented variant
771 Ok(serde_json::from_value(response).unwrap())
772 }
773 }
774
775 /// ### Connection commands
776 ///
777 /// 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.
778 ///
779 /// ----
780 ///
781 /// Determine SimpleX link type and if the bot is already connected via this link.
782 ///
783 /// *Network usage*: interactive.
784 ///
785 /// *Syntax:*
786 ///
787 /// ```
788 /// /_connect plan <userId> <connectionLink>
789 /// ```
790 fn api_connect_plan(
791 &self,
792 command: ApiConnectPlan,
793 ) -> impl Future<Output = Result<Arc<ApiConnectPlanResponse>, Self::Error>> + Send {
794 async move {
795 let response = self.send_raw(command.interpret()).await?;
796 // Safe to unwrap because unrecognized JSON goes to undocumented variant
797 Ok(serde_json::from_value(response).unwrap())
798 }
799 }
800
801 /// ### Connection commands
802 ///
803 /// 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.
804 ///
805 /// ----
806 ///
807 /// Connect via prepared SimpleX link. The link can be 1-time invitation link, contact address or group link
808 ///
809 /// *Network usage*: interactive.
810 ///
811 /// *Syntax:*
812 ///
813 /// ```
814 /// /_connect <userId>[ <str(preparedLink_)>]
815 /// ```
816 fn api_connect(
817 &self,
818 command: ApiConnect,
819 ) -> impl Future<Output = Result<Arc<ApiConnectResponse>, Self::Error>> + Send {
820 async move {
821 let response = self.send_raw(command.interpret()).await?;
822 // Safe to unwrap because unrecognized JSON goes to undocumented variant
823 Ok(serde_json::from_value(response).unwrap())
824 }
825 }
826
827 /// ### Connection commands
828 ///
829 /// 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.
830 ///
831 /// ----
832 ///
833 /// Connect via SimpleX link as string in the active user profile.
834 ///
835 /// *Network usage*: interactive.
836 ///
837 /// *Syntax:*
838 ///
839 /// ```
840 /// /connect[ <connLink_>]
841 /// ```
842 fn connect(
843 &self,
844 command: Connect,
845 ) -> impl Future<Output = Result<Arc<ConnectResponse>, Self::Error>> + Send {
846 async move {
847 let response = self.send_raw(command.interpret()).await?;
848 // Safe to unwrap because unrecognized JSON goes to undocumented variant
849 Ok(serde_json::from_value(response).unwrap())
850 }
851 }
852
853 /// ### Connection commands
854 ///
855 /// 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.
856 ///
857 /// ----
858 ///
859 /// Accept contact request.
860 ///
861 /// *Network usage*: interactive.
862 ///
863 /// *Syntax:*
864 ///
865 /// ```
866 /// /_accept <contactReqId>
867 /// ```
868 fn api_accept_contact(
869 &self,
870 contact_req_id: i64,
871 ) -> impl Future<Output = Result<Arc<ApiAcceptContactResponse>, Self::Error>> + Send {
872 async move {
873 let command = ApiAcceptContact { contact_req_id };
874 let response = self.send_raw(command.interpret()).await?;
875 // Safe to unwrap because unrecognized JSON goes to undocumented variant
876 Ok(serde_json::from_value(response).unwrap())
877 }
878 }
879
880 /// ### Connection commands
881 ///
882 /// 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.
883 ///
884 /// ----
885 ///
886 /// Reject contact request. The user who sent the request is **not notified**.
887 ///
888 /// *Network usage*: no.
889 ///
890 /// *Syntax:*
891 ///
892 /// ```
893 /// /_reject <contactReqId>
894 /// ```
895 fn api_reject_contact(
896 &self,
897 contact_req_id: i64,
898 ) -> impl Future<Output = Result<Arc<ApiRejectContactResponse>, Self::Error>> + Send {
899 async move {
900 let command = ApiRejectContact { contact_req_id };
901 let response = self.send_raw(command.interpret()).await?;
902 // Safe to unwrap because unrecognized JSON goes to undocumented variant
903 Ok(serde_json::from_value(response).unwrap())
904 }
905 }
906
907 /// ### Chat commands
908 ///
909 /// Commands to list and delete conversations.
910 ///
911 /// ----
912 ///
913 /// Get contacts.
914 ///
915 /// *Network usage*: no.
916 ///
917 /// *Syntax:*
918 ///
919 /// ```
920 /// /_contacts <userId>
921 /// ```
922 fn api_list_contacts(
923 &self,
924 user_id: i64,
925 ) -> impl Future<Output = Result<Arc<ApiListContactsResponse>, Self::Error>> + Send {
926 async move {
927 let command = ApiListContacts { user_id };
928 let response = self.send_raw(command.interpret()).await?;
929 // Safe to unwrap because unrecognized JSON goes to undocumented variant
930 Ok(serde_json::from_value(response).unwrap())
931 }
932 }
933
934 /// ### Chat commands
935 ///
936 /// Commands to list and delete conversations.
937 ///
938 /// ----
939 ///
940 /// Get groups.
941 ///
942 /// *Network usage*: no.
943 ///
944 /// *Syntax:*
945 ///
946 /// ```
947 /// /_groups <userId>[ @<contactId_>][ <search>]
948 /// ```
949 fn api_list_groups(
950 &self,
951 command: ApiListGroups,
952 ) -> impl Future<Output = Result<Arc<ApiListGroupsResponse>, Self::Error>> + Send {
953 async move {
954 let response = self.send_raw(command.interpret()).await?;
955 // Safe to unwrap because unrecognized JSON goes to undocumented variant
956 Ok(serde_json::from_value(response).unwrap())
957 }
958 }
959
960 /// ### Chat commands
961 ///
962 /// Commands to list and delete conversations.
963 ///
964 /// ----
965 ///
966 /// Delete chat.
967 ///
968 /// *Network usage*: background.
969 ///
970 /// *Syntax:*
971 ///
972 /// ```
973 /// /_delete <str(chatRef)> <str(chatDeleteMode)>
974 /// ```
975 fn api_delete_chat(
976 &self,
977 chat_ref: ChatRef,
978 chat_delete_mode: ChatDeleteMode,
979 ) -> impl Future<Output = Result<Arc<ApiDeleteChatResponse>, Self::Error>> + Send {
980 async move {
981 let command = ApiDeleteChat {
982 chat_ref,
983 chat_delete_mode,
984 };
985 let response = self.send_raw(command.interpret()).await?;
986 // Safe to unwrap because unrecognized JSON goes to undocumented variant
987 Ok(serde_json::from_value(response).unwrap())
988 }
989 }
990
991 /// ### User profile commands
992 ///
993 /// 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).
994 ///
995 /// ----
996 ///
997 /// Get active user profile
998 ///
999 /// *Network usage*: no.
1000 ///
1001 /// *Syntax:*
1002 ///
1003 /// ```
1004 /// /user
1005 /// ```
1006 fn show_active_user(
1007 &self,
1008 ) -> impl Future<Output = Result<Arc<ShowActiveUserResponse>, Self::Error>> + Send {
1009 async move {
1010 let command = ShowActiveUser {};
1011 let response = self.send_raw(command.interpret()).await?;
1012 // Safe to unwrap because unrecognized JSON goes to undocumented variant
1013 Ok(serde_json::from_value(response).unwrap())
1014 }
1015 }
1016
1017 /// ### User profile commands
1018 ///
1019 /// 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).
1020 ///
1021 /// ----
1022 ///
1023 /// Create new user profile
1024 ///
1025 /// *Network usage*: no.
1026 ///
1027 /// *Syntax:*
1028 ///
1029 /// ```
1030 /// /_create user <json(newUser)>
1031 /// ```
1032 fn create_active_user(
1033 &self,
1034 new_user: NewUser,
1035 ) -> impl Future<Output = Result<Arc<CreateActiveUserResponse>, Self::Error>> + Send {
1036 async move {
1037 let command = CreateActiveUser { new_user };
1038 let response = self.send_raw(command.interpret()).await?;
1039 // Safe to unwrap because unrecognized JSON goes to undocumented variant
1040 Ok(serde_json::from_value(response).unwrap())
1041 }
1042 }
1043
1044 /// ### User profile commands
1045 ///
1046 /// 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).
1047 ///
1048 /// ----
1049 ///
1050 /// Get all user profiles
1051 ///
1052 /// *Network usage*: no.
1053 ///
1054 /// *Syntax:*
1055 ///
1056 /// ```
1057 /// /users
1058 /// ```
1059 fn list_users(
1060 &self,
1061 ) -> impl Future<Output = Result<Arc<ListUsersResponse>, Self::Error>> + Send {
1062 async move {
1063 let command = ListUsers {};
1064 let response = self.send_raw(command.interpret()).await?;
1065 // Safe to unwrap because unrecognized JSON goes to undocumented variant
1066 Ok(serde_json::from_value(response).unwrap())
1067 }
1068 }
1069
1070 /// ### User profile commands
1071 ///
1072 /// 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).
1073 ///
1074 /// ----
1075 ///
1076 /// Set active user profile
1077 ///
1078 /// *Network usage*: no.
1079 ///
1080 /// *Syntax:*
1081 ///
1082 /// ```
1083 /// /_user <userId>[ <json(viewPwd)>]
1084 /// ```
1085 fn api_set_active_user(
1086 &self,
1087 command: ApiSetActiveUser,
1088 ) -> impl Future<Output = Result<Arc<ApiSetActiveUserResponse>, Self::Error>> + Send {
1089 async move {
1090 let response = self.send_raw(command.interpret()).await?;
1091 // Safe to unwrap because unrecognized JSON goes to undocumented variant
1092 Ok(serde_json::from_value(response).unwrap())
1093 }
1094 }
1095
1096 /// ### User profile commands
1097 ///
1098 /// 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).
1099 ///
1100 /// ----
1101 ///
1102 /// Delete user profile.
1103 ///
1104 /// *Network usage*: background.
1105 ///
1106 /// *Syntax:*
1107 ///
1108 /// ```
1109 /// /_delete user <userId> del_smp=on|off[ <json(viewPwd)>]
1110 /// ```
1111 fn api_delete_user(
1112 &self,
1113 command: ApiDeleteUser,
1114 ) -> impl Future<Output = Result<Arc<ApiDeleteUserResponse>, Self::Error>> + Send {
1115 async move {
1116 let response = self.send_raw(command.interpret()).await?;
1117 // Safe to unwrap because unrecognized JSON goes to undocumented variant
1118 Ok(serde_json::from_value(response).unwrap())
1119 }
1120 }
1121
1122 /// ### User profile commands
1123 ///
1124 /// 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).
1125 ///
1126 /// ----
1127 ///
1128 /// Update user profile.
1129 ///
1130 /// *Network usage*: background.
1131 ///
1132 /// *Syntax:*
1133 ///
1134 /// ```
1135 /// /_profile <userId> <json(profile)>
1136 /// ```
1137 fn api_update_profile(
1138 &self,
1139 user_id: i64,
1140 profile: Profile,
1141 ) -> impl Future<Output = Result<Arc<ApiUpdateProfileResponse>, Self::Error>> + Send {
1142 async move {
1143 let command = ApiUpdateProfile { user_id, profile };
1144 let response = self.send_raw(command.interpret()).await?;
1145 // Safe to unwrap because unrecognized JSON goes to undocumented variant
1146 Ok(serde_json::from_value(response).unwrap())
1147 }
1148 }
1149
1150 /// ### User profile commands
1151 ///
1152 /// 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).
1153 ///
1154 /// ----
1155 ///
1156 /// Configure chat preference overrides for the contact.
1157 ///
1158 /// *Network usage*: background.
1159 ///
1160 /// *Syntax:*
1161 ///
1162 /// ```
1163 /// /_set prefs @<contactId> <json(preferences)>
1164 /// ```
1165 fn api_set_contact_prefs(
1166 &self,
1167 contact_id: i64,
1168 preferences: Preferences,
1169 ) -> impl Future<Output = Result<Arc<ApiSetContactPrefsResponse>, Self::Error>> + Send {
1170 async move {
1171 let command = ApiSetContactPrefs {
1172 contact_id,
1173 preferences,
1174 };
1175 let response = self.send_raw(command.interpret()).await?;
1176 // Safe to unwrap because unrecognized JSON goes to undocumented variant
1177 Ok(serde_json::from_value(response).unwrap())
1178 }
1179 }
1180}