feat: added support for pushover service

pull/5/head
Valentyn Nastenko 4 years ago
parent 61d0bc0138
commit 5377dac6ef

@ -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
},
}
}

@ -4,6 +4,7 @@ go 1.16
require ( require (
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect 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/nikoksr/notify v0.15.0
github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/urfave/cli/v2 v2.3.0 github.com/urfave/cli/v2 v2.3.0

@ -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.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= 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/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/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 v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=

@ -28,6 +28,7 @@ RocketChat, Discord, Microsoft Teams and email address.`
cmd.SendToSlack(), cmd.SendToSlack(),
cmd.SendToDiscord(), cmd.SendToDiscord(),
cmd.SendToTeams(), cmd.SendToTeams(),
cmd.SendToPushOver(),
cmd.SendToEmail(), cmd.SendToEmail(),
} }

Loading…
Cancel
Save