telegram_bot_async_raw/requests/
send_chat_action.rs

1use crate::{requests::*, types::*};
2
3/// Strongly typed ChatAction. Instead of passing a String to the
4/// `chat_action` method, this is used.
5#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
6#[must_use = "requests do nothing unless sent"]
7pub enum ChatAction {
8    #[serde(rename = "typing")]
9    Typing,
10    #[serde(rename = "upload_photo")]
11    UploadPhoto,
12    #[serde(rename = "record_video")]
13    RecordVideo,
14    #[serde(rename = "upload_video")]
15    UploadVideo,
16    #[serde(rename = "record_audio")]
17    RecordAudio,
18    #[serde(rename = "upload_audio")]
19    UploadAudio,
20    #[serde(rename = "upload_document")]
21    UploadDocument,
22    #[serde(rename = "find_location")]
23    FindLocation,
24}
25
26/// Use this method when you need to tell the user that something is happening on the bot's side.
27/// The status is set for 5 seconds or less (when a message arrives from your bot,
28/// Telegram clients clear its typing status).
29#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
30pub struct SendChatAction {
31    chat_id: ChatRef,
32    action: ChatAction,
33}
34
35impl Request for SendChatAction {
36    type Type = JsonRequestType<Self>;
37    type Response = JsonTrueToUnitResponse;
38
39    fn serialize(&self) -> Result<HttpRequest, Error> {
40        Self::Type::serialize(RequestUrl::method("sendChatAction"), self)
41    }
42}
43
44impl SendChatAction {
45    pub fn new<C>(chat: C, action: ChatAction) -> Self
46    where
47        C: ToChatRef,
48    {
49        SendChatAction {
50            chat_id: chat.to_chat_ref(),
51            action,
52        }
53    }
54}
55
56/// Send `action` to a chat.
57pub trait CanSendChatAction {
58    fn chat_action(&self, action: ChatAction) -> SendChatAction;
59}
60
61impl<C> CanSendChatAction for C
62where
63    C: ToChatRef,
64{
65    fn chat_action(&self, action: ChatAction) -> SendChatAction {
66        SendChatAction::new(self, action)
67    }
68}