Skip to content

Commit fa40708

Browse files
committed
Add SendMediaGroup method.
1 parent 5781187 commit fa40708

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

bot.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ func (bot *BotAPI) Send(c Chattable) (Message, error) {
307307
return message, err
308308
}
309309

310+
// SendMediaGroup sends a media group and returns the resulting messages.
311+
func (bot *BotAPI) SendMediaGroup(config MediaGroupConfig) ([]Message, error) {
312+
params, _ := config.params()
313+
314+
resp, err := bot.MakeRequest(config.method(), params)
315+
if err != nil {
316+
return nil, err
317+
}
318+
319+
var messages []Message
320+
err = json.Unmarshal(resp.Result, &messages)
321+
322+
return messages, err
323+
}
324+
310325
// GetUserProfilePhotos gets a user's profile photos.
311326
//
312327
// It requires UserID.

bot_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,19 @@ func TestSendWithMediaGroup(t *testing.T) {
517517
NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"),
518518
NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"),
519519
})
520-
_, err := bot.Request(cfg)
520+
521+
messages, err := bot.SendMediaGroup(cfg)
521522
if err != nil {
522523
t.Error(err)
523524
}
525+
526+
if messages == nil {
527+
t.Error()
528+
}
529+
530+
if len(messages) != 3 {
531+
t.Error()
532+
}
524533
}
525534

526535
func ExampleNewBotAPI() {

0 commit comments

Comments
 (0)