From 61d0bc0138c4791ffe107ac422e0a137202bcaa8 Mon Sep 17 00:00:00 2001 From: Valentyn Nastenko Date: Thu, 15 Apr 2021 17:47:29 +0300 Subject: [PATCH 1/3] docs: updated documentation for pushover service --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8867085..35247f6 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ COMMANDS: slack Send message to slack discord Send message to discord teams Send message to microsoft teams + pushover Send message to pushover email Send an email help, h Shows a list of commands or help for one command From 5377dac6efab0a9cb8aeb94da349114dc7de9e9e Mon Sep 17 00:00:00 2001 From: Valentyn Nastenko Date: Thu, 15 Apr 2021 18:02:03 +0300 Subject: [PATCH 2/3] feat: added support for pushover service --- cmd/pushover.go | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ main.go | 1 + 4 files changed, 87 insertions(+) create mode 100644 cmd/pushover.go diff --git a/cmd/pushover.go b/cmd/pushover.go new file mode 100644 index 0000000..511bee8 --- /dev/null +++ b/cmd/pushover.go @@ -0,0 +1,83 @@ +package cmd + +import ( + "fmt" + "log" + "strings" + + "github.com/gregdel/pushover" + "github.com/urfave/cli/v2" +) + +// slackPingMe struct holds data parsed via flags for slack service. +type pushOver struct { + Token string + Recipient string + Message string + Title string +} + +// SendToPushOver parse values from *cli.context and return *cli.Command. +// Values include token, users, Message and Title. +// If multiple users are provided then the string is split with "," separator and +// each user is added to receiver. +func SendToPushOver() *cli.Command { + var pushOverOpts pushOver + return &cli.Command{ + Name: "pushover", + Usage: "Send message to pushover", + UsageText: "pingme pushover --token '123' --user '12345,567' --message 'some message'", + Description: `Pushover uses token to authenticate application and user token to send messages to the user. +All configuration options are also available via environment variables.`, + Flags: []cli.Flag{ + &cli.StringFlag{ + Destination: &pushOverOpts.Token, + Name: "token", + Aliases: []string{"t"}, + Required: true, + Usage: "Token of pushover application used for authenticate application.", + EnvVars: []string{"PUSHOVER_TOKEN"}, + }, + &cli.StringFlag{ + Destination: &pushOverOpts.Recipient, + Name: "user", + Required: true, + Aliases: []string{"u"}, + Usage: "User token used for sending message to user,if sending to multiple userss separate with ','.", + EnvVars: []string{"PUSHOVER_USER"}, + }, + &cli.StringFlag{ + Destination: &pushOverOpts.Message, + Name: "msg", + Aliases: []string{"m"}, + Usage: "Message content.", + EnvVars: []string{"PUSHOVER_MESSAGE"}, + }, + &cli.StringFlag{ + Destination: &pushOverOpts.Title, + Name: "title", + Value: TimeValue, + Usage: "Title of the message.", + EnvVars: []string{"PUSHOVER_TITLE"}, + }, + }, + Action: func(ctx *cli.Context) error { + app := pushover.New(pushOverOpts.Token) + message := pushover.NewMessageWithTitle(pushOverOpts.Message, pushOverOpts.Title) + users := strings.Split(pushOverOpts.Recipient, ",") + + for _, v := range users { + if len(v) == 0 { + return fmt.Errorf(EmptyChannel) + } + recipient := pushover.NewRecipient(v) + responsePushOver, err := app.SendMessage(message, recipient) + if err != nil { + return err + } + log.Printf("Successfully sent!\n%v\n", responsePushOver) + } + return nil + }, + } +} diff --git a/go.mod b/go.mod index 11285ee..92ba9aa 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.16 require ( github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect + github.com/gregdel/pushover v0.0.0-20210216095829-2131362cb888 github.com/nikoksr/notify v0.15.0 github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/urfave/cli/v2 v2.3.0 diff --git a/go.sum b/go.sum index 6e77a5e..5df3046 100644 --- a/go.sum +++ b/go.sum @@ -79,6 +79,8 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gregdel/pushover v0.0.0-20210216095829-2131362cb888 h1:rnBK/Xp+eaxlNrbMRoBTQ/m5c+jq41NSmqgFscNH7zY= +github.com/gregdel/pushover v0.0.0-20210216095829-2131362cb888/go.mod h1:EcaO66Nn1StkpEm1iKtBTV3d2A16SoMsVER1PthX7to= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= diff --git a/main.go b/main.go index 8420f54..10b8a29 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ RocketChat, Discord, Microsoft Teams and email address.` cmd.SendToSlack(), cmd.SendToDiscord(), cmd.SendToTeams(), + cmd.SendToPushOver(), cmd.SendToEmail(), } From 150e3d424a393ab76ea6eae840bf475aa83ea00b Mon Sep 17 00:00:00 2001 From: Valentyn Nastenko Date: Thu, 15 Apr 2021 19:27:25 +0300 Subject: [PATCH 3/3] fix: fixed some mistakes in pushover service --- cmd/pushover.go | 2 +- main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/pushover.go b/cmd/pushover.go index 511bee8..cee8707 100644 --- a/cmd/pushover.go +++ b/cmd/pushover.go @@ -9,7 +9,7 @@ import ( "github.com/urfave/cli/v2" ) -// slackPingMe struct holds data parsed via flags for slack service. +// pushOver struct holds data parsed via flags for pushover service type pushOver struct { Token string Recipient string diff --git a/main.go b/main.go index 10b8a29..3249f5b 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ func main() { app.Description = `PingMe is a CLI tool which provides the ability to send messages or alerts to multiple messaging platforms and also email, everything is configurable via environment variables and command line switches.Currently supported platforms include Slack, Telegram, -RocketChat, Discord, Microsoft Teams and email address.` +RocketChat, Discord, Pushover, Microsoft Teams and email address.` // app.Commands contains the subcommands as functions which return []*cli.Command. app.Commands = []*cli.Command{ cmd.SendToTelegram(),