diff --git a/README.md b/README.md index fe1b6b8..ac6bfef 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ * [ ] Send with New Location. * [ ] Send with New Venue. * [ ] Send with New Video. -* [ ] Send with New Sticker. +* [x] Send with New Sticker. ## Build @@ -60,6 +60,7 @@ docker run --rm \ -e PLUGIN_MESSAGE=test \ -e PLUGIN_PHOTO=tests/github.png \ -e PLUGIN_DOCUMENT=tests/gophercolor.png \ + -e PLUGIN_STICKER=tests/github-logo.png \ -e PLUGIN_DEBUG=true \ -e PLUGIN_FORMAT=markdown \ -e DRONE_REPO_OWNER=appleboy \ diff --git a/main.go b/main.go index 5843000..a885b1c 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,11 @@ func main() { Usage: "send document message", EnvVar: "PLUGIN_DOCUMENT", }, + cli.StringSliceFlag{ + Name: "sticker", + Usage: "send sticker message", + EnvVar: "PLUGIN_STICKER", + }, cli.BoolFlag{ Name: "debug", Usage: "enable debug message", @@ -133,6 +138,7 @@ func run(c *cli.Context) error { Message: c.StringSlice("message"), Photo: c.StringSlice("photo"), Document: c.StringSlice("document"), + Sticker: c.StringSlice("sticker"), Format: c.String("format"), }, } diff --git a/plugin.go b/plugin.go index baf80f8..c9b78f3 100644 --- a/plugin.go +++ b/plugin.go @@ -38,6 +38,7 @@ type ( Message []string Photo []string Document []string + Sticker []string Format string } @@ -122,6 +123,7 @@ func (p Plugin) Exec() error { ids := parseID(p.Config.To) photos := fileExist(trimElement(p.Config.Photo)) documents := fileExist(trimElement(p.Config.Document)) + stickers := fileExist(trimElement(p.Config.Sticker)) // send message. for _, user := range ids { @@ -140,6 +142,11 @@ func (p Plugin) Exec() error { msg := tgbotapi.NewDocumentUpload(user, value) p.Send(bot, msg) } + + for _, value := range stickers { + msg := tgbotapi.NewStickerUpload(user, value) + p.Send(bot, msg) + } } return nil diff --git a/plugin_test.go b/plugin_test.go index efe4a25..b40982c 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -71,6 +71,7 @@ func TestSendMessage(t *testing.T) { Message: []string{"Test Telegram Chat Bot From Travis or Local", " "}, Photo: []string{"tests/github.png", "1234", " "}, Document: []string{"tests/gophercolor.png", "1234", " "}, + Sticker: []string{"tests/github-logo.png", "tests/github.png", "1234", " "}, Debug: false, }, } diff --git a/tests/github-logo.png b/tests/github-logo.png new file mode 100644 index 0000000..8075d5d Binary files /dev/null and b/tests/github-logo.png differ