Skip to main content

rust_tg_bot_raw/bot/
stories.rs

1use super::{push_opt, push_opt_str, Bot, Result};
2use crate::request::request_parameter::RequestParameter;
3use crate::types::{message_entity, story};
4
5#[allow(dead_code)]
6impl Bot {
7    // ======================================================================
8    // Stories
9    // ======================================================================
10
11    /// Use this method to post a story on behalf of a managed business account.
12    ///
13    /// Calls the Telegram `postStory` API method.
14    pub async fn post_story_raw(
15        &self,
16        business_connection_id: &str,
17        content: serde_json::Value,
18        active_period: i64,
19        caption: Option<&str>,
20        parse_mode: Option<&str>,
21        caption_entities: Option<Vec<message_entity::MessageEntity>>,
22        areas: Option<Vec<serde_json::Value>>,
23        post_to_chat_page: Option<bool>,
24        protect_content: Option<bool>,
25    ) -> Result<story::Story> {
26        let mut params = vec![
27            RequestParameter::new(
28                "business_connection_id",
29                serde_json::Value::String(business_connection_id.to_owned()),
30            ),
31            RequestParameter::new("content", content),
32            RequestParameter::new("active_period", serde_json::to_value(active_period)?),
33        ];
34        push_opt_str(&mut params, "caption", caption);
35        push_opt_str(&mut params, "parse_mode", parse_mode);
36        push_opt(&mut params, "caption_entities", &caption_entities)?;
37        push_opt(&mut params, "areas", &areas)?;
38        push_opt(&mut params, "post_to_chat_page", &post_to_chat_page)?;
39        push_opt(&mut params, "protect_content", &protect_content)?;
40        self.do_post("postStory", params).await
41    }
42
43    /// Use this method to edit a story posted on behalf of a managed business account.
44    ///
45    /// Calls the Telegram `editStory` API method.
46    pub async fn edit_story_raw(
47        &self,
48        business_connection_id: &str,
49        story_id: i64,
50        content: serde_json::Value,
51        caption: Option<&str>,
52        parse_mode: Option<&str>,
53        caption_entities: Option<Vec<message_entity::MessageEntity>>,
54        areas: Option<Vec<serde_json::Value>>,
55    ) -> Result<story::Story> {
56        let mut params = vec![
57            RequestParameter::new(
58                "business_connection_id",
59                serde_json::Value::String(business_connection_id.to_owned()),
60            ),
61            RequestParameter::new("story_id", serde_json::to_value(story_id)?),
62            RequestParameter::new("content", content),
63        ];
64        push_opt_str(&mut params, "caption", caption);
65        push_opt_str(&mut params, "parse_mode", parse_mode);
66        push_opt(&mut params, "caption_entities", &caption_entities)?;
67        push_opt(&mut params, "areas", &areas)?;
68        self.do_post("editStory", params).await
69    }
70
71    /// Use this method to delete a story posted on behalf of a managed business account.
72    ///
73    /// Calls the Telegram `deleteStory` API method.
74    pub async fn delete_story_raw(
75        &self,
76        business_connection_id: &str,
77        story_id: i64,
78    ) -> Result<bool> {
79        let params = vec![
80            RequestParameter::new(
81                "business_connection_id",
82                serde_json::Value::String(business_connection_id.to_owned()),
83            ),
84            RequestParameter::new("story_id", serde_json::to_value(story_id)?),
85        ];
86        self.do_post("deleteStory", params).await
87    }
88
89    /// Use this method to repost a story on behalf of a managed business account.
90    ///
91    /// Calls the Telegram `repostStory` API method.
92    pub async fn repost_story_raw(
93        &self,
94        business_connection_id: &str,
95        from_chat_id: i64,
96        from_story_id: i64,
97        active_period: i64,
98        post_to_chat_page: Option<bool>,
99        protect_content: Option<bool>,
100    ) -> Result<story::Story> {
101        let mut params = vec![
102            RequestParameter::new(
103                "business_connection_id",
104                serde_json::Value::String(business_connection_id.to_owned()),
105            ),
106            RequestParameter::new("from_chat_id", serde_json::to_value(from_chat_id)?),
107            RequestParameter::new("from_story_id", serde_json::to_value(from_story_id)?),
108            RequestParameter::new("active_period", serde_json::to_value(active_period)?),
109        ];
110        push_opt(&mut params, "post_to_chat_page", &post_to_chat_page)?;
111        push_opt(&mut params, "protect_content", &protect_content)?;
112        self.do_post("repostStory", params).await
113    }
114}