Merge pull request #26 from kha7iq/refactor-for-testing

Refactor for better integration of new services
pull/28/head
Khaliq 4 years ago committed by GitHub
commit 90b4bf96bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,7 @@
## Our Pledge ## Our Pledge
In the interest of fostering an open and welcoming environment, we as In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and contributors and maintainers pledge to making participation in our project, and
our community a harassment-free experience for everyone, regardless of age, body our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression, size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal level of experience, education, socio-economic status, nationality, personal

@ -4,19 +4,20 @@ possible.
## Project structure ## Project structure
- `main` - Contains definitions for the underlying notification services. - `service` - Contains definitions for the underlying notification services.
- `cmd/discord` - Discord notification service. - `service/discord` - Discord notification service.
- `cmd/email` - Email notification service. - `service/email` - Email notification service.
- `cmd/msteams` - Microsoft Teams notification service. - `service/msteams` - Microsoft Teams notification service.
- `cmd/rocketchat` - RocketChat notification service. - `service/rocketchat` - RocketChat notification service.
- `cmd/slack` - Slack notification service. - `service/slack` - Slack notification service.
- `cmd/telegram` - Telegram notification service - `service/telegram` - Telegram notification service.
- `service/pushover` - Pushover Notification service.
- Documentation - Documentation
`docs` - Contains the documentation in markdown format. `docs` - Contains the documentation in Markdown format.
- `services.md` If you are adding a new service please add documentaiton to `services.md`. - `services.md` If you are adding a new service please add documentation to `services.md`.
- `home.md` Is the main page rendered when docs website is loaded. - `home.md` Is the main page rendered when docs website is loaded.
- `install.md` Contains the install instructions for different packages. - `install.md` Contains the installation instructions for different packages.
- Checking Locally - Checking Locally
- Docsify is used for documentation rendering from markdown, you can download - Docsify is used for documentation rendering from markdown, you can download

@ -3,4 +3,5 @@
* [Home](/) * [Home](/)
* [Installation](install.md) * [Installation](install.md)
* [Services & Usage](services.md) * [Services & Usage](services.md)
* [Contribution](contribution.md)

