Support Audio message.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-10-14 13:36:08 +08:00
parent 57468ba50b
commit 8c0a2a65dc
4 changed files with 17 additions and 1 deletions

View File

@ -9,7 +9,7 @@
* [x] Send with Text Message. (`markdown` or `html` format) * [x] Send with Text Message. (`markdown` or `html` format)
* [x] Send with New Photo. * [x] Send with New Photo.
* [x] Send with New Document. * [x] Send with New Document.
* [ ] Send with New Audio. * [x] Send with New Audio.
* [ ] Send with New Voice. * [ ] Send with New Voice.
* [ ] Send with New Contact. * [ ] Send with New Contact.
* [ ] Send with New Location. * [ ] Send with New Location.
@ -61,6 +61,7 @@ docker run --rm \
-e PLUGIN_PHOTO=tests/github.png \ -e PLUGIN_PHOTO=tests/github.png \
-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_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

@ -47,6 +47,11 @@ func main() {
Usage: "send sticker message", Usage: "send sticker message",
EnvVar: "PLUGIN_STICKER", EnvVar: "PLUGIN_STICKER",
}, },
cli.StringSliceFlag{
Name: "audio",
Usage: "send audio message",
EnvVar: "PLUGIN_AUDIO",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "debug", Name: "debug",
Usage: "enable debug message", Usage: "enable debug message",
@ -139,6 +144,7 @@ func run(c *cli.Context) error {
Photo: c.StringSlice("photo"), Photo: c.StringSlice("photo"),
Document: c.StringSlice("document"), Document: c.StringSlice("document"),
Sticker: c.StringSlice("sticker"), Sticker: c.StringSlice("sticker"),
Audio: c.StringSlice("audio"),
Format: c.String("format"), Format: c.String("format"),
}, },
} }

View File

@ -39,6 +39,7 @@ type (
Photo []string Photo []string
Document []string Document []string
Sticker []string Sticker []string
Audio []string
Format string Format string
} }
@ -124,6 +125,7 @@ func (p Plugin) Exec() error {
photos := fileExist(trimElement(p.Config.Photo)) photos := fileExist(trimElement(p.Config.Photo))
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))
// send message. // send message.
for _, user := range ids { for _, user := range ids {
@ -147,6 +149,12 @@ func (p Plugin) Exec() error {
msg := tgbotapi.NewStickerUpload(user, value) msg := tgbotapi.NewStickerUpload(user, value)
p.Send(bot, msg) p.Send(bot, msg)
} }
for _, value := range audios {
msg := tgbotapi.NewAudioUpload(user, value)
msg.Title = "Audio Message."
p.Send(bot, msg)
}
} }
return nil return nil

View File

@ -72,6 +72,7 @@ func TestSendMessage(t *testing.T) {
Photo: []string{"tests/github.png", "1234", " "}, Photo: []string{"tests/github.png", "1234", " "},
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", " "},
Debug: false, Debug: false,
}, },
} }