-
Notifications
You must be signed in to change notification settings - Fork 15
/
interfaces.go
138 lines (119 loc) · 5.08 KB
/
interfaces.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
133
134
135
136
137
138
package margelet
import (
"gopkg.in/redis.v3"
"gopkg.in/telegram-bot-api.v4"
"net/url"
)
// MessageHandler - interface for message handlers
type MessageHandler interface {
HandleMessage(message Message) error
}
// InlineHandler - interface for message handlers
type InlineHandler interface {
HandleInline(bot MargeletAPI, query *tgbotapi.InlineQuery) error
}
// CallbackHandler - interface for message handlers
type CallbackHandler interface {
HandleCallback(query CallbackQuery) error
}
// CommandHandler - interface for command handlers
type CommandHandler interface {
HandleCommand(msg Message) error
HelpMessage() string
}
// SessionHandler - interface for session handlers
type SessionHandler interface {
HandleSession(session Session) error
CancelSession(session Session)
HelpMessage() string
}
type Store interface {
GetConfigRepository() *ChatConfigRepository
GetSessionRepository() SessionRepository
GetChatRepository() *ChatRepository
GetStatsRepository() StatsRepository
GetRedis() *redis.Client
}
// MargeletAPI - interface, that describes margelet API
type MargeletAPI interface {
Store
Send(c tgbotapi.Chattable) (tgbotapi.Message, error)
AnswerInlineQuery(config tgbotapi.InlineConfig) (tgbotapi.APIResponse, error)
AnswerCallbackQuery(config tgbotapi.CallbackConfig) (tgbotapi.APIResponse, error)
QuickSend(chatID int64, message string, replyMarkup interface{}) (tgbotapi.Message, error)
QuickReply(chatID int64, messageID int, message string, replyMarkup interface{}) (tgbotapi.Message, error)
QuickForceReply(chatID int64, messageID int, message string) (tgbotapi.Message, error)
SendImage(chatID int64, reader tgbotapi.FileReader, caption string, replyMarkup interface{}) (tgbotapi.Message, error)
GetFileDirectURL(fileID string) (string, error)
IsMessageToMe(message tgbotapi.Message) bool
HandleSession(message *tgbotapi.Message, command string)
StartSession(message *tgbotapi.Message, command string)
SendImageByURL(chatID int64, url string, caption string, replyMarkup interface{}) (tgbotapi.Message, error)
SendImageByID(chatID int64, url string, caption string, replyMarkup interface{}) (tgbotapi.Message, error)
SendDocument(chatID int64, reader tgbotapi.FileReader, replyMarkup interface{}) (tgbotapi.Message, error)
SendDocumentByURL(chatID int64, url string, replyMarkup interface{}) (tgbotapi.Message, error)
SendTypingAction(chatID int64) error
SendUploadPhotoAction(chatID int64) error
SendRecordVideoAction(chatID int64) error
SendUploadVideoAction(chatID int64) error
SendRecordAudioAction(chatID int64) error
SendUploadAudioAction(chatID int64) error
SendUploadDocumentAction(chatID int64) error
SendFindLocationAction(chatID int64) error
SendHideKeyboard(chatID int64, message string) error
RawBot() *tgbotapi.BotAPI
GetUserProfilePhotos(config tgbotapi.UserProfilePhotosConfig) (tgbotapi.UserProfilePhotos, error)
GetCurrentUserpic(userID int) (string, error)
GetCurrentUserpicID(userID int) (string, error)
}
// TGBotAPI - interface, that describe telegram-bot-api API
type TGBotAPI interface {
Send(c tgbotapi.Chattable) (tgbotapi.Message, error)
AnswerInlineQuery(config tgbotapi.InlineConfig) (tgbotapi.APIResponse, error)
AnswerCallbackQuery(config tgbotapi.CallbackConfig) (tgbotapi.APIResponse, error)
GetFileDirectURL(fileID string) (string, error)
IsMessageToMe(message tgbotapi.Message) bool
GetUpdatesChan(config tgbotapi.UpdateConfig) (<-chan tgbotapi.Update, error)
MakeRequest(endpoint string, params url.Values) (tgbotapi.APIResponse, error)
}
// AuthorizationPolicy - interface, that describes authorization policy for command or session
type AuthorizationPolicy interface {
Allow(message *tgbotapi.Message) error
}
// Message - interface, that describes incapsulated info aboud user's message with some helper methods
type Message interface {
Store
Message() *tgbotapi.Message
GetFileDirectURL(fileID string) (string, error)
QuickSend(text string, replyMarkup interface{}) (tgbotapi.Message, error)
QuickReply(text string, replyMarkup interface{}) (tgbotapi.Message, error)
QuickForceReply(text string) (tgbotapi.Message, error)
SendImageByURL(url string, caption string, replyMarkup interface{}) (tgbotapi.Message, error)
SendImage(reader tgbotapi.FileReader, caption string, replyMarkup interface{}) (tgbotapi.Message, error)
SendDocument(reader tgbotapi.FileReader, replyMarkup interface{}) (tgbotapi.Message, error)
SendDocumentByURL(url string, replyMarkup interface{}) (tgbotapi.Message, error)
SendTypingAction() error
SendUploadPhotoAction() error
SendRecordVideoAction() error
SendUploadVideoAction() error
SendRecordAudioAction() error
SendUploadAudioAction() error
SendUploadDocumentAction() error
SendFindLocationAction() error
SendHideKeyboard(message string) error
GetCurrentUserpic() (string, error)
GetCurrentUserpicID() (string, error)
Bot() MargeletAPI
StartSession(command string)
}
// Session - interface, that describes incapsulated info aboud user's session with bot
type Session interface {
Message
Responses() []tgbotapi.Message
Finish()
}
type CallbackQuery interface {
Message
Query() *tgbotapi.CallbackQuery
Data() string
}