-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.go
49 lines (43 loc) · 1.04 KB
/
hook.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
package telebot
import (
"encoding/json"
"net/http"
)
// IHook is a provider of Webhook.
type IHook interface {
GetFiles() map[string]File
GetParams() map[string]string
WaitForStop(stop chan struct{})
Handler(w http.ResponseWriter, r *http.Request)
}
// Webhook returns the current webhook status.
func (b *Bot) Webhook() (*IHook, error) {
data, err := b.Raw("getWebhookInfo", nil)
if err != nil {
return nil, err
}
var resp struct {
Result IHook
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp.Result, nil
}
// SetWebhook configures a bot to receive incoming
// updates via an outgoing webhook.
func (b *Bot) SetWebhook(w IHook) error {
_, err := b.sendFiles("setWebhook", w.GetFiles(), w.GetParams())
return err
}
// RemoveWebhook removes webhook integration.
func (b *Bot) RemoveWebhook(dropPending ...bool) error {
drop := false
if len(dropPending) > 0 {
drop = dropPending[0]
}
_, err := b.Raw("deleteWebhook", map[string]bool{
"drop_pending_updates": drop,
})
return err
}