Skip to content

Commit

Permalink
updated to support the telegram bot api v6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
CalliEve committed Nov 14, 2022
1 parent e417d47 commit 01ec59e
Show file tree
Hide file tree
Showing 16 changed files with 461 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "telexide"
version = "0.1.7"
version = "0.1.8"
description = "An async Rust library for the telegram bot API."
documentation = "https://docs.rs/telexide"
repository = "https://github.com/callieve/telexide"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Add the following to your `Cargo.toml` file:

```toml
[dependencies]
telexide = "0.1.7"
telexide = "0.1.8"
```

## Supported Rust Versions
Expand Down
89 changes: 89 additions & 0 deletions src/api/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,95 @@ pub trait API: Sync {
.into()
}

/// Use this method to get custom emoji stickers, which can be used as
/// a forum topic icon by any user. Returns a `Vec<`[`Sticker`]`>`.
async fn get_forum_topic_icon_stickers(&self) -> Result<Vec<Sticker>> {
self.get(APIEndpoint::GetForumTopicIconStickers, None)
.await?
.into()
}

/// Use this method to create a topic in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must
/// have the can_manage_topics administrator rights.
/// Returns information about the created topic as a [`ForumTopic`] object.
async fn create_forum_topic(&self, data: CreateForumTopic) -> Result<ForumTopic> {
self.post(
APIEndpoint::CreateForumTopic,
Some(serde_json::to_value(data)?),
)
.await?
.into()
}

/// Use this method to edit name and icon of a topic in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must
/// have can_manage_topics administrator rights, unless it is the creator of the topic.
/// Returns True on success.
async fn edit_forum_topic(&self, data: EditForumTopic) -> Result<bool> {
self.post(
APIEndpoint::EditForumTopic,
Some(serde_json::to_value(data)?),
)
.await?
.into()
}

/// Use this method to close an open topic in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must
/// have the can_manage_topics administrator rights, unless it is the creator of the topic.
/// Returns True on success.
async fn close_forum_topic(&self, data: CloseForumTopic) -> Result<bool> {
self.post(
APIEndpoint::CloseForumTopic,
Some(serde_json::to_value(data)?),
)
.await?
.into()
}

/// Use this method to reopen a closed topic in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must
/// have the can_manage_topics administrator rights, unless it is the creator of the topic.
/// Returns True on success.
async fn reopen_forum_topic(&self, data: ReopenForumTopic) -> Result<bool> {
self.post(
APIEndpoint::ReopenForumTopic,
Some(serde_json::to_value(data)?),
)
.await?
.into()
}

/// Use this method to delete a forum topic along with all its messages in a forum supergroup chat.
/// The bot must be an administrator in the chat for this to work and must
/// have the can_delete_messages administrator rights.
/// Returns True on success.
async fn delete_forum_topic(&self, data: DeleteForumTopic) -> Result<bool> {
self.post(
APIEndpoint::DeleteForumTopic,
Some(serde_json::to_value(data)?),
)
.await?
.into()
}

/// Use this method to clear the list of pinned messages in a forum topic.
/// The bot must be an administrator in the chat for this to work and must
/// have the can_pin_messages administrator right in the supergroup.
/// Returns True on success.
async fn unpin_all_forum_topic_messages(
&self,
data: UnpinAllForumTopicMessages,
) -> Result<bool> {
self.post(
APIEndpoint::UnpinAllForumTopicMessages,
Some(serde_json::to_value(data)?),
)
.await?
.into()
}

