-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback_handler.go
60 lines (50 loc) · 1.44 KB
/
callback_handler.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
package miyanbor
import (
"regexp"
"github.com/pkg/errors"
)
func (b *Bot) SetSessionStartCallbackHandler(function CallbackFunction) {
sessionStartCallbackFunction = function
}
func (b *Bot) SetFallbackCallbackHandler(function CallbackFunction) {
fallbackCallbackFunction = function
}
func (b *Bot) AddCallbackHandler(callbackQueryPattern string, function CallbackFunction) error {
// Compile pattern
regexPattern, err := regexp.Compile(callbackQueryPattern)
if err != nil {
return errors.Wrap(err, "can't compile pattern")
}
// Add to callbacks list
callbackQueryCallbacks = append(callbackQueryCallbacks, callback{
Pattern: regexPattern,
Function: function,
})
return nil
}
func (b *Bot) AddCommandHandler(commandPattern string, function CallbackFunction) error {
// Compile pattern
regexPattern, err := regexp.Compile(commandPattern)
if err != nil {
return errors.Wrap(err, "can't compile pattern")
}
// Add to callbacks list
commandsCallbacks = append(commandsCallbacks, callback{
Pattern: regexPattern,
Function: function,
})
return nil
}
func (b *Bot) AddMessageHandler(messagePattern string, function CallbackFunction) error {
// Compile pattern
regexPattern, err := regexp.Compile(messagePattern)
if err != nil {
return errors.Wrap(err, "can't compile pattern")
}
// Add to callbacks list
messagesCallbacks = append(messagesCallbacks, callback{
Pattern: regexPattern,
Function: function,
})
return nil
}