init_data_rs/model.rs
1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4#[serde(rename_all = "lowercase")]
5pub enum ChatType {
6 Sender,
7 Private,
8 Group,
9 Supergroup,
10 Channel,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct User {
15 pub added_to_attachment_menu: Option<bool>,
16 pub allows_write_to_pm: Option<bool>,
17 pub first_name: String,
18 pub id: i64,
19 pub is_bot: Option<bool>,
20 pub is_premium: Option<bool>,
21 pub last_name: Option<String>,
22 pub language_code: Option<String>,
23 pub photo_url: Option<String>,
24 pub username: Option<String>,
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct Chat {
29 pub id: i64,
30 pub photo_url: Option<String>,
31 #[serde(rename = "type")]
32 pub chat_type: ChatType,
33 pub title: String,
34 pub username: Option<String>,
35}
36
37/// This object contains data that is transferred to the Mini App when it is opened. It is empty if the Mini App was launched from a keyboard button or from inline mode.
38/// See: <https://core.telegram.org/bots/webapps#webappinitdata>
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct InitData {
41 /// Unix time when the form was opened.
42 pub auth_date: u64,
43 /// Optional.
44 /// Time in seconds, after which a message can be sent via the answerWebAppQuery method.
45 pub can_send_after: Option<u32>,
46 /// Optional.
47 /// An object containing data about the chat where the bot was launched via the attachment menu. Returned for supergroups, channels and group chats – only for Mini Apps launched via the attachment menu.
48 pub chat: Option<Chat>,
49 /// Optional.
50 /// Type of the chat from which the Mini App was opened. Can be either “sender” for a private chat with the user opening the link, “private”, “group”, “supergroup”, or “channel”. Returned only for Mini Apps launched from direct links.
51 pub chat_type: Option<ChatType>,
52 /// Optional.
53 /// Global identifier, uniquely corresponding to the chat from which the Mini App was opened. Returned only for Mini Apps launched from a direct link.
54 pub chat_instance: Option<i64>,
55 /// A hash of all passed parameters, which the bot server can use to check their validity.
56 pub hash: String,
57 /// Optional.
58 /// A unique identifier for the Mini App session, required for sending messages via the answerWebAppQuery method.
59 pub query_id: Option<String>,
60 /// Optional.
61 /// An object containing data about the chat partner of the current user in the chat where the bot was launched via the attachment menu. Returned only for private chats and only for Mini Apps launched via the attachment menu.
62 pub receiver: Option<User>,
63 /// Optional.
64 /// The value of the startattach parameter, passed via link. Only returned for Mini Apps when launched from the attachment menu via link.
65 /// The value of the `start_param` parameter will also be passed in the GET-parameter tgWebAppStartParam, so the Mini App can load the correct interface right away.
66 pub start_param: Option<String>,
67 /// Optional. An object containing data about the current user.
68 pub user: Option<User>,
69 /// A signature of all passed parameters (except hash), which the third party can use to check their validity.
70 /// This field is only for third-party validation, shall be optional?
71 pub signature: Option<String>,
72}