Skip to main content

botrs/interaction/
types.rs

1use serde::{Deserialize, Deserializer, Serialize, Serializer};
2
3/// Interaction type enumeration
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[repr(u8)]
6pub enum InteractionType {
7    /// Ping interaction
8    Ping = 1,
9    /// Application command interaction
10    ApplicationCommand = 2,
11    /// HTTP proxy interaction
12    HttpProxy = 10,
13    /// Inline keyboard interaction
14    InlineKeyboard = 11,
15}
16
17wire_enum_with_default!(InteractionType, u8, Ping, {
18    Ping = 1,
19    ApplicationCommand = 2,
20    HttpProxy = 10,
21    InlineKeyboard = 11,
22});
23
24impl Serialize for InteractionType {
25    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
26    where
27        S: Serializer,
28    {
29        serializer.serialize_u8(*self as u8)
30    }
31}
32
33impl<'de> Deserialize<'de> for InteractionType {
34    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
35    where
36        D: Deserializer<'de>,
37    {
38        Ok(Self::from(u8::deserialize(deserializer)?))
39    }
40}
41
42/// Interaction data type enumeration
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44#[repr(u8)]
45pub enum InteractionDataType {
46    /// Chat input search
47    ChatInputSearch = 9,
48    /// HTTP proxy
49    HttpProxy = 10,
50    /// Inline keyboard button click
51    InlineKeyboardButtonClick = 11,
52    /// C2C callback command click
53    CallbackCommandClick = 12,
54    /// Message feedback click
55    MessageFeedbackClick = 13,
56    /// Clear session click
57    ClearSessionClick = 14,
58}
59
60wire_enum_with_default!(InteractionDataType, u8, ChatInputSearch, {
61    ChatInputSearch = 9,
62    HttpProxy = 10,
63    InlineKeyboardButtonClick = 11,
64    CallbackCommandClick = 12,
65    MessageFeedbackClick = 13,
66    ClearSessionClick = 14,
67});
68
69impl Serialize for InteractionDataType {
70    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
71    where
72        S: Serializer,
73    {
74        serializer.serialize_u8(*self as u8)
75    }
76}
77
78impl<'de> Deserialize<'de> for InteractionDataType {
79    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
80    where
81        D: Deserializer<'de>,
82    {
83        Ok(Self::from(u8::deserialize(deserializer)?))
84    }
85}