diff --git a/README.md b/README.md index b0205a0..637ba38 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ * [x] Send with New Photo. * [x] Send with New Document. * [x] Send with New Audio. -* [ ] Send with New Voice. +* [x] Send with New Voice. * [ ] Send with New Contact. * [ ] Send with New Location. * [ ] Send with New Venue. @@ -62,6 +62,7 @@ docker run --rm \ -e PLUGIN_DOCUMENT=tests/gophercolor.png \ -e PLUGIN_STICKER=tests/github-logo.png \ -e PLUGIN_AUDIO=tests/audio.mp3 \ + -e PLUGIN_VOICE=tests/voice.ogg \ -e PLUGIN_DEBUG=true \ -e PLUGIN_FORMAT=markdown \ -e DRONE_REPO_OWNER=appleboy \ diff --git a/main.go b/main.go index 07abfac..e3cd0fc 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,11 @@ func main() { Usage: "send audio message", EnvVar: "PLUGIN_AUDIO", }, + cli.StringSliceFlag{ + Name: "voice", + Usage: "send voice message", + EnvVar: "PLUGIN_VOICE", + }, cli.BoolFlag{ Name: "debug", Usage: "enable debug message", @@ -145,6 +150,7 @@ func run(c *cli.Context) error { Document: c.StringSlice("document"), Sticker: c.StringSlice("sticker"), Audio: c.StringSlice("audio"), + Voice: c.StringSlice("voice"), Format: c.String("format"), }, } diff --git a/plugin.go b/plugin.go index 33be709..708a1cc 100644 --- a/plugin.go +++ b/plugin.go @@ -40,6 +40,7 @@ type ( Document []string Sticker []string Audio []string + Voice []string Format string } @@ -126,6 +127,7 @@ func (p Plugin) Exec() error { documents := fileExist(trimElement(p.Config.Document)) stickers := fileExist(trimElement(p.Config.Sticker)) audios := fileExist(trimElement(p.Config.Audio)) + voices := fileExist(trimElement(p.Config.Voice)) // send message. for _, user := range ids { @@ -155,6 +157,11 @@ func (p Plugin) Exec() error { msg.Title = "Audio Message." p.Send(bot, msg) } + + for _, value := range voices { + msg := tgbotapi.NewVoiceUpload(user, value) + p.Send(bot, msg) + } } return nil diff --git a/plugin_test.go b/plugin_test.go index 96d2dbf..6a46a59 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -73,6 +73,7 @@ func TestSendMessage(t *testing.T) { 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", " "}, + Voice: []string{"tests/voice.ogg", "tests/github.png", "1234", " "}, Debug: false, }, } diff --git a/tests/audio.mp3 b/tests/audio.mp3 new file mode 100644 index 0000000..06b0284 Binary files /dev/null and b/tests/audio.mp3 differ diff --git a/tests/voice.ogg b/tests/voice.ogg new file mode 100644 index 0000000..0d7f43e Binary files /dev/null and b/tests/voice.ogg differ