use std::{
future::{Future, IntoFuture},
pin::Pin,
};
use serde::Serialize;
use crate::{
api::API,
entities::{
message::Message,
misc::{
chat_id::ChatId,
input_file::{GetFiles, InputFile},
reply_markup::ReplyMarkup,
},
reply_parameters::ReplyParameters,
},
errors::ConogramError,
impl_into_future_multipart,
request::RequestT,
utils::deserialize_utils::is_false,
};
#[derive(Debug, Clone, Serialize)]
pub struct SendStickerParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub business_connection_id: Option<String>,
pub chat_id: ChatId,
#[serde(skip_serializing_if = "Option::is_none")]
pub message_thread_id: Option<i64>,
pub sticker: InputFile,
#[serde(skip_serializing_if = "Option::is_none")]
pub emoji: Option<String>,
#[serde(default, skip_serializing_if = "is_false")]
pub disable_notification: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub protect_content: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub allow_paid_broadcast: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub message_effect_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_parameters: Option<ReplyParameters>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<ReplyMarkup>,
}
impl GetFiles for SendStickerParams {
fn get_files(&self) -> Vec<&InputFile> {
vec![&self.sticker]
}
}
impl_into_future_multipart!(SendStickerRequest<'a>);
#[derive(Clone)]
pub struct SendStickerRequest<'a> {
api: &'a API,
params: SendStickerParams,
}
impl<'a> RequestT for SendStickerRequest<'a> {
type ParamsType = SendStickerParams;
type ReturnType = Message;
fn get_name() -> &'static str {
"sendSticker"
}
fn get_api_ref(&self) -> &API {
self.api
}
fn get_params_ref(&self) -> &Self::ParamsType {
&self.params
}
fn is_multipart() -> bool {
true
}
}
impl<'a> SendStickerRequest<'a> {
pub fn new(api: &'a API, chat_id: impl Into<ChatId>, sticker: impl Into<InputFile>) -> Self {
Self {
api,
params: SendStickerParams {
chat_id: chat_id.into(),
sticker: sticker.into(),
business_connection_id: Option::default(),
message_thread_id: Option::default(),
emoji: Option::default(),
disable_notification: bool::default(),
protect_content: bool::default(),
allow_paid_broadcast: bool::default(),
message_effect_id: Option::default(),
reply_parameters: Option::default(),
reply_markup: Option::default(),
},
}
}
#[must_use]
pub fn business_connection_id(mut self, business_connection_id: impl Into<String>) -> Self {
self.params.business_connection_id = Some(business_connection_id.into());
self
}
#[must_use]
pub fn chat_id(mut self, chat_id: impl Into<ChatId>) -> Self {
self.params.chat_id = chat_id.into();
self
}
#[must_use]
pub fn message_thread_id(mut self, message_thread_id: impl Into<i64>) -> Self {
self.params.message_thread_id = Some(message_thread_id.into());
self
}
#[must_use]
pub fn sticker(mut self, sticker: impl Into<InputFile>) -> Self {
self.params.sticker = sticker.into();
self
}
#[must_use]
pub fn emoji(mut self, emoji: impl Into<String>) -> Self {
self.params.emoji = Some(emoji.into());
self
}
#[must_use]
pub fn disable_notification(mut self, disable_notification: impl Into<bool>) -> Self {
self.params.disable_notification = disable_notification.into();
self
}
#[must_use]
pub fn protect_content(mut self, protect_content: impl Into<bool>) -> Self {
self.params.protect_content = protect_content.into();
self
}
#[must_use]
pub fn allow_paid_broadcast(mut self, allow_paid_broadcast: impl Into<bool>) -> Self {
self.params.allow_paid_broadcast = allow_paid_broadcast.into();
self
}
#[must_use]
pub fn message_effect_id(mut self, message_effect_id: impl Into<String>) -> Self {
self.params.message_effect_id = Some(message_effect_id.into());
self
}
#[must_use]
pub fn reply_parameters(mut self, reply_parameters: impl Into<ReplyParameters>) -> Self {
self.params.reply_parameters = Some(reply_parameters.into());
self
}
#[must_use]
pub fn reply_markup(mut self, reply_markup: impl Into<ReplyMarkup>) -> Self {
self.params.reply_markup = Some(reply_markup.into());
self
}
}
impl API {
pub fn send_sticker(
&self,
chat_id: impl Into<ChatId>,
sticker: impl Into<InputFile>,
) -> SendStickerRequest {
SendStickerRequest::new(self, chat_id, sticker)
}
}