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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use rvk::objects::Integer;
use serde_derive::Deserialize;
use serde_json::Value;
use std::collections::HashMap;
#[derive(Debug, Deserialize)]
pub struct CallbackAPIRequest {
secret: String,
group_id: i32,
#[serde(rename = "type")]
r#type: String,
#[serde(default)]
object: Object,
}
impl CallbackAPIRequest {
pub fn new(secret: &str, group_id: i32, r#type: &str, object: Object) -> Self {
Self {
secret: secret.into(),
group_id,
r#type: r#type.into(),
object,
}
}
pub fn secret(&self) -> &str {
&self.secret
}
pub fn group_id(&self) -> i32 {
self.group_id
}
pub fn r#type(&self) -> &str {
&self.r#type
}
pub fn object(&self) -> &Object {
&self.object
}
}
#[derive(Debug, Deserialize, Clone)]
pub struct Object {
from_id: Option<Integer>,
peer_id: Option<Integer>,
user_id: Option<Integer>,
text: Option<String>,
payload: Option<String>,
action: Option<Value>,
#[serde(flatten)]
extra: HashMap<String, Value>,
}
impl Default for Object {
fn default() -> Self {
Self {
from_id: None,
peer_id: None,
user_id: None,
text: None,
payload: None,
action: None,
extra: Default::default(),
}
}
}
impl Object {
pub fn new(
from_id: Option<Integer>,
peer_id: Option<Integer>,
user_id: Option<Integer>,
text: Option<String>,
payload: Option<String>,
action: Option<Value>,
extra: HashMap<String, Value>,
) -> Self {
Self {
from_id,
peer_id,
user_id,
text,
payload,
action,
extra,
}
}
pub fn get_from_id(&self) -> &Option<Integer> {
&self.from_id
}
pub fn peer_id(&self) -> &Option<Integer> {
&self.peer_id
}
pub fn user_id(&self) -> &Option<Integer> {
&self.user_id
}
pub fn text(&self) -> &Option<String> {
&self.text
}
pub fn payload(&self) -> &Option<String> {
&self.payload
}
pub fn action(&self) -> &Option<Value> {
&self.action
}
pub fn extra(&self) -> &HashMap<String, Value> {
&self.extra
}
}