This repository has been archived by the owner on Aug 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
87 lines (76 loc) · 2.61 KB
/
options.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
package telegram
import (
"encoding/json"
httpf "github.com/jfk9w-go/flu/httpf"
"github.com/jfk9w-go/flu"
"github.com/pkg/errors"
)
// GetUpdatesOptions is /getUpdates request options.
// See https://core.telegram.org/bots/api#getupdates
type GetUpdatesOptions struct {
// Identifier of the first update to be returned.
// Must be greater by one than the highest among the identifiers of previously received updates.
// By default, updates starting with the earliest unconfirmed update are returned.
// An update is considered confirmed as soon as getUpdates is called with an offset
// higher than its update_id. The negative offset can be specified to retrieve updates
// starting from -offset update from the end of the updates queue.
// All previous updates will be forgotten.
Offset ID `json:"offset,omitempty"`
// Limits the number of updates to be retrieved.
// Values between 1—100 are accepted. Defaults to 100.
Limit int `json:"limit,omitempty"`
// Timeout for long polling.
TimeoutSecs int `json:"timeout,omitempty"`
// List the types of updates you want your bot to receive.
AllowedUpdates []string `json:"allowed_updates,omitempty"`
}
type SendOptions struct {
DisableNotification bool
ReplyToMessageID ID
ReplyMarkup ReplyMarkup
}
func (o *SendOptions) body(chatID ChatID, item sendable) (flu.EncoderTo, error) {
mediaGroup := item.kind() == "mediaGroup"
var form *httpf.Form
if !mediaGroup {
form = httpf.FormValue(item)
} else {
form = new(httpf.Form)
}
form = form.Set("chat_id", chatID.queryParam())
if o != nil {
if o.DisableNotification {
form = form.Set("disable_notification", "1")
}
if o.ReplyToMessageID != 0 {
form = form.Set("reply_to_message_id", o.ReplyToMessageID.queryParam())
}
if !mediaGroup && o.ReplyMarkup != nil {
bytes, err := json.Marshal(o.ReplyMarkup)
if err != nil {
return nil, errors.Wrap(err, "serialize reply_markup")
}
form = form.Set("reply_markup", string(bytes))
}
}
return item.body(form)
}
type CopyOptions struct {
*SendOptions
Caption string `url:"caption,omitempty"`
ParseMode ParseMode `url:"parse_mode,omitempty"`
}
func (o *CopyOptions) body(chatID ChatID, ref MessageRef) (flu.EncoderTo, error) {
form := httpf.FormValue(o)
form.Set("chat_id", chatID.queryParam())
return ref.body(form)
}
type AnswerOptions struct {
Text string `url:"text,omitempty"`
ShowAlert bool `url:"show_alert,omitempty"`
URL string `url:"url,omitempty"`
CacheTime int `url:"cache_time,omitempty"`
}
func (o *AnswerOptions) body(id string) flu.EncoderTo {
return httpf.FormValue(o).Set("callback_query_id", id)
}