Support Voice Message.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-10-14 13:57:31 +08:00
parent 8c0a2a65dc
commit 1142360e53
6 changed files with 16 additions and 1 deletions

View File

@ -10,7 +10,7 @@
* [x] Send with New Photo. * [x] Send with New Photo.
* [x] Send with New Document. * [x] Send with New Document.
* [x] Send with New Audio. * [x] Send with New Audio.
* [ ] Send with New Voice. * [x] Send with New Voice.
* [ ] Send with New Contact. * [ ] Send with New Contact.
* [ ] Send with New Location. * [ ] Send with New Location.
* [ ] Send with New Venue. * [ ] Send with New Venue.
@ -62,6 +62,7 @@ docker run --rm \
-e PLUGIN_DOCUMENT=tests/gophercolor.png \ -e PLUGIN_DOCUMENT=tests/gophercolor.png \
-e PLUGIN_STICKER=tests/github-logo.png \ -e PLUGIN_STICKER=tests/github-logo.png \
-e PLUGIN_AUDIO=tests/audio.mp3 \ -e PLUGIN_AUDIO=tests/audio.mp3 \
-e PLUGIN_VOICE=tests/voice.ogg \
-e PLUGIN_DEBUG=true \ -e PLUGIN_DEBUG=true \
-e PLUGIN_FORMAT=markdown \ -e PLUGIN_FORMAT=markdown \
-e DRONE_REPO_OWNER=appleboy \ -e DRONE_REPO_OWNER=appleboy \

View File

@ -52,6 +52,11 @@ func main() {
Usage: "send audio message", Usage: "send audio message",
EnvVar: "PLUGIN_AUDIO", EnvVar: "PLUGIN_AUDIO",
}, },
cli.StringSliceFlag{
Name: "voice",
Usage: "send voice message",
EnvVar: "PLUGIN_VOICE",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "debug", Name: "debug",
Usage: "enable debug message", Usage: "enable debug message",
@ -145,6 +150,7 @@ func run(c *cli.Context) error {
Document: c.StringSlice("document"), Document: c.StringSlice("document"),
Sticker: c.StringSlice("sticker"), Sticker: c.StringSlice("sticker"),
Audio: c.StringSlice("audio"), Audio: c.StringSlice("audio"),
Voice: c.StringSlice("voice"),
Format: c.String("format"), Format: c.String("format"),
}, },
} }

View File

@ -40,6 +40,7 @@ type (
Document []string Document []string
Sticker []string Sticker []string
Audio []string Audio []string
Voice []string
Format string Format string
} }
@ -126,6 +127,7 @@ func (p Plugin) Exec() error {
documents := fileExist(trimElement(p.Config.Document)) documents := fileExist(trimElement(p.Config.Document))
stickers := fileExist(trimElement(p.Config.Sticker)) stickers := fileExist(trimElement(p.Config.Sticker))
audios := fileExist(trimElement(p.Config.Audio)) audios := fileExist(trimElement(p.Config.Audio))
voices := fileExist(trimElement(p.Config.Voice))
// send message. // send message.
for _, user := range ids { for _, user := range ids {
@ -155,6 +157,11 @@ func (p Plugin) Exec() error {
msg.Title = "Audio Message." msg.Title = "Audio Message."
p.Send(bot, msg) p.Send(bot, msg)
} }
for _, value := range voices {
msg := tgbotapi.NewVoiceUpload(user, value)
p.Send(bot, msg)
}
} }
return nil return nil

View File

@ -73,6 +73,7 @@ func TestSendMessage(t *testing.T) {
Document: []string{"tests/gophercolor.png", "1234", " "}, Document: []string{"tests/gophercolor.png", "1234", " "},
Sticker: []string{"tests/github-logo.png", "tests/github.png", "1234", " "}, Sticker: []string{"tests/github-logo.png", "tests/github.png", "1234", " "},
Audio: []string{"tests/audio.mp3", "tests/github.png", "1234", " "}, Audio: []string{"tests/audio.mp3", "tests/github.png", "1234", " "},
Voice: []string{"tests/voice.ogg", "tests/github.png", "1234", " "},
Debug: false, Debug: false,
}, },
} }

BIN
tests/audio.mp3 Normal file

Binary file not shown.

BIN
tests/voice.ogg Normal file

Binary file not shown.