Skip to content

Commit

Permalink
Bot API 7.0: Reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ayrat555 committed Dec 30, 2023
1 parent 172997c commit 89196ce
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
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/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
76 changes: 76 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,74 @@ 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))]
#[serde(rename = "type")]
pub type_field: String,

#[builder(setter(into))]
pub emoji: String,
}

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

#[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

0 comments on commit 89196ce

Please sign in to comment.