-
Notifications
You must be signed in to change notification settings - Fork 68
/
options.go
132 lines (112 loc) · 3.45 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
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
package bot
import (
"time"
"github.com/go-telegram/bot/models"
)
// Option is a function that configures a bot.
type Option func(b *Bot)
// WithCheckInitTimeout allows to redefine CheckInitTimeout
func WithCheckInitTimeout(timeout time.Duration) Option {
return func(b *Bot) {
b.checkInitTimeout = timeout
}
}
// WithMiddlewares allows to set middlewares for each incoming request
func WithMiddlewares(middlewares ...Middleware) Option {
return func(b *Bot) {
b.middlewares = append(b.middlewares, middlewares...)
}
}
// WithMessageTextHandler allows to set handler for incoming text messages
// Also you can use *bot.RegisterHandler function after bot creation
func WithMessageTextHandler(pattern string, matchType MatchType, handler HandlerFunc) Option {
return func(b *Bot) {
b.RegisterHandler(HandlerTypeMessageText, pattern, matchType, handler)
}
}
// WithCallbackQueryDataHandler allows to set handler for incoming callback query
// Also you can use *bot.RegisterHandler function after bot creation
func WithCallbackQueryDataHandler(pattern string, matchType MatchType, handler HandlerFunc) Option {
return func(b *Bot) {
b.RegisterHandler(HandlerTypeCallbackQueryData, pattern, matchType, handler)
}
}
// WithDefaultHandler allows to set default handler for incoming updates
func WithDefaultHandler(handler HandlerFunc) Option {
return func(b *Bot) {
b.defaultHandlerFunc = handler
}
}
// WithDebug allows to enable debug mode. In debug mode, all requests and responses are logged by debug handler
func WithDebug() Option {
return func(b *Bot) {
b.isDebug = true
}
}
// WithErrorsHandler allows to set handler for errors
func WithErrorsHandler(handler ErrorsHandler) Option {
return func(b *Bot) {
b.errorsHandler = handler
}
}
// WithDebugHandler allows to set handler for debug messages
func WithDebugHandler(handler DebugHandler) Option {
return func(b *Bot) {
b.debugHandler = handler
}
}
// WithHTTPClient allows to set custom http client
func WithHTTPClient(pollTimeout time.Duration, client HttpClient) Option {
return func(b *Bot) {
b.pollTimeout = pollTimeout
b.client = client
}
}
// WithServerURL allows to set custom server url
func WithServerURL(serverURL string) Option {
return func(b *Bot) {
b.url = serverURL
}
}
// WithSkipGetMe allows skip call GetMe on bot init
func WithSkipGetMe() Option {
return func(b *Bot) {
b.skipGetMe = true
}
}
// WithAllowedUpdates allows to set custom params for getUpdates method
func WithAllowedUpdates(params AllowedUpdates) Option {
return func(b *Bot) {
b.allowedUpdates = params
}
}
// WithUpdatesChannelCap allows setting custom capacity for the Updates channel
func WithUpdatesChannelCap(cap int) Option {
return func(b *Bot) {
b.updates = make(chan *models.Update, cap)
}
}
// WithWebhookSecretToken allows setting X-Telegram-Bot-Api-Secret-Token sent from Telegram servers
func WithWebhookSecretToken(webhookSecretToken string) Option {
return func(b *Bot) {
b.webhookSecretToken = webhookSecretToken
}
}
// WithWorkers allows setting the number of workers that are processing the Updates channel
func WithWorkers(workers int) Option {
return func(b *Bot) {
b.workers = workers
}
}
// UseTestEnvironment allows to use test environment
func UseTestEnvironment() Option {
return func(b *Bot) {
b.testEnvironment = true
}
}
// WithNotAsyncHandlers allows to run handlers in the main goroutine
func WithNotAsyncHandlers() Option {
return func(b *Bot) {
b.notAsyncHandlers = true
}
}