Skip to content

Commit

Permalink
Bot API 6.1 Changes (#73)
Browse files Browse the repository at this point in the history
* Bot API 6.1 Changes

* add create_invoice_link method

* bump version
  • Loading branch information
ayrat555 authored Jun 21, 2022
1 parent 997730c commit 8fd398f
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.18.0 (2022-06-21)
### [Bot API 6.1](https://core.telegram.org/bots/api-changelog#june-20-2022) - [#73](https://github.com/ayrat555/frankenstein/pull/73)

* Added the fields `join_to_send_messages` and `join_by_request` to the struct `Chat`.
* Added the method `create_invoice_link` to generate an HTTP link for an invoice
* Added the field `is_premium` to the struct `User`.
* Added the field `premium_animation` to the struct `Sticker`.
* Added the field `added_to_attachment_menu` to the struct `User`.
* Added the parameter `secret_token` to the method `set_webhook`.

## 0.17.0 (2022-06-16)

* Change type of file_size from u32 to u64 by @ayrat555 in [#70](https://github.com/ayrat555/frankenstein/pull/70)
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.17.0"
version = "0.18.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 of the API.
It's a complete wrapper for Telegram bot API and it's up to date with version 6.1 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.17"
frankenstein = "0.18"
```

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

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

You can also disable all features:

```toml
frankenstein = { version = "0.17", default-features = false }
frankenstein = { version = "0.18", default-features = false }
```

In this case the crate will ship only with telegram types
Expand Down Expand Up @@ -158,7 +158,7 @@ It has two variants:

### Documentation

Frankenstein implements all telegram bot api methods. To see which parameters you should pass, check [docs.rs](https://docs.rs/frankenstein/0.17.0/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.18.0/frankenstein/api_traits/telegram_api/trait.TelegramApi.html#provided-methods)

You can check out a real world bot created using this library - [El Monitorro](https://github.com/ayrat555/el_monitorro). El Monitorro is a feed reader bot.

Expand All @@ -170,7 +170,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.17", default-features = false, features = ["telegram-trait"] }
frankenstein = { version = "0.18", default-features = false, features = ["telegram-trait"] }
```

2. Implement `TelegramApi` trait which requires two functions:
Expand Down
80 changes: 80 additions & 0 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ pub struct SetWebhookParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub drop_pending_updates: Option<bool>,

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

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Builder)]
Expand Down Expand Up @@ -1836,6 +1840,82 @@ pub struct SendInvoiceParams {
pub reply_markup: Option<InlineKeyboardMarkup>,
}

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

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

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

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

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

pub prices: Vec<LabeledPrice>,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct AnswerShippingQueryParams {
#[builder(setter(into))]
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 @@ -11,6 +11,7 @@ use crate::api_params::BanChatMemberParams;
use crate::api_params::BanChatSenderChatParams;
use crate::api_params::CopyMessageParams;
use crate::api_params::CreateChatInviteLinkParams;
use crate::api_params::CreateInvoiceLinkParams;
use crate::api_params::CreateNewStickerSetParams;
use crate::api_params::DeclineChatJoinRequestParams;
use crate::api_params::DeleteChatPhotoParams;
Expand Down Expand Up @@ -967,6 +968,13 @@ pub trait AsyncTelegramApi {
self.request("sendInvoice", Some(params)).await
}

async fn create_invoice_link(
&self,
params: &CreateInvoiceLinkParams,
) -> Result<MethodResponse<String>, Self::Error> {
self.request("createInvoiceLink", Some(params)).await
}

async fn answer_shipping_query(
&self,
params: &AnswerShippingQueryParams,
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 @@ -11,6 +11,7 @@ use crate::api_params::BanChatMemberParams;
use crate::api_params::BanChatSenderChatParams;
use crate::api_params::CopyMessageParams;
use crate::api_params::CreateChatInviteLinkParams;
use crate::api_params::CreateInvoiceLinkParams;
use crate::api_params::CreateNewStickerSetParams;
use crate::api_params::DeclineChatJoinRequestParams;
use crate::api_params::DeleteChatPhotoParams;
Expand Down Expand Up @@ -916,6 +917,13 @@ pub trait TelegramApi {
self.request("sendInvoice", Some(params))
}

fn create_invoice_link(
&self,
params: &CreateInvoiceLinkParams,
) -> Result<MethodResponse<String>, Self::Error> {
self.request("createInvoiceLink", Some(params))
}

fn answer_shipping_query(
&self,
params: &AnswerShippingQueryParams,
Expand Down
20 changes: 20 additions & 0 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ pub struct User {
#[builder(setter(into, strip_option), default)]
pub language_code: Option<String>,

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

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub can_join_groups: Option<bool>,
Expand Down Expand Up @@ -425,6 +433,14 @@ 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 join_to_send_messages: Option<bool>,

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

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub description: Option<String>,
Expand Down Expand Up @@ -1429,6 +1445,10 @@ pub struct Sticker {
#[builder(setter(into, strip_option), default)]
pub set_name: Option<String>,

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

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

0 comments on commit 8fd398f

Please sign in to comment.