1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use super::base::{Request, TelegramMethod};

use crate::{
    client::Bot,
    types::{InlineQueryResult, SentWebAppMessage},
};

use serde::Serialize;

/// Use this method to set the result of an interaction with a [`Web App`](https://core.telegram.org/bots/webapps) and send a corresponding message on behalf of the user to the chat from which the query originated.
/// # Documentation
/// <https://core.telegram.org/bots/api#answerwebappquery>
/// # Returns
/// On success, a [`SentWebAppMessage`] object is returned
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct AnswerWebAppQuery {
    /// Unique identifier for the query to be answered
    pub web_app_query_id: String,
    /// A JSON-serialized object describing the message to be sent
    pub result: InlineQueryResult,
}

impl AnswerWebAppQuery {
    #[must_use]
    pub fn new(web_app_query_id: impl Into<String>, result: impl Into<InlineQueryResult>) -> Self {
        Self {
            web_app_query_id: web_app_query_id.into(),
            result: result.into(),
        }
    }

    #[must_use]
    pub fn web_app_query_id(self, val: impl Into<String>) -> Self {
        Self {
            web_app_query_id: val.into(),
            ..self
        }
    }

    #[must_use]
    pub fn result(self, val: impl Into<InlineQueryResult>) -> Self {
        Self {
            result: val.into(),
            ..self
        }
    }
}

impl TelegramMethod for AnswerWebAppQuery {
    type Method = Self;
    type Return = SentWebAppMessage;

    fn build_request<Client>(&self, _bot: &Bot<Client>) -> Request<Self::Method> {
        Request::new("answerWebAppQuery", self, None)
    }
}

impl AsRef<AnswerWebAppQuery> for AnswerWebAppQuery {
    fn as_ref(&self) -> &Self {
        self
    }
}