diff --git a/README.md b/README.md index ac6bfef..b0205a0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ * [x] Send with Text Message. (`markdown` or `html` format) * [x] Send with New Photo. * [x] Send with New Document. -* [ ] Send with New Audio. +* [x] Send with New Audio. * [ ] Send with New Voice. * [ ] Send with New Contact. * [ ] Send with New Location. @@ -61,6 +61,7 @@ docker run --rm \ -e PLUGIN_PHOTO=tests/github.png \ -e PLUGIN_DOCUMENT=tests/gophercolor.png \ -e PLUGIN_STICKER=tests/github-logo.png \ + -e PLUGIN_AUDIO=tests/audio.mp3 \ -e PLUGIN_DEBUG=true \ -e PLUGIN_FORMAT=markdown \ -e DRONE_REPO_OWNER=appleboy \ diff --git a/main.go b/main.go index a885b1c..07abfac 100644 --- a/main.go +++ b/main.go @@ -47,6 +47,11 @@ func main() { Usage: "send sticker message", EnvVar: "PLUGIN_STICKER", }, + cli.StringSliceFlag{ + Name: "audio", + Usage: "send audio message", + EnvVar: "PLUGIN_AUDIO", + }, cli.BoolFlag{ Name: "debug", Usage: "enable debug message", @@ -139,6 +144,7 @@ func run(c *cli.Context) error { Photo: c.StringSlice("photo"), Document: c.StringSlice("document"), Sticker: c.StringSlice("sticker"), + Audio: c.StringSlice("audio"), Format: c.String("format"), }, } diff --git a/plugin.go b/plugin.go index c9b78f3..33be709 100644 --- a/plugin.go +++ b/plugin.go @@ -39,6 +39,7 @@ type ( Photo []string Document []string Sticker []string + Audio []string Format string } @@ -124,6 +125,7 @@ func (p Plugin) Exec() error { photos := fileExist(trimElement(p.Config.Photo)) documents := fileExist(trimElement(p.Config.Document)) stickers := fileExist(trimElement(p.Config.Sticker)) + audios := fileExist(trimElement(p.Config.Audio)) // send message. for _, user := range ids { @@ -147,6 +149,12 @@ func (p Plugin) Exec() error { msg := tgbotapi.NewStickerUpload(user, value) p.Send(bot, msg) } + + for _, value := range audios { + msg := tgbotapi.NewAudioUpload(user, value) + msg.Title = "Audio Message." + p.Send(bot, msg) + } } return nil diff --git a/plugin_test.go b/plugin_test.go index b40982c..96d2dbf 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -72,6 +72,7 @@ func TestSendMessage(t *testing.T) { Photo: []string{"tests/github.png", "1234", " "}, Document: []string{"tests/gophercolor.png", "1234", " "}, Sticker: []string{"tests/github-logo.png", "tests/github.png", "1234", " "}, + Audio: []string{"tests/audio.mp3", "tests/github.png", "1234", " "}, Debug: false, }, }