Skip to content

Commit ce4fc98

Browse files
committed
Add support for uploading multiple files.
1 parent 2f7211a commit ce4fc98

File tree

8 files changed

+388
-498
lines changed

8 files changed

+388
-498
lines changed

bot.go

+175-117
Large diffs are not rendered by default.

bot_test.go

+40-28
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestSendWithMessageForward(t *testing.T) {
9292
func TestSendWithNewPhoto(t *testing.T) {
9393
bot, _ := getBot(t)
9494

95-
msg := NewPhotoUpload(ChatID, "tests/image.jpg")
95+
msg := NewPhoto(ChatID, "tests/image.jpg")
9696
msg.Caption = "Test"
9797
_, err := bot.Send(msg)
9898

@@ -107,7 +107,7 @@ func TestSendWithNewPhotoWithFileBytes(t *testing.T) {
107107
data, _ := ioutil.ReadFile("tests/image.jpg")
108108
b := FileBytes{Name: "image.jpg", Bytes: data}
109109

110-
msg := NewPhotoUpload(ChatID, b)
110+
msg := NewPhoto(ChatID, b)
111111
msg.Caption = "Test"
112112
_, err := bot.Send(msg)
113113

@@ -122,7 +122,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
122122
f, _ := os.Open("tests/image.jpg")
123123
reader := FileReader{Name: "image.jpg", Reader: f, Size: -1}
124124

125-
msg := NewPhotoUpload(ChatID, reader)
125+
msg := NewPhoto(ChatID, reader)
126126
msg.Caption = "Test"
127127
_, err := bot.Send(msg)
128128

@@ -134,7 +134,7 @@ func TestSendWithNewPhotoWithFileReader(t *testing.T) {
134134
func TestSendWithNewPhotoReply(t *testing.T) {
135135
bot, _ := getBot(t)
136136

137-
msg := NewPhotoUpload(ChatID, "tests/image.jpg")
137+
msg := NewPhoto(ChatID, "tests/image.jpg")
138138
msg.ReplyToMessageID = ReplyToMessageID
139139

140140
_, err := bot.Send(msg)
@@ -147,7 +147,7 @@ func TestSendWithNewPhotoReply(t *testing.T) {
147147
func TestSendNewPhotoToChannel(t *testing.T) {
148148
bot, _ := getBot(t)
149149

150-
msg := NewPhotoUploadToChannel(Channel, "tests/image.jpg")
150+
msg := NewPhotoToChannel(Channel, "tests/image.jpg")
151151
msg.Caption = "Test"
152152
_, err := bot.Send(msg)
153153

@@ -163,7 +163,7 @@ func TestSendNewPhotoToChannelFileBytes(t *testing.T) {
163163
data, _ := ioutil.ReadFile("tests/image.jpg")
164164
b := FileBytes{Name: "image.jpg", Bytes: data}
165165

166-
msg := NewPhotoUploadToChannel(Channel, b)
166+
msg := NewPhotoToChannel(Channel, b)
167167
msg.Caption = "Test"
168168
_, err := bot.Send(msg)
169169

@@ -179,7 +179,7 @@ func TestSendNewPhotoToChannelFileReader(t *testing.T) {
179179
f, _ := os.Open("tests/image.jpg")
180180
reader := FileReader{Name: "image.jpg", Reader: f, Size: -1}
181181

182-
msg := NewPhotoUploadToChannel(Channel, reader)
182+
msg := NewPhotoToChannel(Channel, reader)
183183
msg.Caption = "Test"
184184
_, err := bot.Send(msg)
185185

@@ -192,7 +192,7 @@ func TestSendNewPhotoToChannelFileReader(t *testing.T) {
192192
func TestSendWithExistingPhoto(t *testing.T) {
193193
bot, _ := getBot(t)
194194

195-
msg := NewPhotoShare(ChatID, ExistingPhotoFileID)
195+
msg := NewPhoto(ChatID, FileID(ExistingPhotoFileID))
196196
msg.Caption = "Test"
197197
_, err := bot.Send(msg)
198198

@@ -204,7 +204,19 @@ func TestSendWithExistingPhoto(t *testing.T) {
204204
func TestSendWithNewDocument(t *testing.T) {
205205
bot, _ := getBot(t)
206206

207-
msg := NewDocumentUpload(ChatID, "tests/image.jpg")
207+
msg := NewDocument(ChatID, "tests/image.jpg")
208+
_, err := bot.Send(msg)
209+
210+
if err != nil {
211+
t.Error(err)
212+
}
213+
}
214+
215+
func TestSendWithNewDocumentAndThumb(t *testing.T) {
216+
bot, _ := getBot(t)
217+
218+
msg := NewDocument(ChatID, "tests/voice.ogg")
219+
msg.AddFile("thumb", "tests/image.jpg")
208220
_, err := bot.Send(msg)
209221

210222
if err != nil {
@@ -215,7 +227,7 @@ func TestSendWithNewDocument(t *testing.T) {
215227
func TestSendWithExistingDocument(t *testing.T) {
216228
bot, _ := getBot(t)
217229

218-
msg := NewDocumentShare(ChatID, ExistingDocumentFileID)
230+
msg := NewDocument(ChatID, FileID(ExistingDocumentFileID))
219231
_, err := bot.Send(msg)
220232

221233
if err != nil {
@@ -226,7 +238,7 @@ func TestSendWithExistingDocument(t *testing.T) {
226238
func TestSendWithNewAudio(t *testing.T) {
227239
bot, _ := getBot(t)
228240

229-
msg := NewAudioUpload(ChatID, "tests/audio.mp3")
241+
msg := NewAudio(ChatID, "tests/audio.mp3")
230242
msg.Title = "TEST"
231243
msg.Duration = 10
232244
msg.Performer = "TEST"
@@ -242,7 +254,7 @@ func TestSendWithNewAudio(t *testing.T) {
242254
func TestSendWithExistingAudio(t *testing.T) {
243255
bot, _ := getBot(t)
244256

245-
msg := NewAudioShare(ChatID, ExistingAudioFileID)
257+
msg := NewAudio(ChatID, FileID(ExistingAudioFileID))
246258
msg.Title = "TEST"
247259
msg.Duration = 10
248260
msg.Performer = "TEST"
@@ -257,7 +269,7 @@ func TestSendWithExistingAudio(t *testing.T) {
257269
func TestSendWithNewVoice(t *testing.T) {
258270
bot, _ := getBot(t)
259271

260-
msg := NewVoiceUpload(ChatID, "tests/voice.ogg")
272+
msg := NewVoice(ChatID, "tests/voice.ogg")
261273
msg.Duration = 10
262274
_, err := bot.Send(msg)
263275

@@ -269,7 +281,7 @@ func TestSendWithNewVoice(t *testing.T) {
269281
func TestSendWithExistingVoice(t *testing.T) {
270282
bot, _ := getBot(t)
271283

272-
msg := NewVoiceShare(ChatID, ExistingVoiceFileID)
284+
msg := NewVoice(ChatID, FileID(ExistingVoiceFileID))
273285
msg.Duration = 10
274286
_, err := bot.Send(msg)
275287

@@ -311,7 +323,7 @@ func TestSendWithVenue(t *testing.T) {
311323
func TestSendWithNewVideo(t *testing.T) {
312324
bot, _ := getBot(t)
313325

314-
msg := NewVideoUpload(ChatID, "tests/video.mp4")
326+
msg := NewVideo(ChatID, "tests/video.mp4")
315327
msg.Duration = 10
316328
msg.Caption = "TEST"
317329

@@ -325,7 +337,7 @@ func TestSendWithNewVideo(t *testing.T) {
325337
func TestSendWithExistingVideo(t *testing.T) {
326338
bot, _ := getBot(t)
327339

328-
msg := NewVideoShare(ChatID, ExistingVideoFileID)
340+
msg := NewVideo(ChatID, FileID(ExistingVideoFileID))
329341
msg.Duration = 10
330342
msg.Caption = "TEST"
331343

@@ -339,7 +351,7 @@ func TestSendWithExistingVideo(t *testing.T) {
339351
func TestSendWithNewVideoNote(t *testing.T) {
340352
bot, _ := getBot(t)
341353

342-
msg := NewVideoNoteUpload(ChatID, 240, "tests/videonote.mp4")
354+
msg := NewVideoNote(ChatID, 240, "tests/videonote.mp4")
343355
msg.Duration = 10
344356

345357
_, err := bot.Send(msg)
@@ -352,7 +364,7 @@ func TestSendWithNewVideoNote(t *testing.T) {
352364
func TestSendWithExistingVideoNote(t *testing.T) {
353365
bot, _ := getBot(t)
354366

355-
msg := NewVideoNoteShare(ChatID, 240, ExistingVideoNoteFileID)
367+
msg := NewVideoNote(ChatID, 240, FileID(ExistingVideoNoteFileID))
356368
msg.Duration = 10
357369

358370
_, err := bot.Send(msg)
@@ -365,7 +377,7 @@ func TestSendWithExistingVideoNote(t *testing.T) {
365377
func TestSendWithNewSticker(t *testing.T) {
366378
bot, _ := getBot(t)
367379

368-
msg := NewStickerUpload(ChatID, "tests/image.jpg")
380+
msg := NewSticker(ChatID, "tests/image.jpg")
369381

370382
_, err := bot.Send(msg)
371383

@@ -377,7 +389,7 @@ func TestSendWithNewSticker(t *testing.T) {
377389
func TestSendWithExistingSticker(t *testing.T) {
378390
bot, _ := getBot(t)
379391

380-
msg := NewStickerShare(ChatID, ExistingStickerFileID)
392+
msg := NewSticker(ChatID, FileID(ExistingStickerFileID))
381393

382394
_, err := bot.Send(msg)
383395

@@ -389,7 +401,7 @@ func TestSendWithExistingSticker(t *testing.T) {
389401
func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
390402
bot, _ := getBot(t)
391403

392-
msg := NewStickerUpload(ChatID, "tests/image.jpg")
404+
msg := NewSticker(ChatID, "tests/image.jpg")
393405
msg.ReplyMarkup = ReplyKeyboardRemove{
394406
RemoveKeyboard: true,
395407
Selective: false,
@@ -404,7 +416,7 @@ func TestSendWithNewStickerAndKeyboardHide(t *testing.T) {
404416
func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) {
405417
bot, _ := getBot(t)
406418

407-
msg := NewStickerShare(ChatID, ExistingStickerFileID)
419+
msg := NewSticker(ChatID, FileID(ExistingStickerFileID))
408420
msg.ReplyMarkup = ReplyKeyboardRemove{
409421
RemoveKeyboard: true,
410422
Selective: false,
@@ -526,9 +538,9 @@ func TestSendWithMediaGroup(t *testing.T) {
526538
bot, _ := getBot(t)
527539

528540
cfg := NewMediaGroup(ChatID, []interface{}{
529-
NewInputMediaPhoto("https://i.imgur.com/unQLJIb.jpg"),
530-
NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"),
531-
NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"),
541+
NewInputMediaPhoto(FileURL("https://i.imgur.com/unQLJIb.jpg")),
542+
NewInputMediaPhoto("tests/image.jpg"),
543+
NewInputMediaVideo("tests/video.mp4"),
532544
})
533545

534546
messages, err := bot.SendMediaGroup(cfg)
@@ -537,11 +549,11 @@ func TestSendWithMediaGroup(t *testing.T) {
537549
}
538550

539551
if messages == nil {
540-
t.Error()
552+
t.Error("No received messages")
541553
}
542554

543-
if len(messages) != 3 {
544-
t.Error()
555+
if len(messages) != len(cfg.Media) {
556+
t.Errorf("Different number of messages: %d", len(messages))
545557
}
546558
}
547559

0 commit comments

Comments
 (0)