-
Notifications
You must be signed in to change notification settings - Fork 2
/
structs.go
74 lines (63 loc) · 2.53 KB
/
structs.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
package bots
import (
"errors"
"strings"
)
// ErrIgnoredItem is returned when the story should be ignored.
var ErrIgnoredItem = errors.New("item ignored")
// SendMessageRequest is a struct that maps to a sendMessage request.
type SendMessageRequest struct {
ChatID string `json:"chat_id"`
Text string `json:"text"`
ParseMode string `json:"parse_mode,omitempty"`
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup,omitempty"`
DisableNotification bool `json:"disable_notification,omitempty"`
}
// InlineKeyboardMarkup type.
type InlineKeyboardMarkup struct {
InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard,omitempty"`
}
// InlineKeyboardButton type.
type InlineKeyboardButton struct {
Text string `json:"text,omitempty"`
URL string `json:"url,omitempty"`
}
// SendMessageResponse is the response from sendMessage request.
type SendMessageResponse struct {
OK bool `json:"ok"`
Result Result `json:"result"`
}
// Result is a submessage in SendMessageResponse. We only care the MessageID for now.
type Result struct {
MessageID int64 `json:"message_id"`
}
// EditMessageTextRequest is the request to editMessageText method.
type EditMessageTextRequest struct {
ChatID string `json:"chat_id"`
MessageID int64 `json:"message_id"`
Text string `json:"text"`
ParseMode string `json:"parse_mode,omitempty"`
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// DeleteMessageRequest is the request to deleteMessage method.
type DeleteMessageRequest struct {
ChatID string `json:"chat_id"`
MessageID int64 `json:"message_id"`
}
// DeleteMessageResponse is the response to deleteMessage method.
type DeleteMessageResponse struct {
OK bool `json:"ok"`
ErrorCode int64 `json:"error_code"`
Description string `json:"description"`
}
// ShouldIgnoreError return true if the message contains an error but should be ignored.
func (r *DeleteMessageResponse) ShouldIgnoreError() bool {
return (r.ErrorCode == 400 &&
// Someone manually deleted the message from the channel
(strings.Contains(r.Description, "message to delete not found") ||
// Story was on top 30 list for > 24 hours but Telegram API only allow
// deleting messages that were posted in <48 hours.
// It should be fine to just ignore this error, and leave these stories in
// channel forever.
strings.Contains(r.Description, "message can't be deleted")))
}