Skip to content

Commit

Permalink
Bot API 6.5 Changes (#97)
Browse files Browse the repository at this point in the history
* Bop API 6.5 Changes

https://core.telegram.org/bots/api#february-3-2023

* fix test

* remove `into` from u64

* bump version
  • Loading branch information
ayrat555 committed Feb 4, 2023
1 parent 3a52ed2 commit d7f0291
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 15 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Changelog

## 0.23.0 (2023-02-04)

### [Bot API 6.5](https://core.telegram.org/bots/api#february-3-2023) - [#97](https://github.com/ayrat555/frankenstein/pull/97)

* Added the struct `KeyboardButtonRequestUser` and the field `request_user` to the struct `KeyboardButton`.
* Added the struct `KeyboardButtonRequestChat` and the field `request_chat` to the struct `KeyboardButton`.
* Added the structs `UserShared`, `ChatShared` and the fields `user_shared`, and `chat_shared` to the struct `Message`.
* Replaced the fields `can_send_media_messages` in the structs `ChatMemberRestricted` and `ChatPermissions` with separate fields `can_send_audios`, `can_send_documents`, `can_send_photos`, `can_send_videos`, `can_send_video_notes`, and `can_send_voice_notes` for different media types.
* Added the parameter `use_independent_chat_permissions` to the structs `RestrictChatMemberParams` and `SetChatPermissionsParams`.
* Added the field `user_chat_id` to the struct `ChatJoinRequest`.

## 0.22.1 (2023-02-01)

* Improve code style - [#96](https://github.com/ayrat555/frankenstein/pull/96)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "frankenstein"
version = "0.22.1"
version = "0.23.0"
authors = ["Ayrat Badykov <[email protected]>"]
description = "Telegram bot API client for Rust"
edition = "2018"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Telegram bot API client for Rust.

It's a complete wrapper for Telegram bot API and it's up to date with version 6.4 of the API.
It's a complete wrapper for Telegram bot API and it's up to date with version 6.5 of the API.

Frankenstein data structures (rust structs and enums) are mapped one-to-one from Telegram bot API objects and method params.

Expand All @@ -17,7 +17,7 @@ Add this to your Cargo.toml

```toml
[dependencies]
frankenstein = "0.22"
frankenstein = "0.23"
```

## Features
Expand All @@ -35,13 +35,13 @@ frankenstein = "0.22"
To use the async client add the following line to your `Cargo.toml` file:

```toml
frankenstein = { version = "0.22", default-features = false, features = ["async-http-client"] }
frankenstein = { version = "0.23", default-features = false, features = ["async-http-client"] }
```

You can also disable all features:

```toml
frankenstein = { version = "0.22", default-features = false }
frankenstein = { version = "0.23", default-features = false }
```

In this case the crate will ship only with telegram types
Expand Down Expand Up @@ -195,7 +195,7 @@ AsyncApi::builder().api_url(api_url).client(client).build()

### Documentation

Frankenstein implements all telegram bot api methods. To see which parameters you should pass, check [docs.rs](https://docs.rs/frankenstein/0.22.1/frankenstein/api_traits/telegram_api/trait.TelegramApi.html#provided-methods)
Frankenstein implements all telegram bot api methods. To see which parameters you should pass, check [docs.rs](https://docs.rs/frankenstein/0.23.0/frankenstein/api_traits/telegram_api/trait.TelegramApi.html#provided-methods)

You can check out real-world bots created using this library:

Expand All @@ -213,7 +213,7 @@ The library uses `ureq` http client by default, but it can be easily replaced wi
1. `ureq` comes with a default feature (`impl`). So the feature should be disabled:

```toml
frankenstein = { version = "0.22", default-features = false, features = ["telegram-trait"] }
frankenstein = { version = "0.23", default-features = false, features = ["telegram-trait"] }
```

2. Implement `TelegramApi` trait which requires two functions:
Expand Down
2 changes: 1 addition & 1 deletion src/api/telegram_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ mod tests {

#[test]
fn get_chat_success() {
let response_string = "{\"ok\":true,\"result\":{\"id\":-1001368460856,\"type\":\"supergroup\",\"title\":\"Frankenstein\",\"photo\":{\"small_file_id\":\"AQADAgAT-kgrmy4AAwIAA8jhydkW____s1Cm6Dc_w8Ge7QUAAR8E\",\"small_file_unique_id\":\"AQAD-kgrmy4AA57tBQAB\",\"big_file_id\":\"AQADAgAT-kgrmy4AAwMAA8jhydkW____s1Cm6Dc_w8Gg7QUAAR8E\",\"big_file_unique_id\":\"AQAD-kgrmy4AA6DtBQAB\"},\"description\":\"Frankenstein group\",\"invite_link\":\"https://t.me/joinchat/smSXMzNKTwA0ZjFi\",\"permissions\":{\"can_send_messages\":true,\"can_send_media_messages\":true,\"can_send_polls\":true,\"can_send_other_messages\":true,\"can_add_web_page_previews\":true,\"can_change_info\":true,\"can_invite_users\":true,\"can_pin_messages\":true}}}";
let response_string = "{\"ok\":true,\"result\":{\"id\":-1001368460856,\"type\":\"supergroup\",\"title\":\"Frankenstein\",\"photo\":{\"small_file_id\":\"AQADAgAT-kgrmy4AAwIAA8jhydkW____s1Cm6Dc_w8Ge7QUAAR8E\",\"small_file_unique_id\":\"AQAD-kgrmy4AA57tBQAB\",\"big_file_id\":\"AQADAgAT-kgrmy4AAwMAA8jhydkW____s1Cm6Dc_w8Gg7QUAAR8E\",\"big_file_unique_id\":\"AQAD-kgrmy4AA6DtBQAB\"},\"description\":\"Frankenstein group\",\"invite_link\":\"https://t.me/joinchat/smSXMzNKTwA0ZjFi\",\"permissions\":{\"can_send_messages\":true,\"can_send_polls\":true,\"can_send_other_messages\":true,\"can_add_web_page_previews\":true,\"can_change_info\":true,\"can_invite_users\":true,\"can_pin_messages\":true}}}";
let params = GetChatParams::builder().chat_id(-1001368460856).build();

let _m = mockito::mock("POST", "/getChat")
Expand Down
8 changes: 8 additions & 0 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,10 @@ pub struct RestrictChatMemberParams {

pub permissions: ChatPermissions,

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub until_date: Option<u64>,
Expand Down Expand Up @@ -1295,6 +1299,10 @@ pub struct SetChatPermissionsParams {
pub chat_id: ChatId,

pub permissions: ChatPermissions,

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down
123 changes: 116 additions & 7 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,41 @@ pub struct ChatMemberMember {

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

pub user: User,

pub is_member: bool,

pub can_change_info: bool,
pub can_send_messages: bool,

pub can_invite_users: bool,
pub can_send_audios: bool,

pub can_pin_messages: bool,
pub can_send_documents: bool,

pub can_manage_topics: bool,
pub can_send_photos: bool,

pub can_send_messages: bool,
pub can_send_videos: bool,

pub can_send_video_notes: bool,

pub can_send_media_messages: bool,
pub can_send_voice_notes: bool,

pub can_send_polls: bool,

pub can_send_other_messages: bool,

pub can_add_web_page_previews: bool,

pub can_change_info: bool,

pub can_invite_users: bool,

pub can_pin_messages: bool,

pub can_manage_topics: bool,

pub until_date: u64,
}

Expand Down Expand Up @@ -735,6 +748,14 @@ pub struct Message {
#[builder(setter(into, strip_option), default)]
pub successful_payment: Option<Box<SuccessfulPayment>>,

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

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub connected_website: Option<String>,
Expand Down Expand Up @@ -1197,6 +1218,20 @@ pub struct GeneralForumTopicHidden {}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct GeneralForumTopicUnhidden {}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct UserShared {
pub request_id: i32,

pub user_id: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct ChatShared {
pub request_id: i32,

pub user_id: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct WriteAccessAllowed {}

Expand Down Expand Up @@ -1266,6 +1301,14 @@ pub struct KeyboardButton {
#[builder(setter(into))]
pub text: String,

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

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub request_contact: Option<bool>,
Expand All @@ -1283,6 +1326,50 @@ pub struct KeyboardButton {
pub web_app: Option<WebAppInfo>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct KeyboardButtonRequestUser {
pub request_id: i32,

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

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct KeyboardButtonRequestChat {
pub request_id: i32,

pub chat_is_channel: bool,

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

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

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

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

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

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

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct KeyboardButtonPollType {
#[serde(rename = "type")]
Expand Down Expand Up @@ -1469,6 +1556,8 @@ pub struct ChatJoinRequest {

pub from: User,

pub user_chat_id: u64,

pub date: u64,

#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -1488,7 +1577,27 @@ pub struct ChatPermissions {

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

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

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

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

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

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
Expand Down

0 comments on commit d7f0291

Please sign in to comment.