Add support for launching Web Apps from inline query results

This commit is contained in:
Сырцев Вадим Игоревич 2024-06-15 15:01:15 +03:00
parent b7e2f25562
commit 693b5c08e5
3 changed files with 52 additions and 15 deletions

View file

@ -3123,21 +3123,10 @@ Schema(
descr: Doc(md: "Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don't support pagination. Offset length can't exceed 64 bytes.")
),
Param(
name: "switch_pm_text",
ty: Option(String),
descr: Doc(md: "If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter")
),
Param(
name: "switch_pm_parameter",
ty: Option(String),
descr: Doc(
md: "[Deep-linking] parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only `A-Z`, `a-z`, `0-9`, `_` and `-` are allowed.\n\n_Example_: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a 'Connect your YouTube account' button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link. Once done, the bot can offer a [switch_inline] button so that the user can easily return to the chat where they wanted to use the bot's inline capabilities.",
md_links: {
"Deep-linking": "https://core.telegram.org/bots#deep-linking",
"switch_inline": "https://core.telegram.org/bots/api#inlinekeyboardmarkup",
},
),
),
name: "button",
ty: Option(RawTy("InlineQueryResultsButton")),
descr: Doc(md: "A JSON-serialized object describing a button to be shown above inline query results")
)
],
),
Method(

View file

@ -64,6 +64,7 @@ pub use inline_query_result_photo::*;
pub use inline_query_result_venue::*;
pub use inline_query_result_video::*;
pub use inline_query_result_voice::*;
pub use inline_query_results_button::*;
pub use input_file::*;
pub use input_media::*;
pub use input_message_content::*;
@ -166,6 +167,7 @@ mod general_forum_topic_hidden;
mod general_forum_topic_unhidden;
mod inline_keyboard_button;
mod inline_keyboard_markup;
mod inline_query_results_button;
mod input_file;
mod input_media;
mod input_message_content;

View file

@ -0,0 +1,46 @@
use serde::{Deserialize, Serialize};
use crate::types::WebAppInfo;
/// This object represents a button to be shown above inline query results. You
/// must use exactly one of the optional fields.
///
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultsbutton)
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct InlineQueryResultsButton {
/// Label text on the button
pub text: String,
#[serde(flatten)]
pub kind: InlineQueryResultsButtonKind,
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub enum InlineQueryResultsButtonKind {
/// Description of the [Web App] that will be launched when the user presses
/// the button. The Web App will be able to switch back to the inline mode
/// using the method [switchInlineQuery] inside the Web App.
///
/// [Web App]: https://core.telegram.org/bots/webapps
/// [switchInlineQuery]: https://core.telegram.org/bots/webapps#initializing-mini-apps
WebApp(WebAppInfo),
/// [Deep-linking] parameter for the /start message sent to the bot when a
/// user presses the button. 1-64 characters, only `A-Z`, `a-z`, `0-9`, `_`
/// and `-` are allowed.
///
/// Example: An inline bot that sends YouTube videos can
/// ask the user to connect the bot to their YouTube account to adapt search
/// results accordingly. To do this, it displays a 'Connect your YouTube
/// account' button above the results, or even before showing any. The user
/// presses the button, switches to a private chat with the bot and, in
/// doing so, passes a start parameter that instructs the bot to return an
/// OAuth link. Once done, the bot can offer a [switch_inline] button so
/// that the user can easily return to the chat where they wanted to use
/// the bot's inline capabilities.
///
/// [Deep-linking]: https://core.telegram.org/bots/features#deep-linking
/// [switch_inline]: https://core.telegram.org/bots/api#inlinekeyboardmarkup
StartParameter(String),
}