@ -0,0 +1,73 @@
## Contributing to PingMe
We want to make contributing to this project as easy and transparent as
possible.
## Project structure
- `service` - Contains definitions for the underlying notification services.
- `service/discord` - Discord notification service.
- `service/email` - Email notification service.
- `service/msteams` - Microsoft Teams notification service.
- `service/rocketchat` - RocketChat notification service.
- `service/slack` - Slack notification service.
- `service/telegram` - Telegram notification service.
- `service/pushover` - Pushover Notification service.
- Documentation
`docs` - Contains the documentation in Markdown format.
- `services.md` If you are adding a new service please add documentation to `services.md`.
- `home.md` Is the main page rendered when docs website is loaded.
- `install.md` Contains the installation instructions for different packages.
- Checking Locally
- Docsify is used for documentation rendering from markdown, you can download
the cli and test locally before opening a pull request.
Install
```bash
npm i docsify-cli -g
# yarn global add docsify-cli
```
Serve locally
```bash
docsify serve docs
```
## Commits
Commit messages should be well formatted, and to make that "standardized", we
are using Conventional Commits.
```shell
<type>[<scope>]: <short summary>
│ │ │
│ │ └─> Summary in present tense. Not capitalized. No period at the end.
│ │
│ └─> Scope (optional): eg. common, compiler, authentication, core
└─> Type: chore, docs, feat, fix, refactor, style, or test.
```
You can follow the documentation on
[their website](https://www.conventionalcommits.org).
## Pull Requests
We actively welcome your pull requests.
1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes (`make test`).
5. Make sure your code lints (`make lint`).
6. Make sure your code is well formatted (`make fmt`).
## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.
## License
By contributing to PingMe, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.

@ -61,7 +61,7 @@ as message, and most of all this serves as a swiss army knife sort of tool which
## Contributing ## Contributing
Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/kha7iq/pingme/issues). You can also take a look at the [contributing guide](https://github.com/kha7iq/pingme/blob/master/CONTRIBUTING.md). Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/kha7iq/pingme/issues). You can also take a look at the [contribution guide](contribution.md).
@ -73,6 +73,6 @@ Give a ⭐️ if you like this project!
## Disclaimer ## Disclaimer
Any misuse of this utilify is your own liability and responsibility and cannot be attributed to the authors of this library. See [license](LICENSE) for more. Any misuse of this utility is your own liability and responsibility and cannot be attributed to the authors of this library. See [license](https://github.com/kha7iq/pingme/blob/master/LICENSE.md) for more.
Spamming through the use of this library **may get you permanently banned** on most supported platforms. Spamming through the use of this library **may get you permanently banned** on most supported platforms.

@ -4,7 +4,15 @@ import (
"log" "log"
"os" "os"
"github.com/kha7iq/pingme/cmd" "github.com/kha7iq/pingme/service/discord"
"github.com/kha7iq/pingme/service/email"
"github.com/kha7iq/pingme/service/mattermost"
"github.com/kha7iq/pingme/service/msteams"
"github.com/kha7iq/pingme/service/pushbullet"
"github.com/kha7iq/pingme/service/pushover"
"github.com/kha7iq/pingme/service/rocketchat"
"github.com/kha7iq/pingme/service/slack"
"github.com/kha7iq/pingme/service/telegram"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -12,7 +20,7 @@ import (
// Version variable is used for semVer // Version variable is used for semVer
var Version string var Version string
// main with combile all the function into commands // main with combine all the function into commands
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "PingMe" app.Name = "PingMe"
@ -24,15 +32,15 @@ variables and command line switches.Currently supported platforms include Slack,
RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams and email address.` RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams and email address.`
// app.Commands contains the subcommands as functions which return []*cli.Command. // app.Commands contains the subcommands as functions which return []*cli.Command.
app.Commands = []*cli.Command{ app.Commands = []*cli.Command{
cmd.SendToTelegram(), telegram.Send(),
cmd.SendToRocketChat(), rocketchat.Send(),
cmd.SendToSlack(), slack.Send(),
cmd.SendToDiscord(), discord.Send(),
cmd.SendToTeams(), msteams.Send(),
cmd.SendToPushOver(), pushover.Send(),
cmd.SendToEmail(), email.Send(),
cmd.SendToMattermost(), mattermost.Send(),
cmd.SendToPushBullet(), pushbullet.Send(),
} }
err := app.Run(os.Args) err := app.Run(os.Args)

@ -1,4 +1,4 @@
package cmd package discord
import ( import (
"context" "context"
@ -6,6 +6,8 @@ import (
"log" "log"
"strings" "strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify" "github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/discord" "github.com/nikoksr/notify/service/discord"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -19,11 +21,11 @@ type discordPingMe struct {
Title string Title string
} }
// SendToDiscord parse values from *cli.context and return *cli.Command. // Send parse values from *cli.context and return *cli.Command.
// Values include discord bot token, userID, channelIDs, Message and Title. // Values include discord bot token, userID, channelIDs, Message and Title.
// If multiple channels are provided then the string is split with "," separator and // If multiple channels are provided then the string is split with "," separator and
// each channelID is added to receiver. // each channelID is added to receiver.
func SendToDiscord() *cli.Command { func Send() *cli.Command {
var discordOpts discordPingMe var discordOpts discordPingMe
return &cli.Command{ return &cli.Command{
Name: "discord", Name: "discord",
@ -56,7 +58,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &discordOpts.Title, Destination: &discordOpts.Title,
Name: "title", Name: "title",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Title of the message.", Usage: "Title of the message.",
EnvVars: []string{"DISCORD_MSG_TITLE"}, EnvVars: []string{"DISCORD_MSG_TITLE"},
}, },
@ -72,7 +74,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(discordOpts.Channel, ",") chn := strings.Split(discordOpts.Channel, ",")
for _, v := range chn { for _, v := range chn {
if len(v) <= 0 { if len(v) <= 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
discordSvc.AddReceivers(v) discordSvc.AddReceivers(v)

@ -1,11 +1,12 @@
package cmd package email
import ( import (
"context" "context"
"fmt"
"log" "log"
"strings" "strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify" "github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/mail" "github.com/nikoksr/notify/service/mail"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -23,12 +24,12 @@ type email struct {
Identity string Identity string
} }
// SendToEmail parse values from *cli.context and return *cli.Command. // Send parses values from *cli.context and return *cli.Command.
// SendAddress is used for authentication with smtp server, host and port is required // SendAddress is used for authentication with smtp server, host and port is required
// the default value for port is set to "587" and host as "smtp.gmail.com" // the default value for port is set to "587" and host as "smtp.gmail.com"
// If multiple ReceiverAddress are provided then the string value is split with "," separator and // If multiple ReceiverAddress are provided then the string value is split with "," separator and
// each ReceiverAddress is added to receiver. // each ReceiverAddress is added to receiver.
func SendToEmail() *cli.Command { func Send() *cli.Command {
var emailOpts email var emailOpts email
return &cli.Command{ return &cli.Command{
Name: "email", Name: "email",
@ -98,7 +99,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &emailOpts.Subject, Destination: &emailOpts.Subject,
Name: "sub", Name: "sub",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Subject of the email", Usage: "Subject of the email",
EnvVars: []string{"EMAIL_SUBJECT"}, EnvVars: []string{"EMAIL_SUBJECT"},
}, },
@ -111,7 +112,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(emailOpts.ReceiverAddress, ",") chn := strings.Split(emailOpts.ReceiverAddress, ",")
for _, v := range chn { for _, v := range chn {
if len(v) <= 0 { if len(v) <= 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
emailSvc.AddReceivers(v) emailSvc.AddReceivers(v)

@ -0,0 +1,13 @@
package helpers
import (
"errors"
"time"
)
var (
// ErrChannel variable holds default error message if no channel is provided.
ErrChannel = errors.New("target channel or id can not be empty")
// TimeValue holds current date and time in unix format.
TimeValue = "⏰ " + time.Now().Format(time.UnixDate)
)

@ -1,4 +1,4 @@
package cmd package mattermost
import ( import (
"bytes" "bytes"
@ -9,6 +9,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/kha7iq/pingme/service/helpers"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -47,11 +49,11 @@ type matterMostResponse struct {
Metadata struct{} `json:"metadata"` Metadata struct{} `json:"metadata"`
} }
// SendToMattermost parse values from *cli.context and return *cli.Command // Send parse values from *cli.context and return *cli.Command
// and send messages to target channels. // and send messages to target channels.
// If multiple channel ids are provided then the string is split with "," separator and // If multiple channel ids are provided then the string is split with "," separator and
// message is sent to each channel. // message is sent to each channel.
func SendToMattermost() *cli.Command { func Send() *cli.Command {
var mattermostOpts matterMost var mattermostOpts matterMost
return &cli.Command{ return &cli.Command{
Name: "mattermost", Name: "mattermost",
@ -87,7 +89,7 @@ You can specify multiple channels by separating the value with ','.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &mattermostOpts.Title, Destination: &mattermostOpts.Title,
Name: "title", Name: "title",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Title of the message.", Usage: "Title of the message.",
EnvVars: []string{"MATTERMOST_TITLE"}, EnvVars: []string{"MATTERMOST_TITLE"},
}, },
@ -126,7 +128,7 @@ You can specify multiple channels by separating the value with ','.`,
ids := strings.Split(mattermostOpts.ChanIDs, ",") ids := strings.Split(mattermostOpts.ChanIDs, ",")
for _, v := range ids { for _, v := range ids {
if len(v) == 0 { if len(v) == 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
jsonData, err := toJSON(v, fullMessage) jsonData, err := toJSON(v, fullMessage)

@ -1,11 +1,12 @@
package cmd package msteams
import ( import (
"context" "context"
"fmt"
"log" "log"
"strings" "strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify" "github.com/nikoksr/notify"
msteams2 "github.com/nikoksr/notify/service/msteams" msteams2 "github.com/nikoksr/notify/service/msteams"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -18,11 +19,11 @@ type msTeams struct {
Title string Title string
} }
// SendToTeams parse values from *cli.context and return *cli.Command. // Send parse values from *cli.context and return *cli.Command.
// Values include Ms Teams Webhook, Message and Title. // Values include Ms Teams Webhook, Message and Title.
// If multiple webhooks are provided then the string is split with "," separator and // If multiple webhooks are provided then the string is split with "," separator and
// each webhook is added to receiver. // each webhook is added to receiver.
func SendToTeams() *cli.Command { func Send() *cli.Command {
var msTeamOpt msTeams var msTeamOpt msTeams
return &cli.Command{ return &cli.Command{
Name: "teams", Name: "teams",
@ -48,7 +49,7 @@ you can add permissions for multiple channels to single webhook.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &msTeamOpt.Title, Destination: &msTeamOpt.Title,
Name: "title", Name: "title",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Title of the message.", Usage: "Title of the message.",
EnvVars: []string{"TEAMS_MSG_TITLE"}, EnvVars: []string{"TEAMS_MSG_TITLE"},
}, },
@ -60,7 +61,7 @@ you can add permissions for multiple channels to single webhook.`,
chn := strings.Split(msTeamOpt.Webhook, ",") chn := strings.Split(msTeamOpt.Webhook, ",")
for _, v := range chn { for _, v := range chn {
if len(v) <= 0 { if len(v) <= 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
teamsSvc.AddReceivers(v) teamsSvc.AddReceivers(v)
} }

@ -1,11 +1,12 @@
package cmd package pushbullet
import ( import (
"context" "context"
"fmt"
"log" "log"
"strings" "strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify" "github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/pushbullet" "github.com/nikoksr/notify/service/pushbullet"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -21,11 +22,11 @@ type pushBullet struct {
SMS bool SMS bool
} }
// SendToPushBullet parse values from *cli.context and return *cli.Command. // Send parse values from *cli.context and return *cli.Command.
// Values include pushbullet token, Device, phone number, Message and Title. // Values include pushbullet token, Device, phone number, Message and Title.
// If multiple devices are provided they the string is split with "," separator and // If multiple devices are provided they the string is split with "," separator and
// each device is added to receiver. // each device is added to receiver.
func SendToPushBullet() *cli.Command { func Send() *cli.Command {
var pushBulletOpts pushBullet var pushBulletOpts pushBullet
return &cli.Command{ return &cli.Command{
Name: "pushbullet", Name: "pushbullet",
@ -68,7 +69,7 @@ Multiple device nicknames or numbers can be used separated by comma.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &pushBulletOpts.Title, Destination: &pushBulletOpts.Title,
Name: "title", Name: "title",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Title of the message.", Usage: "Title of the message.",
EnvVars: []string{"PUSHBULLET_TITLE"}, EnvVars: []string{"PUSHBULLET_TITLE"},
}, },
@ -92,7 +93,7 @@ Multiple device nicknames or numbers can be used separated by comma.`,
devices := strings.Split(pushBulletOpts.PhoneNumber, ",") devices := strings.Split(pushBulletOpts.PhoneNumber, ",")
for _, v := range devices { for _, v := range devices {
if len(v) <= 0 { if len(v) <= 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
pushBulletSmsSvc.AddReceivers(v) pushBulletSmsSvc.AddReceivers(v)
@ -112,7 +113,7 @@ Multiple device nicknames or numbers can be used separated by comma.`,
devices := strings.Split(pushBulletOpts.Device, ",") devices := strings.Split(pushBulletOpts.Device, ",")
for _, v := range devices { for _, v := range devices {
if len(v) <= 0 { if len(v) <= 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
pushBulletSvc.AddReceivers(v) pushBulletSvc.AddReceivers(v)
} }

@ -1,10 +1,11 @@
package cmd package pushover
import ( import (
"fmt"
"log" "log"
"strings" "strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/gregdel/pushover" "github.com/gregdel/pushover"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -17,11 +18,11 @@ type pushOver struct {
Title string Title string
} }
// SendToPushOver parse values from *cli.context and return *cli.Command. // Send parse values from *cli.context and return *cli.Command.
// Values include token, users, Message and Title. // Values include token, users, Message and Title.
// If multiple users are provided then the string is split with "," separator and // If multiple users are provided then the string is split with "," separator and
// each user is added to receiver. // each user is added to receiver.
func SendToPushOver() *cli.Command { func Send() *cli.Command {
var pushOverOpts pushOver var pushOverOpts pushOver
return &cli.Command{ return &cli.Command{
Name: "pushover", Name: "pushover",
@ -56,7 +57,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &pushOverOpts.Title, Destination: &pushOverOpts.Title,
Name: "title", Name: "title",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Title of the message.", Usage: "Title of the message.",
EnvVars: []string{"PUSHOVER_TITLE"}, EnvVars: []string{"PUSHOVER_TITLE"},
}, },
@ -68,7 +69,7 @@ All configuration options are also available via environment variables.`,
for _, v := range users { for _, v := range users {
if len(v) == 0 { if len(v) == 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
recipient := pushover.NewRecipient(v) recipient := pushover.NewRecipient(v)
responsePushOver, err := app.SendMessage(message, recipient) responsePushOver, err := app.SendMessage(message, recipient)

@ -1,11 +1,10 @@
package cmd package rocketchat
import ( import (
"context" "context"
"fmt"
"strings" "strings"
"time"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify" "github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/rocketchat" "github.com/nikoksr/notify/service/rocketchat"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -21,17 +20,11 @@ type rocketChat struct {
Scheme string Scheme string
} }
var ( // Send parse values from *cli.context and return *cli.Command.
// EmptyChannel variable holds default error message if no channel is provided.
EmptyChannel = "channel name or id can not be empty"
TimeValue = "⏰ " + time.Now().Format(time.UnixDate)
)
// SendToRocketChat parse values from *cli.context and return *cli.Command.
// Values include rocketchat token, , UserId, channelIDs, ServerURL, Scheme, Message and Title. // Values include rocketchat token, , UserId, channelIDs, ServerURL, Scheme, Message and Title.
// If multiple channels are provided then the string is split with "," separator and // If multiple channels are provided then the string is split with "," separator and
// each channelID is added to receiver. // each channelID is added to receiver.
func SendToRocketChat() *cli.Command { func Send() *cli.Command {
var rocketChatOpts rocketChat var rocketChatOpts rocketChat
return &cli.Command{ return &cli.Command{
Name: "rocketchat", Name: "rocketchat",
@ -90,7 +83,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &rocketChatOpts.Title, Destination: &rocketChatOpts.Title,
Name: "title", Name: "title",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Title of the message", Usage: "Title of the message",
EnvVars: []string{"ROCKETCHAT_TITLE"}, EnvVars: []string{"ROCKETCHAT_TITLE"},
}, },
@ -106,7 +99,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(rocketChatOpts.Channel, ",") chn := strings.Split(rocketChatOpts.Channel, ",")
for _, v := range chn { for _, v := range chn {
if len(v) <= 0 { if len(v) <= 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
rocketChatSvc.AddReceivers(v) rocketChatSvc.AddReceivers(v)

@ -1,11 +1,12 @@
package cmd package slack
import ( import (
"context" "context"
"fmt"
"log" "log"
"strings" "strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify" "github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/slack" "github.com/nikoksr/notify/service/slack"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -19,11 +20,11 @@ type slackPingMe struct {
Title string Title string
} }
// SendToSlack parse values from *cli.context and return *cli.Command. // Send parse values from *cli.context and return *cli.Command.
// Values include slack token, channelIDs, Message and Title. // Values include slack token, channelIDs, Message and Title.
// If multiple channels are provided then the string is split with "," separator and // If multiple channels are provided then the string is split with "," separator and
// each channelID is added to receiver. // each channelID is added to receiver.
func SendToSlack() *cli.Command { func Send() *cli.Command {
var slackOpts slackPingMe var slackOpts slackPingMe
return &cli.Command{ return &cli.Command{
Name: "slack", Name: "slack",
@ -59,7 +60,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &slackOpts.Title, Destination: &slackOpts.Title,
Name: "title", Name: "title",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Title of the message.", Usage: "Title of the message.",
EnvVars: []string{"SLACK_MSG_TITLE"}, EnvVars: []string{"SLACK_MSG_TITLE"},
}, },
@ -70,7 +71,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(slackOpts.Channel, ",") chn := strings.Split(slackOpts.Channel, ",")
for _, v := range chn { for _, v := range chn {
if len(v) <= 0 { if len(v) <= 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
slackSvc.AddReceivers(v) slackSvc.AddReceivers(v)

@ -1,12 +1,13 @@
package cmd package telegram
import ( import (
"context" "context"
"fmt"
"log" "log"
"strconv" "strconv"
"strings" "strings"
"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify" "github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/telegram" "github.com/nikoksr/notify/service/telegram"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
@ -20,11 +21,11 @@ type teleGram struct {
Title string Title string
} }
// SendToTelegram parse values from *cli.context and return *cli.Command. // Send parse values from *cli.context and return *cli.Command.
// Values include telegram token, channelIDs, Message and Title. // Values include telegram token, channelIDs, Message and Title.
// If multiple channels are provided they the string is split with "," separator and // If multiple channels are provided they the string is split with "," separator and
// each channelID is added to receiver. // each channelID is added to receiver.
func SendToTelegram() *cli.Command { func Send() *cli.Command {
var telegramOpts teleGram var telegramOpts teleGram
return &cli.Command{ return &cli.Command{
Name: "telegram", Name: "telegram",
@ -60,7 +61,7 @@ All configuration options are also available via environment variables.`,
&cli.StringFlag{ &cli.StringFlag{
Destination: &telegramOpts.Title, Destination: &telegramOpts.Title,
Name: "title", Name: "title",
Value: TimeValue, Value: helpers.TimeValue,
Usage: "Title of the message.", Usage: "Title of the message.",
EnvVars: []string{"TELEGRAM_TITLE"}, EnvVars: []string{"TELEGRAM_TITLE"},
}, },
@ -75,7 +76,7 @@ All configuration options are also available via environment variables.`,
chn := strings.Split(telegramOpts.Channel, ",") chn := strings.Split(telegramOpts.Channel, ",")
for _, v := range chn { for _, v := range chn {
if len(v) <= 0 { if len(v) <= 0 {
return fmt.Errorf(EmptyChannel) return helpers.ErrChannel
} }
k, errStr := strconv.Atoi(v) k, errStr := strconv.Atoi(v)
if errStr != nil { if errStr != nil {
Loading…
Cancel
Save