Skip to content

Commit

Permalink
Bot API 6.2
Browse files Browse the repository at this point in the history
* August 12 most api changes

* some fixes

* Eq derive

* Fixing tests and fixing Serialize for Sticker and StickerSet

* Eq my bad xd

* Some more changes

* Just one StickerType

* Fix comments

* import Sticker async api

* Deprecated and hidden

* Allow deprecated in Api Params
  • Loading branch information
pxp9 authored Aug 13, 2022
1 parent 80435de commit 8d7f439
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/api/telegram_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ mod tests {

#[test]
fn send_sticker_success() {
let response_string = "{\"ok\":true,\"result\":{\"message_id\":2788,\"from\":{\"id\":1276618370,\"is_bot\":true,\"first_name\":\"test_el_bot\",\"username\":\"el_mon_test_bot\"},\"date\":1619245784,\"chat\":{\"id\":275808073,\"type\":\"private\",\"username\":\"Ayrat555\",\"first_name\":\"Ayrat\",\"last_name\":\"Badykov\"},\"sticker\":{\"file_id\":\"CAACAgIAAxkDAAIK5GCDutgNxc07rqqtjkGWrGskbHfQAAIMEAACRx8ZSKJ6Z5GkdVHcHwQ\",\"file_unique_id\":\"AgADDBAAAkcfGUg\",\"width\":512,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumb\":{\"file_id\":\"AAMCAgADGQMAAgrkYIO62A3FzTuuqq2OQZasayRsd9AAAgwQAAJHHxlIonpnkaR1Udz29bujLgADAQAHbQADzR4AAh8E\",\"file_unique_id\":\"AQAD9vW7oy4AA80eAAI\",\"width\":320,\"height\":320,\"file_size\":19264},\"file_size\":36596}}}";
let response_string = "{\"ok\":true,\"result\":{\"message_id\":2788,\"from\":{\"id\":1276618370,\"is_bot\":true,\"first_name\":\"test_el_bot\",\"username\":\"el_mon_test_bot\"},\"date\":1619245784,\"chat\":{\"id\":275808073,\"type\":\"private\",\"username\":\"Ayrat555\",\"first_name\":\"Ayrat\",\"last_name\":\"Badykov\"},\"sticker\":{\"file_id\":\"CAACAgIAAxkDAAIK5GCDutgNxc07rqqtjkGWrGskbHfQAAIMEAACRx8ZSKJ6Z5GkdVHcHwQ\",\"file_unique_id\":\"AgADDBAAAkcfGUg\",\"type\":\"regular\",\"width\":512,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumb\":{\"file_id\":\"AAMCAgADGQMAAgrkYIO62A3FzTuuqq2OQZasayRsd9AAAgwQAAJHHxlIonpnkaR1Udz29bujLgADAQAHbQADzR4AAh8E\",\"file_unique_id\":\"AQAD9vW7oy4AA80eAAI\",\"width\":320,\"height\":320,\"file_size\":19264},\"file_size\":36596}}}";

let file = std::path::PathBuf::from("./frankenstein_logo.png");
let params = SendStickerParams::builder()
Expand All @@ -1617,14 +1617,14 @@ mod tests {

#[test]
fn get_sticker_set_success() {
let response_string = "{\"ok\":true,\"result\":{\"name\":\"unocards\",\"title\":\"UNO Bot\",\"is_animated\":false,\"is_video\":false,\"contains_masks\":false,\"stickers\":[{\"file_id\":\"CAACAgQAAxUAAWCDxAQVJ6X7FGiBD5NyjN5DDvgfAALZAQACX1eZAAEqnpNt3SpG_x8E\",\"file_unique_id\":\"AgAD2QEAAl9XmQAB\",\"width\":342,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumb\":{\"file_id\":\"AAMCBAADFQABYIPEBBUnpfsUaIEPk3KM3kMO-B8AAtkBAAJfV5kAASqek23dKkb_P75BGQAEAQAHbQADBBEAAh8E\",\"file_unique_id\":\"AQADP75BGQAEBBEAAg\",\"width\":85,\"height\":128,\"file_size\":2452},\"emoji\":\"dd\",\"set_name\":\"unocards\",\"file_size\":8898}]}}";
let response_string = "{\"ok\":true,\"result\":{\"name\":\"unocards\",\"title\":\"UNO Bot\",\"sticker_type\":\"regular\",\"is_animated\":false,\"is_video\":false,\"contains_masks\":false,\"stickers\":[{\"file_id\":\"CAACAgQAAxUAAWCDxAQVJ6X7FGiBD5NyjN5DDvgfAALZAQACX1eZAAEqnpNt3SpG_x8E\",\"file_unique_id\":\"AgAD2QEAAl9XmQAB\",\"type\":\"regular\",\"width\":342,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumb\":{\"file_id\":\"AAMCBAADFQABYIPEBBUnpfsUaIEPk3KM3kMO-B8AAtkBAAJfV5kAASqek23dKkb_P75BGQAEAQAHbQADBBEAAh8E\",\"file_unique_id\":\"AQADP75BGQAEBBEAAg\",\"width\":85,\"height\":128,\"file_size\":2452},\"emoji\":\"dd\",\"set_name\":\"unocards\",\"file_size\":8898}]}}";

let params = GetStickerSetParams::builder().name("unocards").build();
let _m = mockito::mock("POST", "/getStickerSet")
.with_status(200)
.with_body(response_string)
.create();
let api = Api::new_url(mockito::server_url());

let response = api.get_sticker_set(&params).unwrap();

let json = serde_json::to_string(&response).unwrap();
Expand Down
15 changes: 14 additions & 1 deletion src/api_params.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(deprecated)]
use crate::objects::{
BotCommand, ChatAdministratorRights, ChatPermissions, ForceReply, InlineKeyboardMarkup,
InlineQueryResultArticle, InlineQueryResultAudio, InlineQueryResultCachedAudio,
Expand All @@ -11,7 +12,7 @@ use crate::objects::{
PassportElementErrorFiles, PassportElementErrorFrontSide, PassportElementErrorReverseSide,
PassportElementErrorSelfie, PassportElementErrorTranslationFile,
PassportElementErrorTranslationFiles, PassportElementErrorUnspecified, PollType,
ReplyKeyboardMarkup, ReplyKeyboardRemove, ShippingOption,
ReplyKeyboardMarkup, ReplyKeyboardRemove, ShippingOption, StickerType,
};
use crate::{AllowedUpdate, ParseMode};
use serde::Deserialize;
Expand Down Expand Up @@ -1645,9 +1646,15 @@ pub struct CreateNewStickerSetParams {
#[builder(setter(into, strip_option), default)]
pub webm_sticker: Option<InputFile>,

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

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

#[doc(hidden)]
#[deprecated(since = "0.19.2", note = "Please use `sticker_type` instead")]
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub contains_masks: Option<bool>,
Expand All @@ -1657,6 +1664,12 @@ pub struct CreateNewStickerSetParams {
pub mask_position: Option<MaskPosition>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct GetCustomEmojiStickersParams {
#[builder(setter(into))]
pub custom_emoji_ids: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct AddStickerToSetParams {
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 @@ -34,6 +34,7 @@ use crate::api_params::GetChatMemberCountParams;
use crate::api_params::GetChatMemberParams;
use crate::api_params::GetChatMenuButtonParams;
use crate::api_params::GetChatParams;
use crate::api_params::GetCustomEmojiStickersParams;
use crate::api_params::GetFileParams;
use crate::api_params::GetGameHighScoresParams;
use crate::api_params::GetMyCommandsParams;
Expand Down Expand Up @@ -102,6 +103,7 @@ use crate::objects::Update;
use crate::objects::User;
use crate::objects::UserProfilePhotos;
use crate::objects::WebhookInfo;
use crate::Sticker;
use async_trait::async_trait;
use std::path::PathBuf;

Expand Down Expand Up @@ -913,6 +915,12 @@ pub trait AsyncTelegramApi {
.await
}

async fn get_custom_emoji_stickers(
&self,
params: &GetCustomEmojiStickersParams,
) -> Result<MethodResponse<Vec<Sticker>>, Self::Error> {
self.request("getCustomEmojiStickers", Some(params)).await
}
async fn add_sticker_to_set(
&self,
params: &AddStickerToSetParams,
Expand Down
9 changes: 9 additions & 0 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ use crate::objects::Update;
use crate::objects::User;
use crate::objects::UserProfilePhotos;
use crate::objects::WebhookInfo;
use crate::GetCustomEmojiStickersParams;
use crate::Sticker;
use std::path::PathBuf;

pub trait TelegramApi {
Expand Down Expand Up @@ -864,6 +866,13 @@ pub trait TelegramApi {
self.request_with_possible_form_data(method_name, params, files)
}

fn get_custom_emoji_stickers(
&self,
params: &GetCustomEmojiStickersParams,
) -> Result<MethodResponse<Vec<Sticker>>, Self::Error> {
self.request("getCustomEmojiStickers", Some(params))
}

fn add_sticker_to_set(
&self,
params: &AddStickerToSetParams,
Expand Down
32 changes: 32 additions & 0 deletions src/objects.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#![allow(deprecated)]
use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder as Builder;

use crate::ParseMode;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum StickerType {
#[serde(rename = "regular")]
Regular,
#[serde(rename = "mask")]
Mask,
#[serde(rename = "custom_emoji")]
CustomEmoji,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(untagged)]
pub enum InputMessageContent {
Expand Down Expand Up @@ -58,6 +69,7 @@ pub enum MessageEntityType {
Pre,
TextLink,
TextMention,
CustomEmoji,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -433,6 +445,10 @@ pub struct Chat {
#[builder(setter(into, strip_option), default)]
pub has_private_forwards: Option<bool>,

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub join_to_send_messages: Option<bool>,
Expand Down Expand Up @@ -745,6 +761,10 @@ pub struct MessageEntity {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub language: Option<String>,

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -1425,6 +1445,9 @@ pub struct Sticker {
#[builder(setter(into))]
pub file_unique_id: String,

#[serde(rename = "type")]
pub sticker_type: StickerType,

pub width: u32,

pub height: u32,
Expand Down Expand Up @@ -1453,6 +1476,10 @@ pub struct Sticker {
#[builder(setter(into, strip_option), default)]
pub mask_position: Option<MaskPosition>,

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub file_size: Option<u64>,
Expand All @@ -1466,10 +1493,15 @@ pub struct StickerSet {
#[builder(setter(into))]
pub title: String,

#[serde(rename = "sticker_type")]
pub sticker_type: StickerType,

pub is_animated: bool,

pub is_video: bool,

#[doc(hidden)]
#[deprecated(since = "0.19.2", note = "Please use `sticker_type` instead")]
pub contains_masks: bool,

pub stickers: Vec<Sticker>,
Expand Down

0 comments on commit 8d7f439

Please sign in to comment.