1mod builder;
2mod response;
3mod types;
4
5pub use builder::{SetChatNotice, SetChatSettings};
6pub use response::{ChatSettingResponse, MessageResponse};
7pub use types::{ChatCondition, ChatGroup, ChatSlowModeSec, MinFollowerMinute};
8
9use std::future::Future;
10
11use types::{MessageBody, NoticeBody};
12
13use crate::{
14 BaseClient, Error, Response, UserClient,
15 types::constants::{CHATS, SEND, SETTINGS},
16};
17
18pub trait ChatAPI: BaseClient {
19 fn send_message(
21 &self,
22 message: &str,
23 ) -> impl Future<Output = Result<Response<MessageResponse>, Error>> + Send;
24
25 fn set_chat_notice<'a>(&'a self) -> SetChatNotice<'a>;
27
28 fn get_chat_settings(
30 &self,
31 ) -> impl Future<Output = Result<Response<ChatSettingResponse>, Error>> + Send;
32
33 fn set_chat_settings<'a>(&'a self) -> SetChatSettings<'a>;
35}
36
37impl ChatAPI for UserClient {
38 async fn send_message(&self, message: &str) -> Result<Response<MessageResponse>, Error> {
39 let mut url = self.base_url();
40 url.path_segments_mut().unwrap().extend([CHATS, SEND]);
41 crate::client::json(self.http_client().post(url).json(&MessageBody { message })).await
42 }
43
44 fn set_chat_notice<'a>(&'a self) -> SetChatNotice<'a> {
45 SetChatNotice::new(self)
46 }
47
48 async fn get_chat_settings(&self) -> Result<Response<ChatSettingResponse>, Error> {
49 let mut url = self.base_url();
50 url.path_segments_mut().unwrap().extend([CHATS, SETTINGS]);
51 crate::client::json(self.http_client().get(url)).await
52 }
53
54 fn set_chat_settings<'a>(&'a self) -> SetChatSettings<'a> {
55 SetChatSettings::new(self)
56 }
57}