/// Use this method to send answers to callback queries sent from [inline keyboards](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating).
/// The answer will be displayed to the user as a notification at the top of
/// the chat screen or as an alert. On success, True is returned.
Expand Down
14 changes: 14 additions & 0 deletions src/api/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ pub enum APIEndpoint {
GetChatMember,
SetChatStickerSet,
DeleteChatStickerSet,
GetForumTopicIconStickers,
CreateForumTopic,
EditForumTopic,
CloseForumTopic,
ReopenForumTopic,
DeleteForumTopic,
UnpinAllForumTopicMessages,
AnswerCallbackQuery,
EditMessageText,
EditMessageCaption,
Expand Down Expand Up @@ -158,6 +165,13 @@ impl APIEndpoint {
Self::GetChatMember => "getChatMember",
Self::SetChatStickerSet => "setChatStickerSet",
Self::DeleteChatStickerSet => "deleteChatStickerSet",
Self::GetForumTopicIconStickers => "getForumTopicIconStickers",
Self::CreateForumTopic => "createForumTopic",
Self::EditForumTopic => "editForumTopic",
Self::CloseForumTopic => "closeForumTopic",
Self::ReopenForumTopic => "reopenForumTopic",
Self::DeleteForumTopic => "deleteForumTopic",
Self::UnpinAllForumTopicMessages => "unpinAllForumTopicMessages",
Self::AnswerCallbackQuery => "answerCallbackQuery",
Self::EditMessageText => "editMessageText",
Self::EditMessageCaption => "editMessageCaption",
Expand Down
3 changes: 3 additions & 0 deletions src/api/types/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ pub struct PromoteChatMember {
/// other administrator privilege.
#[serde(skip_serializing_if = "Option::is_none")]
pub can_manage_chat: Option<bool>,
/// If the user is allowed to create, rename, close, and reopen forum topics, supergroups only
#[serde(skip_serializing_if = "Option::is_none")]
pub can_manage_topics: Option<bool>,
}

/// struct for holding data needed to call
Expand Down
104 changes: 104 additions & 0 deletions src/api/types/forum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use crate::model::utils::IntegerOrString;
use serde::{Deserialize, Serialize};
use telexide_proc_macros::build_struct;

/// struct for holding data needed to call
/// [`create_forum_topic`]
///
/// [`create_forum_topic`]:
/// ../../api/trait.API.html#method.create_forum_topic
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct CreateForumTopic {
/// Unique identifier for the target chat or username of the target supergroup
pub chat_id: IntegerOrString,
/// Topic name, 1-128 characters
pub name: String,
/// Color of the topic icon in RGB format.
/// Currently, must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F.
#[serde(skip_serializing_if = "Option::is_none")]
pub icon_color: Option<i64>,
/// Unique identifier of the custom emoji shown as the topic icon.
/// Use [`get_forum_topic_icon_stickers`] to get all allowed custom emoji identifiers.
///
/// [`get_forum_topic_icon_stickers`]: ../../api/trait.API.html#method.get_forum_topic_icon_stickers
#[serde(skip_serializing_if = "Option::is_none")]
pub icon_custom_emoji_id: Option<String>,
}

/// struct for holding data needed to call
/// [`edit_forum_topic`]
///
/// [`edit_forum_topic`]:
/// ../../api/trait.API.html#method.edit_forum_topic
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct EditForumTopic {
/// Unique identifier for the target chat or username of the target supergroup
pub chat_id: IntegerOrString,
/// Unique identifier for the target message thread of the forum topic
pub message_thread_id: i64,
/// Topic name, 1-128 characters
pub name: String,
/// Unique identifier of the custom emoji shown as the topic icon.
/// Use [`get_forum_topic_icon_stickers`] to get all allowed custom emoji identifiers.
///
/// [`get_forum_topic_icon_stickers`]: ../../api/trait.API.html#method.get_forum_topic_icon_stickers
pub icon_custom_emoji_id: String,
}

/// struct for holding data needed to call
/// [`close_forum_topic`]
///
/// [`close_forum_topic`]:
/// ../../api/trait.API.html#method.close_forum_topic
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct CloseForumTopic {
/// Unique identifier for the target chat or username of the target supergroup
pub chat_id: IntegerOrString,
/// Unique identifier for the target message thread of the forum topic
pub message_thread_id: i64,
}

/// struct for holding data needed to call
/// [`reopen_forum_topic`]
///
/// [`reopen_forum_topic`]:
/// ../../api/trait.API.html#method.reopen_forum_topic
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ReopenForumTopic {
/// Unique identifier for the target chat or username of the target supergroup
pub chat_id: IntegerOrString,
/// Unique identifier for the target message thread of the forum topic
pub message_thread_id: i64,
}

/// struct for holding data needed to call
/// [`delete_forum_topic`]
///
/// [`delete_forum_topic`]:
/// ../../api/trait.API.html#method.delete_forum_topic
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct DeleteForumTopic {
/// Unique identifier for the target chat or username of the target supergroup
pub chat_id: IntegerOrString,
/// Unique identifier for the target message thread of the forum topic
pub message_thread_id: i64,
}

/// struct for holding data needed to call
/// [`unpin_all_forum_topic_messages`]
///
/// [`cunpin_all_forum_topic_messages`]:
/// ../../api/trait.API.html#method.unpin_all_forum_topic_messages
#[build_struct]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct UnpinAllForumTopicMessages {
/// Unique identifier for the target chat or username of the target supergroup
pub chat_id: IntegerOrString,
/// Unique identifier for the target message thread of the forum topic
pub message_thread_id: i64,
}
4 changes: 4 additions & 0 deletions src/api/types/games.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use telexide_proc_macros::build_struct;
pub struct SendGame {
/// Unique identifier for the target chat
pub chat_id: IntegerOrString,
/// Unique identifier for the target message thread (topic) of the forum;
/// for forum supergroups only
#[serde(skip_serializing_if = "Option::is_none")]
pub message_thread_id: Option<i64>,
/// Short name of the game, serves as the unique identifier for the game.
/// Set up your games via Botfather.
pub game_short_name: String,
Expand Down
2 changes: 2 additions & 0 deletions src/api/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
mod chat;
mod commands;
mod edit_messages;
mod forum;
mod games;
mod inline;
mod input_media;
Expand All @@ -18,6 +19,7 @@ mod webhooks;
pub use chat::*;
pub use commands::*;
pub use edit_messages::*;
pub use forum::*;
pub use games::*;
pub use inline::*;
pub use input_media::*;
Expand Down
4 changes: 4 additions & 0 deletions src/api/types/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use telexide_proc_macros::build_struct;
pub struct SendInvoice {
/// Unique identifier for the target private chat
pub chat_id: IntegerOrString,
/// Unique identifier for the target message thread (topic) of the forum;
/// for forum supergroups only
#[serde(skip_serializing_if = "Option::is_none")]
pub message_thread_id: Option<i64>,
/// Product name, 1-32 characters
pub title: String,
/// Product description, 1-255 characters
Expand Down
Loading

0 comments on commit 01ec59e

Please sign in to comment.