@@ -38,11 +38,13 @@ const (
3838 ModeMarkdown = "Markdown"
3939)
4040
41+ //Chattable represents any event in chat(MessageConfig, PhotoConfig, ChatActionConfig and others)
4142type Chattable interface {
4243 Values () (url.Values , error )
4344 Method () string
4445}
4546
47+ //Fileable represents any file event(PhotoConfig, DocumentConfig, AudioConfig, VoiceConfig, VideoConfig, StickerConfig)
4648type Fileable interface {
4749 Chattable
4850 Params () (map [string ]string , error )
@@ -51,14 +53,15 @@ type Fileable interface {
5153 UseExistingFile () bool
5254}
5355
54- // Base struct for all chat event(Message, Photo and so on)
56+ // BaseChat is base struct for all chat event(Message, Photo and so on)
5557type BaseChat struct {
5658 ChatID int
5759 ChannelUsername string
5860 ReplyToMessageID int
5961 ReplyMarkup interface {}
6062}
6163
64+ // Values returns url.Values representation of BaseChat
6265func (chat * BaseChat ) Values () (url.Values , error ) {
6366 v := url.Values {}
6467 if chat .ChannelUsername != "" {
@@ -83,6 +86,7 @@ func (chat *BaseChat) Values() (url.Values, error) {
8386 return v , nil
8487}
8588
89+ // BaseFile is base struct for all file events(PhotoConfig, DocumentConfig, AudioConfig, VoiceConfig, VideoConfig, StickerConfig)
8690type BaseFile struct {
8791 BaseChat
8892 FilePath string
@@ -91,6 +95,7 @@ type BaseFile struct {
9195 UseExisting bool
9296}
9397
98+ // Params returns map[string]string representation of BaseFile
9499func (file BaseFile ) Params () (map [string ]string , error ) {
95100 params := make (map [string ]string )
96101
@@ -116,6 +121,7 @@ func (file BaseFile) Params() (map[string]string, error) {
116121 return params , nil
117122}
118123
124+ // GetFile returns abstract representation of File inside BaseFile
119125func (file BaseFile ) GetFile () interface {} {
120126 var result interface {}
121127 if file .FilePath == "" {
@@ -127,6 +133,7 @@ func (file BaseFile) GetFile() interface{} {
127133 return result
128134}
129135
136+ // UseExistingFile returns true if BaseFile contains already uploaded file by FileID
130137func (file BaseFile ) UseExistingFile () bool {
131138 return file .UseExisting
132139}
@@ -140,6 +147,7 @@ type MessageConfig struct {
140147 ReplyMarkup interface {}
141148}
142149
150+ // Values returns url.Values representation of MessageConfig
143151func (config MessageConfig ) Values () (url.Values , error ) {
144152 v , _ := config .BaseChat .Values ()
145153 v .Add ("text" , config .Text )
@@ -151,6 +159,7 @@ func (config MessageConfig) Values() (url.Values, error) {
151159 return v , nil
152160}
153161
162+ // Method returns Telegram API method name for sending Message
154163func (config MessageConfig ) Method () string {
155164 return "SendMessage"
156165}
@@ -163,13 +172,15 @@ type ForwardConfig struct {
163172 MessageID int
164173}
165174
175+ // Values returns url.Values representation of ForwardConfig
166176func (config ForwardConfig ) Values () (url.Values , error ) {
167177 v , _ := config .BaseChat .Values ()
168178 v .Add ("from_chat_id" , strconv .Itoa (config .FromChatID ))
169179 v .Add ("message_id" , strconv .Itoa (config .MessageID ))
170180 return v , nil
171181}
172182
183+ // Method returns Telegram API method name for sending Forward
173184func (config ForwardConfig ) Method () string {
174185 return "forwardMessage"
175186}
@@ -180,6 +191,7 @@ type PhotoConfig struct {
180191 Caption string
181192}
182193
194+ // Params returns map[string]string representation of PhotoConfig
183195func (config PhotoConfig ) Params () (map [string ]string , error ) {
184196 params , _ := config .BaseFile .Params ()
185197
@@ -190,6 +202,7 @@ func (config PhotoConfig) Params() (map[string]string, error) {
190202 return params , nil
191203}
192204
205+ // Values returns url.Values representation of PhotoConfig
193206func (config PhotoConfig ) Values () (url.Values , error ) {
194207 v , _ := config .BaseChat .Values ()
195208
@@ -200,10 +213,12 @@ func (config PhotoConfig) Values() (url.Values, error) {
200213 return v , nil
201214}
202215
216+ // Name return field name for uploading file
203217func (config PhotoConfig ) Name () string {
204218 return "photo"
205219}
206220
221+ // Method returns Telegram API method name for sending Photo
207222func (config PhotoConfig ) Method () string {
208223 return "SendPhoto"
209224}
@@ -216,6 +231,7 @@ type AudioConfig struct {
216231 Title string
217232}
218233
234+ // Values returns url.Values representation of AudioConfig
219235func (config AudioConfig ) Values () (url.Values , error ) {
220236 v , _ := config .BaseChat .Values ()
221237
@@ -234,6 +250,7 @@ func (config AudioConfig) Values() (url.Values, error) {
234250 return v , nil
235251}
236252
253+ // Params returns map[string]string representation of AudioConfig
237254func (config AudioConfig ) Params () (map [string ]string , error ) {
238255 params , _ := config .BaseFile .Params ()
239256
@@ -251,10 +268,12 @@ func (config AudioConfig) Params() (map[string]string, error) {
251268 return params , nil
252269}
253270
271+ // Name return field name for uploading file
254272func (config AudioConfig ) Name () string {
255273 return "audio"
256274}
257275
276+ // Method returns Telegram API method name for sending Audio
258277func (config AudioConfig ) Method () string {
259278 return "SendAudio"
260279}
@@ -264,6 +283,7 @@ type DocumentConfig struct {
264283 BaseFile
265284}
266285
286+ // Values returns url.Values representation of DocumentConfig
267287func (config DocumentConfig ) Values () (url.Values , error ) {
268288 v , _ := config .BaseChat .Values ()
269289
@@ -272,16 +292,19 @@ func (config DocumentConfig) Values() (url.Values, error) {
272292 return v , nil
273293}
274294
295+ // Params returns map[string]string representation of DocumentConfig
275296func (config DocumentConfig ) Params () (map [string ]string , error ) {
276297 params , _ := config .BaseFile .Params ()
277298
278299 return params , nil
279300}
280301
302+ // Name return field name for uploading file
281303func (config DocumentConfig ) Name () string {
282304 return "document"
283305}
284306
307+ // Method returns Telegram API method name for sending Document
285308func (config DocumentConfig ) Method () string {
286309 return "sendDocument"
287310}
@@ -291,6 +314,7 @@ type StickerConfig struct {
291314 BaseFile
292315}
293316
317+ // Values returns url.Values representation of StickerConfig
294318func (config StickerConfig ) Values () (url.Values , error ) {
295319 v , _ := config .BaseChat .Values ()
296320
@@ -299,16 +323,19 @@ func (config StickerConfig) Values() (url.Values, error) {
299323 return v , nil
300324}
301325
326+ // Params returns map[string]string representation of StickerConfig
302327func (config StickerConfig ) Params () (map [string ]string , error ) {
303328 params , _ := config .BaseFile .Params ()
304329
305330 return params , nil
306331}
307332
333+ // Name return field name for uploading file
308334func (config StickerConfig ) Name () string {
309335 return "sticker"
310336}
311337
338+ // Method returns Telegram API method name for sending Sticker
312339func (config StickerConfig ) Method () string {
313340 return "sendSticker"
314341}
@@ -320,6 +347,7 @@ type VideoConfig struct {
320347 Caption string
321348}
322349
350+ // Values returns url.Values representation of VideoConfig
323351func (config VideoConfig ) Values () (url.Values , error ) {
324352 v , _ := config .BaseChat .Values ()
325353
@@ -334,16 +362,19 @@ func (config VideoConfig) Values() (url.Values, error) {
334362 return v , nil
335363}
336364
365+ // Params returns map[string]string representation of VideoConfig
337366func (config VideoConfig ) Params () (map [string ]string , error ) {
338367 params , _ := config .BaseFile .Params ()
339368
340369 return params , nil
341370}
342371
372+ // Name return field name for uploading file
343373func (config VideoConfig ) Name () string {
344374 return "video"
345375}
346376
377+ // Method returns Telegram API method name for sending Video
347378func (config VideoConfig ) Method () string {
348379 return "sendVideo"
349380}
@@ -354,6 +385,7 @@ type VoiceConfig struct {
354385 Duration int
355386}
356387
388+ // Values returns url.Values representation of VoiceConfig
357389func (config VoiceConfig ) Values () (url.Values , error ) {
358390 v , _ := config .BaseChat .Values ()
359391
@@ -365,6 +397,7 @@ func (config VoiceConfig) Values() (url.Values, error) {
365397 return v , nil
366398}
367399
400+ // Params returns map[string]string representation of VoiceConfig
368401func (config VoiceConfig ) Params () (map [string ]string , error ) {
369402 params , _ := config .BaseFile .Params ()
370403
@@ -375,10 +408,12 @@ func (config VoiceConfig) Params() (map[string]string, error) {
375408 return params , nil
376409}
377410
411+ // Name return field name for uploading file
378412func (config VoiceConfig ) Name () string {
379413 return "voice"
380414}
381415
416+ // Method returns Telegram API method name for sending Voice
382417func (config VoiceConfig ) Method () string {
383418 return "sendVoice"
384419}
@@ -390,6 +425,7 @@ type LocationConfig struct {
390425 Longitude float64
391426}
392427
428+ // Values returns url.Values representation of LocationConfig
393429func (config LocationConfig ) Values () (url.Values , error ) {
394430 v , _ := config .BaseChat .Values ()
395431
@@ -399,6 +435,7 @@ func (config LocationConfig) Values() (url.Values, error) {
399435 return v , nil
400436}
401437
438+ // Method returns Telegram API method name for sending Location
402439func (config LocationConfig ) Method () string {
403440 return "sendLocation"
404441}
@@ -409,12 +446,14 @@ type ChatActionConfig struct {
409446 Action string
410447}
411448
449+ // Values returns url.Values representation of ChatActionConfig
412450func (config ChatActionConfig ) Values () (url.Values , error ) {
413451 v , _ := config .BaseChat .Values ()
414452 v .Add ("action" , config .Action )
415453 return v , nil
416454}
417455
456+ // Method returns Telegram API method name for sending ChatAction
418457func (config ChatActionConfig ) Method () string {
419458 return "sendChatAction"
420459}
0 commit comments