Skip to main content

tgbot/types/definitions/inline_mode/
guest.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api::{Method, Payload},
5    types::InlineQueryResult,
6};
7
8/// An inline message sent by a guest bot.
9#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
10pub struct SentGuestMessage {
11    /// Identifier of the sent inline message
12    pub inline_message_id: String,
13}
14
15impl From<&str> for SentGuestMessage {
16    fn from(value: &str) -> Self {
17        Self {
18            inline_message_id: String::from(value),
19        }
20    }
21}
22
23impl From<String> for SentGuestMessage {
24    fn from(value: String) -> Self {
25        Self {
26            inline_message_id: value,
27        }
28    }
29}
30
31impl From<SentGuestMessage> for String {
32    fn from(value: SentGuestMessage) -> Self {
33        value.inline_message_id
34    }
35}
36
37/// Reply to a received guest message.
38#[derive(Clone, Debug, Serialize)]
39pub struct AnswerGuestQuery {
40    guest_query_id: String,
41    result: InlineQueryResult,
42}
43
44impl AnswerGuestQuery {
45    /// Creates a new `AnswerGuestQuery`.
46    ///
47    /// # Arguments
48    ///
49    /// * `guest_query_id` - Unique identifier for the query to be answered.
50    /// * `result` - The message to be sent.
51    pub fn new<A, B>(guest_query_id: A, result: B) -> Self
52    where
53        A: Into<String>,
54        B: Into<InlineQueryResult>,
55    {
56        Self {
57            guest_query_id: guest_query_id.into(),
58            result: result.into(),
59        }
60    }
61}
62
63impl Method for AnswerGuestQuery {
64    type Response = SentGuestMessage;
65
66    fn into_payload(self) -> Payload {
67        Payload::json("answerGuestQuery", self)
68    }
69}