use serde::{Deserialize, Serialize};
use crate::{
api::{Method, Payload, PayloadError},
types::{ChatId, Integer},
};
#[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ChatAction {
ChooseSticker,
FindLocation,
RecordVideo,
RecordVoice,
RecordVideoNote,
Typing,
UploadDocument,
UploadPhoto,
UploadVideo,
UploadVideoNote,
UploadVoice,
}
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct SendChatAction {
action: ChatAction,
chat_id: ChatId,
business_connection_id: Option<String>,
message_thread_id: Option<Integer>,
}
impl SendChatAction {
pub fn new<T>(chat_id: T, action: ChatAction) -> Self
where
T: Into<ChatId>,
{
Self {
action,
chat_id: chat_id.into(),
business_connection_id: None,
message_thread_id: None,
}
}
pub fn with_business_connection_id<T>(mut self, value: T) -> Self
where
T: Into<String>,
{
self.business_connection_id = Some(value.into());
self
}
pub fn with_message_thread_id(mut self, value: Integer) -> Self {
self.message_thread_id = Some(value);
self
}
}
impl Method for SendChatAction {
type Response = bool;
fn into_payload(self) -> Result<Payload, PayloadError> {
Payload::json("sendChatAction", self)
}
}