-
Notifications
You must be signed in to change notification settings - Fork 30
/
types.go
200 lines (155 loc) · 4.35 KB
/
types.go
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package botgolang
//go:generate easyjson -all types.go
type EventType string
type PartType string
const (
NEW_MESSAGE EventType = "newMessage"
EDITED_MESSAGE EventType = "editedMessage"
DELETED_MESSAGE EventType = "deletedMessage"
PINNED_MESSAGE EventType = "pinnedMessage"
UNPINNED_MESSAGE EventType = "unpinnedMessage"
NEW_CHAT_MEMBERS EventType = "newChatMembers"
LEFT_CHAT_MEMBERS EventType = "leftChatMembers"
CALLBACK_QUERY EventType = "callbackQuery"
STICKER PartType = "sticker"
MENTION PartType = "mention"
VOICE PartType = "voice"
FILE PartType = "file"
FORWARD PartType = "forward"
REPLY PartType = "reply"
)
type Response struct {
OK bool `json:"ok"`
Description string `json:"description,omitempty"`
}
type Photo struct {
URL string `json:"url"`
}
type BotInfo struct {
User
// Nickname of the bot
Nick string `json:"nick"`
// Name of the bot
FirstName string `json:"firstName"`
// Information about the box
About string `json:"about"`
// A slice of avatars
Photo []Photo `json:"photo"`
}
type eventsResponse struct {
OK bool `json:"ok"`
Events []*Event `json:"events"`
}
type User struct {
ID string `json:"userId"`
}
type ChatMember struct {
User
Creator bool `json:"creator"`
Admin bool `json:"admin"`
}
type UsersListResponse struct {
List []User `json:"users"`
}
type MembersListResponse struct {
// TODO: cursor
List []ChatMember `json:"members"`
}
type AdminsListResponse struct {
List []ChatMember `json:"admins"`
}
type Contact struct {
User
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}
type BaseEventPayload struct {
// Id of the message.
// Presented in newMessage, editedMessage, deletedMessage, pinnedMessage, unpinnedMessage events.
MsgID string `json:"msgId"`
// Chat info.
// Presented in all events.
Chat Chat `json:"chat"`
// Author of the message
// Presented in newMessage and editedMessage events.
From Contact `json:"from"`
// Text of the message.
// Presented in newMessage, editedMessage and pinnedMessage events.
Text string `json:"text"`
// Timestamp of the event.
Timestamp int `json:"timestamp"`
}
type EventPayload struct {
client *Client
BaseEventPayload
// Parts of the message.
// Presented only in newMessage event.
Parts []Part `json:"parts"`
// Id of the query.
// Presented only in callbackQuery event.
QueryID string `json:"queryId"`
// Callback message of the query (parent message for button).
// Presented only in callbackQuery event.
CallbackMsg BaseEventPayload `json:"message"`
// CallbackData of the query (id of button).
// Presented only in callbackQuery event.
CallbackData string `json:"callbackData"`
LeftMembers []Contact `json:"leftMembers"`
NewMembers []Contact `json:"newMembers"`
AddedBy Contact `json:"addedBy"`
RemovedBy Contact `json:"removedBy"`
}
func (ep *EventPayload) Message() *Message {
return message(ep.client, ep.BaseEventPayload)
}
func (ep *EventPayload) CallbackMessage() *Message {
return message(ep.client, ep.CallbackMsg)
}
func message(client *Client, msg BaseEventPayload) *Message {
msg.Chat.client = client
return &Message{
client: client,
ID: msg.MsgID,
Text: msg.Text,
Chat: msg.Chat,
Timestamp: msg.Timestamp,
}
}
type PartMessage struct {
From Contact `json:"from"`
MsgID string `json:"msgId"`
Text string `json:"text"`
Timestamp int `json:"timestamp"`
}
type PartPayload struct {
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
UserID string `json:"userId"`
FileID string `json:"fileId"`
Caption string `json:"caption"`
Type string `json:"type"`
PartMessage PartMessage `json:"message"`
Message PartMessage `json:"-"`
}
type Event struct {
client *Client
// Id of the event
EventID int `json:"eventId"`
// Type of the event: newMessage, editedMessage, deletedMessage, pinnedMessage, unpinnedMessage, newChatMembers
Type EventType `json:"type"`
// Payload of the event
Payload EventPayload `json:"payload"`
}
type Part struct {
// Type of the part
Type PartType `json:"type"`
// Payload of the part
Payload PartPayload `json:"payload"`
}
func (ep *EventPayload) CallbackQuery() *ButtonResponse {
return &ButtonResponse{
client: ep.client,
QueryID: ep.QueryID,
CallbackData: ep.CallbackData,
}
}