Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot API 7.0 #128

Merged
merged 5 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::objects::{
MenuButton, MessageEntity, PassportElementErrorDataField, PassportElementErrorFile,
PassportElementErrorFiles, PassportElementErrorFrontSide, PassportElementErrorReverseSide,
PassportElementErrorSelfie, PassportElementErrorTranslationFile,
PassportElementErrorTranslationFiles, PassportElementErrorUnspecified, PollType,
PassportElementErrorTranslationFiles, PassportElementErrorUnspecified, PollType, ReactionType,
ReplyKeyboardMarkup, ReplyKeyboardRemove, ShippingOption, StickerFormat, StickerType,
WebAppInfo,
};
Expand Down Expand Up @@ -1135,6 +1135,20 @@ pub struct SendChatActionParams {
pub action: ChatAction,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct SetMessageReactionParams {
#[builder(setter(into))]
pub chat_id: ChatId,

pub message_id: i32,

pub reacion: Vec<ReactionType>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub is_big: Option<bool>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct GetUserProfilePhotosParams {
pub user_id: u64,
Expand Down
8 changes: 8 additions & 0 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ use crate::api_params::SetChatStickerSetParams;
use crate::api_params::SetChatTitleParams;
use crate::api_params::SetCustomEmojiStickerSetThumbnailParams;
use crate::api_params::SetGameScoreParams;
use crate::api_params::SetMessageReactionParams;
use crate::api_params::SetMyCommandsParams;
use crate::api_params::SetMyDefaultAdministratorRightsParams;
use crate::api_params::SetMyDescriptionParams;
Expand Down Expand Up @@ -488,6 +489,13 @@ pub trait AsyncTelegramApi {
self.request("sendChatAction", Some(params)).await
}

async fn set_message_reaction(
&self,
params: &SetMessageReactionParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("setMessageReaction", Some(params)).await
}

async fn get_user_profile_photos(
&self,
params: &GetUserProfilePhotosParams,
Expand Down
8 changes: 8 additions & 0 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ use crate::api_params::SetChatStickerSetParams;
use crate::api_params::SetChatTitleParams;
use crate::api_params::SetCustomEmojiStickerSetThumbnailParams;
use crate::api_params::SetGameScoreParams;
use crate::api_params::SetMessageReactionParams;
use crate::api_params::SetMyCommandsParams;
use crate::api_params::SetMyDefaultAdministratorRightsParams;
use crate::api_params::SetMyDescriptionParams;
Expand Down Expand Up @@ -454,6 +455,13 @@ pub trait TelegramApi {
self.request("sendChatAction", Some(params))
}

fn set_message_reaction(
&self,
params: &SetMessageReactionParams,
) -> Result<MethodResponse<bool>, Self::Error> {
self.request("setMessageReaction", Some(params))
}

fn get_user_profile_photos(
&self,
params: &GetUserProfilePhotosParams,
Expand Down
68 changes: 68 additions & 0 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ pub enum UpdateContent {
EditedMessage(Message),
ChannelPost(Message),
EditedChannelPost(Message),
MessageReaction(MessageReactionUpdated),
MessageReactionCount(MessageReactionCountUpdated),
InlineQuery(InlineQuery),
ChosenInlineResult(ChosenInlineResult),
CallbackQuery(CallbackQuery),
Expand Down Expand Up @@ -402,6 +404,8 @@ pub enum AllowedUpdate {
EditedMessage,
ChannelPost,
EditedChannelPost,
MessageReaction,
MessageReactionCount,
InlineQuery,
ChosenInlineResult,
CallbackQuery,
Expand Down Expand Up @@ -491,6 +495,10 @@ pub struct Chat {
#[builder(setter(into, strip_option), default)]
pub active_usernames: Option<Vec<String>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub available_reactions: Option<Vec<ReactionType>>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub emoji_status_custom_emoji_id: Option<String>,
Expand Down Expand Up @@ -1722,6 +1730,66 @@ pub struct ChatLocation {
pub address: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ReactionType {
Emoji(ReactionTypeEmoji),
CustomEmoji(ReactionTypeCustomEmoji),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Eq)]
pub struct ReactionTypeEmoji {
#[builder(setter(into))]
pub emoji: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Eq)]
pub struct ReactionTypeCustomEmoji {
#[builder(setter(into))]
pub custom_emoji: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct ReactionCount {
#[builder(setter(into))]
#[serde(rename = "type")]
pub type_field: ReactionType,

pub total_count: i32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct MessageReactionUpdated {
pub chat: Chat,

pub message_id: i32,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub user: Option<User>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub actor_chat: Option<Chat>,

pub date: u64,

pub old_reaction: Vec<ReactionType>,

pub new_reaction: Vec<ReactionType>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct MessageReactionCountUpdated {
pub chat: Chat,

pub message_id: i32,

pub date: u64,

pub reactions: Vec<ReactionCount>,
}

#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, Builder)]
pub struct ForumTopic {
pub message_thread_id: i32,
Expand Down