-
Notifications
You must be signed in to change notification settings - Fork 3
/
getting-updates.go
127 lines (102 loc) · 3.64 KB
/
getting-updates.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
package telegram
import "context"
// Update struct.
type Update struct {
UpdateID int `json:"update_id"`
Message *Message `json:"message,omitempty"`
EditedMessage *Message `json:"edited_message,omitempty"`
ChannelPost *Message `json:"channel_post,omitempty"`
EditedChannelPost *Message `json:"edited_channel_post,omitempty"`
InlineQuery *InlineQuery `json:"inline_query,omitempty"`
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
CallbackQuery *CallbackQuery `json:"callback_query,omitempty"`
ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"`
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
Poll *Poll `json:"poll,omitempty"`
PollAnswer *PollAnswer `json:"poll_answer"`
MyChatMember *ChatMemberUpdated `json:"my_chat_member,omitempty"`
ChatMember *ChatMemberUpdated `json:"chat_member,omitempty"`
ChatJoinRequest *ChatJoinRequest `json:"chat_join_request,omitempty"`
}
// GetUpdatesResponse interface.
type GetUpdatesResponse interface {
Response
GetUpdates() []Update
}
type getUpdatesResponse struct {
response
Result []Update `json:"result,omitempty"`
}
func (r *getUpdatesResponse) GetUpdates() []Update {
return r.Result
}
func (b *bot) GetUpdates(ctx context.Context, options ...MethodOption) (GetUpdatesResponse, error) {
var res getUpdatesResponse
err := b.doRequest(ctx, "getUpdates", &res, options...)
if err != nil {
return nil, err
}
return &res, nil
}
// SetWebhookResponse interface.
type SetWebhookResponse interface {
Response
}
type setWebhookResponse struct {
response
}
func (b *bot) SetWebhook(ctx context.Context, options ...MethodOption) (SetWebhookResponse, error) {
var res setWebhookResponse
err := b.doRequest(ctx, "setWebhook", &res, options...)
if err != nil {
return nil, err
}
return &res, nil
}
// DeleteWebhookResponse interface.
type DeleteWebhookResponse interface {
Response
}
type deleteWebhookResponse struct {
response
}
func (b *bot) DeleteWebhook(ctx context.Context) (DeleteWebhookResponse, error) {
var res deleteWebhookResponse
err := b.doRequest(ctx, "deleteWebhook", &res)
if err != nil {
return nil, err
}
return &res, nil
}
// GetWebhookInfoResponse interface.
type GetWebhookInfoResponse interface {
Response
GetWebhookInfo() *WebhookInfo
}
type getWebhookInfoResponse struct {
response
Result *WebhookInfo `json:"result,omitempty"`
}
func (r *getWebhookInfoResponse) GetWebhookInfo() *WebhookInfo {
return r.Result
}
func (b *bot) GetWebhookInfo(ctx context.Context) (GetWebhookInfoResponse, error) {
var res getWebhookInfoResponse
err := b.doRequest(ctx, "getWebhookInfo", &res)
if err != nil {
return nil, err
}
return &res, nil
}
// WebhookInfo struct.
type WebhookInfo struct {
URL string `json:"url"`
HasCustomCertificate bool `json:"has_custom_certificate"`
PendingUpdateCount int `json:"pending_update_count"`
IPAddress *string `json:"ip_address,omitempty"`
LastErrorDate *int `json:"last_error_date,omitempty"`
LastErrorMessage *string `json:"last_error_message,omitempty"`
LastSynchronizationError *int `json:"last_synchronization_error_date,omitempty"` // Optional. Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters
MaxConnections *int `json:"max_connections,omitempty"`
AllowedUpdates []string `json:"allowed_updates,omitempty"`
}