From 9b5027207d0311b7e8a8623af23b5aab49ddc09a Mon Sep 17 00:00:00 2001 From: kha7iq Date: Thu, 29 Apr 2021 23:27:01 +0800 Subject: [PATCH 1/6] docs: add minor fixes --- CONTRIBUTING.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fa10bfc..2ee5658 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,19 +4,20 @@ possible. ## Project structure -- `main` - Contains definitions for the underlying notification services. - - `cmd/discord` - Discord notification service. - - `cmd/email` - Email notification service. - - `cmd/msteams` - Microsoft Teams notification service. - - `cmd/rocketchat` - RocketChat notification service. - - `cmd/slack` - Slack notification service. - - `cmd/telegram` - Telegram notification service +- `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 documentaiton to `services.md`. + `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 install instructions for different packages. + - `install.md` Contains the installation instructions for different packages. - Checking Locally - Docsify is used for documentation rendering from markdown, you can download From 9ebc8405d097cb119aa57b71b89aa21f3b9e2bd7 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Thu, 29 Apr 2021 23:28:10 +0800 Subject: [PATCH 2/6] docs: add minor fixes --- CODE_OF_CONDUCT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 5c07c54..b4df6c3 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -3,7 +3,7 @@ ## Our Pledge 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 size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal From b59578d9900755a75ae17edcc0ab70a20e93f91c Mon Sep 17 00:00:00 2001 From: kha7iq Date: Thu, 29 Apr 2021 23:29:04 +0800 Subject: [PATCH 3/6] docs: add contributation links --- docs/_sidebar.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/_sidebar.md b/docs/_sidebar.md index aee2dc3..a7e297e 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -3,4 +3,5 @@ * [Home](/) * [Installation](install.md) * [Services & Usage](services.md) +* [Contribution](contribution.md) \ No newline at end of file From 5d9ba57a77e40fac14dc72fde5790633c2578b24 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Thu, 29 Apr 2021 23:30:06 +0800 Subject: [PATCH 4/6] docs: add contributation guide --- docs/contribution.md | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 docs/contribution.md diff --git a/docs/contribution.md b/docs/contribution.md new file mode 100644 index 0000000..2ee5658 --- /dev/null +++ b/docs/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 + + []: + │ │ │ + │ │ └─> 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. From 158452591ebc6c9a5a95d5ba758bc5c7771b9acc Mon Sep 17 00:00:00 2001 From: kha7iq Date: Thu, 29 Apr 2021 23:30:32 +0800 Subject: [PATCH 5/6] docs: update links --- docs/home.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/home.md b/docs/home.md index d0cb0e4..adc5244 100644 --- a/docs/home.md +++ b/docs/home.md @@ -61,7 +61,7 @@ as message, and most of all this serves as a swiss army knife sort of tool which ## Contributing -Contributions, issues and feature requests are welcome!
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!
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 -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. From f1bdc11693dc191f0c20af877c6ce1ab3208bb70 Mon Sep 17 00:00:00 2001 From: kha7iq Date: Thu, 29 Apr 2021 23:33:17 +0800 Subject: [PATCH 6/6] refactor: restructure project for better integration of new services --- main.go | 30 ++++++++++++++--------- {cmd => service/discord}/discord.go | 12 +++++---- {cmd => service/email}/email.go | 13 +++++----- service/helpers/helper.go | 13 ++++++++++ {cmd => service/mattermost}/mattermost.go | 12 +++++---- {cmd => service/msteams}/msteams.go | 13 +++++----- {cmd => service/pushbullet}/pushbullet.go | 15 ++++++------ {cmd => service/pushover}/pushover.go | 13 +++++----- {cmd => service/rocketchat}/rocketchat.go | 19 +++++--------- {cmd => service/slack}/slack.go | 13 +++++----- {cmd => service/telegram}/telegram.go | 13 +++++----- 11 files changed, 95 insertions(+), 71 deletions(-) rename {cmd => service/discord}/discord.go (91%) rename {cmd => service/email}/email.go (94%) create mode 100644 service/helpers/helper.go rename {cmd => service/mattermost}/mattermost.go (96%) rename {cmd => service/msteams}/msteams.go (90%) rename {cmd => service/pushbullet}/pushbullet.go (93%) rename {cmd => service/pushover}/pushover.go (91%) rename {cmd => service/rocketchat}/rocketchat.go (88%) rename {cmd => service/slack}/slack.go (91%) rename {cmd => service/telegram}/telegram.go (91%) diff --git a/main.go b/main.go index e789cde..a64d89c 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,15 @@ import ( "log" "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" ) @@ -12,7 +20,7 @@ import ( // Version variable is used for semVer var Version string -// main with combile all the function into commands +// main with combine all the function into commands func main() { app := cli.NewApp() 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.` // app.Commands contains the subcommands as functions which return []*cli.Command. app.Commands = []*cli.Command{ - cmd.SendToTelegram(), - cmd.SendToRocketChat(), - cmd.SendToSlack(), - cmd.SendToDiscord(), - cmd.SendToTeams(), - cmd.SendToPushOver(), - cmd.SendToEmail(), - cmd.SendToMattermost(), - cmd.SendToPushBullet(), + telegram.Send(), + rocketchat.Send(), + slack.Send(), + discord.Send(), + msteams.Send(), + pushover.Send(), + email.Send(), + mattermost.Send(), + pushbullet.Send(), } err := app.Run(os.Args) diff --git a/cmd/discord.go b/service/discord/discord.go similarity index 91% rename from cmd/discord.go rename to service/discord/discord.go index 964fb31..1b654c1 100644 --- a/cmd/discord.go +++ b/service/discord/discord.go @@ -1,4 +1,4 @@ -package cmd +package discord import ( "context" @@ -6,6 +6,8 @@ import ( "log" "strings" + "github.com/kha7iq/pingme/service/helpers" + "github.com/nikoksr/notify" "github.com/nikoksr/notify/service/discord" "github.com/urfave/cli/v2" @@ -19,11 +21,11 @@ type discordPingMe struct { 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. // If multiple channels are provided then the string is split with "," separator and // each channelID is added to receiver. -func SendToDiscord() *cli.Command { +func Send() *cli.Command { var discordOpts discordPingMe return &cli.Command{ Name: "discord", @@ -56,7 +58,7 @@ All configuration options are also available via environment variables.`, &cli.StringFlag{ Destination: &discordOpts.Title, Name: "title", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Title of the message.", EnvVars: []string{"DISCORD_MSG_TITLE"}, }, @@ -72,7 +74,7 @@ All configuration options are also available via environment variables.`, chn := strings.Split(discordOpts.Channel, ",") for _, v := range chn { if len(v) <= 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } discordSvc.AddReceivers(v) diff --git a/cmd/email.go b/service/email/email.go similarity index 94% rename from cmd/email.go rename to service/email/email.go index fda5267..aae64e2 100644 --- a/cmd/email.go +++ b/service/email/email.go @@ -1,11 +1,12 @@ -package cmd +package email import ( "context" - "fmt" "log" "strings" + "github.com/kha7iq/pingme/service/helpers" + "github.com/nikoksr/notify" "github.com/nikoksr/notify/service/mail" "github.com/urfave/cli/v2" @@ -23,12 +24,12 @@ type email struct { 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 // 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 // each ReceiverAddress is added to receiver. -func SendToEmail() *cli.Command { +func Send() *cli.Command { var emailOpts email return &cli.Command{ Name: "email", @@ -98,7 +99,7 @@ All configuration options are also available via environment variables.`, &cli.StringFlag{ Destination: &emailOpts.Subject, Name: "sub", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Subject of the email", EnvVars: []string{"EMAIL_SUBJECT"}, }, @@ -111,7 +112,7 @@ All configuration options are also available via environment variables.`, chn := strings.Split(emailOpts.ReceiverAddress, ",") for _, v := range chn { if len(v) <= 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } emailSvc.AddReceivers(v) diff --git a/service/helpers/helper.go b/service/helpers/helper.go new file mode 100644 index 0000000..2779475 --- /dev/null +++ b/service/helpers/helper.go @@ -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) +) diff --git a/cmd/mattermost.go b/service/mattermost/mattermost.go similarity index 96% rename from cmd/mattermost.go rename to service/mattermost/mattermost.go index 449775a..bc8566d 100644 --- a/cmd/mattermost.go +++ b/service/mattermost/mattermost.go @@ -1,4 +1,4 @@ -package cmd +package mattermost import ( "bytes" @@ -9,6 +9,8 @@ import ( "strings" "time" + "github.com/kha7iq/pingme/service/helpers" + "github.com/urfave/cli/v2" ) @@ -47,11 +49,11 @@ type matterMostResponse struct { 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. // If multiple channel ids are provided then the string is split with "," separator and // message is sent to each channel. -func SendToMattermost() *cli.Command { +func Send() *cli.Command { var mattermostOpts matterMost return &cli.Command{ Name: "mattermost", @@ -87,7 +89,7 @@ You can specify multiple channels by separating the value with ','.`, &cli.StringFlag{ Destination: &mattermostOpts.Title, Name: "title", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Title of the message.", EnvVars: []string{"MATTERMOST_TITLE"}, }, @@ -126,7 +128,7 @@ You can specify multiple channels by separating the value with ','.`, ids := strings.Split(mattermostOpts.ChanIDs, ",") for _, v := range ids { if len(v) == 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } jsonData, err := toJSON(v, fullMessage) diff --git a/cmd/msteams.go b/service/msteams/msteams.go similarity index 90% rename from cmd/msteams.go rename to service/msteams/msteams.go index d0fac89..e109441 100644 --- a/cmd/msteams.go +++ b/service/msteams/msteams.go @@ -1,11 +1,12 @@ -package cmd +package msteams import ( "context" - "fmt" "log" "strings" + "github.com/kha7iq/pingme/service/helpers" + "github.com/nikoksr/notify" msteams2 "github.com/nikoksr/notify/service/msteams" "github.com/urfave/cli/v2" @@ -18,11 +19,11 @@ type msTeams struct { 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. // If multiple webhooks are provided then the string is split with "," separator and // each webhook is added to receiver. -func SendToTeams() *cli.Command { +func Send() *cli.Command { var msTeamOpt msTeams return &cli.Command{ Name: "teams", @@ -48,7 +49,7 @@ you can add permissions for multiple channels to single webhook.`, &cli.StringFlag{ Destination: &msTeamOpt.Title, Name: "title", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Title of the message.", EnvVars: []string{"TEAMS_MSG_TITLE"}, }, @@ -60,7 +61,7 @@ you can add permissions for multiple channels to single webhook.`, chn := strings.Split(msTeamOpt.Webhook, ",") for _, v := range chn { if len(v) <= 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } teamsSvc.AddReceivers(v) } diff --git a/cmd/pushbullet.go b/service/pushbullet/pushbullet.go similarity index 93% rename from cmd/pushbullet.go rename to service/pushbullet/pushbullet.go index 6477ee4..a358c0a 100644 --- a/cmd/pushbullet.go +++ b/service/pushbullet/pushbullet.go @@ -1,11 +1,12 @@ -package cmd +package pushbullet import ( "context" - "fmt" "log" "strings" + "github.com/kha7iq/pingme/service/helpers" + "github.com/nikoksr/notify" "github.com/nikoksr/notify/service/pushbullet" "github.com/urfave/cli/v2" @@ -21,11 +22,11 @@ type pushBullet struct { 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. // If multiple devices are provided they the string is split with "," separator and // each device is added to receiver. -func SendToPushBullet() *cli.Command { +func Send() *cli.Command { var pushBulletOpts pushBullet return &cli.Command{ Name: "pushbullet", @@ -68,7 +69,7 @@ Multiple device nicknames or numbers can be used separated by comma.`, &cli.StringFlag{ Destination: &pushBulletOpts.Title, Name: "title", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Title of the message.", EnvVars: []string{"PUSHBULLET_TITLE"}, }, @@ -92,7 +93,7 @@ Multiple device nicknames or numbers can be used separated by comma.`, devices := strings.Split(pushBulletOpts.PhoneNumber, ",") for _, v := range devices { if len(v) <= 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } pushBulletSmsSvc.AddReceivers(v) @@ -112,7 +113,7 @@ Multiple device nicknames or numbers can be used separated by comma.`, devices := strings.Split(pushBulletOpts.Device, ",") for _, v := range devices { if len(v) <= 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } pushBulletSvc.AddReceivers(v) } diff --git a/cmd/pushover.go b/service/pushover/pushover.go similarity index 91% rename from cmd/pushover.go rename to service/pushover/pushover.go index dfed0e7..3d4adb1 100644 --- a/cmd/pushover.go +++ b/service/pushover/pushover.go @@ -1,10 +1,11 @@ -package cmd +package pushover import ( - "fmt" "log" "strings" + "github.com/kha7iq/pingme/service/helpers" + "github.com/gregdel/pushover" "github.com/urfave/cli/v2" ) @@ -17,11 +18,11 @@ type pushOver struct { 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. // If multiple users are provided then the string is split with "," separator and // each user is added to receiver. -func SendToPushOver() *cli.Command { +func Send() *cli.Command { var pushOverOpts pushOver return &cli.Command{ Name: "pushover", @@ -56,7 +57,7 @@ All configuration options are also available via environment variables.`, &cli.StringFlag{ Destination: &pushOverOpts.Title, Name: "title", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Title of the message.", EnvVars: []string{"PUSHOVER_TITLE"}, }, @@ -68,7 +69,7 @@ All configuration options are also available via environment variables.`, for _, v := range users { if len(v) == 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } recipient := pushover.NewRecipient(v) responsePushOver, err := app.SendMessage(message, recipient) diff --git a/cmd/rocketchat.go b/service/rocketchat/rocketchat.go similarity index 88% rename from cmd/rocketchat.go rename to service/rocketchat/rocketchat.go index 5ed4318..7efcfba 100644 --- a/cmd/rocketchat.go +++ b/service/rocketchat/rocketchat.go @@ -1,11 +1,10 @@ -package cmd +package rocketchat import ( "context" - "fmt" "strings" - "time" + "github.com/kha7iq/pingme/service/helpers" "github.com/nikoksr/notify" "github.com/nikoksr/notify/service/rocketchat" "github.com/urfave/cli/v2" @@ -21,17 +20,11 @@ type rocketChat struct { Scheme string } -var ( - // 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. +// Send parse values from *cli.context and return *cli.Command. // Values include rocketchat token, , UserId, channelIDs, ServerURL, Scheme, Message and Title. // If multiple channels are provided then the string is split with "," separator and // each channelID is added to receiver. -func SendToRocketChat() *cli.Command { +func Send() *cli.Command { var rocketChatOpts rocketChat return &cli.Command{ Name: "rocketchat", @@ -90,7 +83,7 @@ All configuration options are also available via environment variables.`, &cli.StringFlag{ Destination: &rocketChatOpts.Title, Name: "title", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Title of the message", EnvVars: []string{"ROCKETCHAT_TITLE"}, }, @@ -106,7 +99,7 @@ All configuration options are also available via environment variables.`, chn := strings.Split(rocketChatOpts.Channel, ",") for _, v := range chn { if len(v) <= 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } rocketChatSvc.AddReceivers(v) diff --git a/cmd/slack.go b/service/slack/slack.go similarity index 91% rename from cmd/slack.go rename to service/slack/slack.go index d47d77e..4cc5709 100644 --- a/cmd/slack.go +++ b/service/slack/slack.go @@ -1,11 +1,12 @@ -package cmd +package slack import ( "context" - "fmt" "log" "strings" + "github.com/kha7iq/pingme/service/helpers" + "github.com/nikoksr/notify" "github.com/nikoksr/notify/service/slack" "github.com/urfave/cli/v2" @@ -19,11 +20,11 @@ type slackPingMe struct { 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. // If multiple channels are provided then the string is split with "," separator and // each channelID is added to receiver. -func SendToSlack() *cli.Command { +func Send() *cli.Command { var slackOpts slackPingMe return &cli.Command{ Name: "slack", @@ -59,7 +60,7 @@ All configuration options are also available via environment variables.`, &cli.StringFlag{ Destination: &slackOpts.Title, Name: "title", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Title of the message.", EnvVars: []string{"SLACK_MSG_TITLE"}, }, @@ -70,7 +71,7 @@ All configuration options are also available via environment variables.`, chn := strings.Split(slackOpts.Channel, ",") for _, v := range chn { if len(v) <= 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } slackSvc.AddReceivers(v) diff --git a/cmd/telegram.go b/service/telegram/telegram.go similarity index 91% rename from cmd/telegram.go rename to service/telegram/telegram.go index 8e1475f..ecd5c21 100644 --- a/cmd/telegram.go +++ b/service/telegram/telegram.go @@ -1,12 +1,13 @@ -package cmd +package telegram import ( "context" - "fmt" "log" "strconv" "strings" + "github.com/kha7iq/pingme/service/helpers" + "github.com/nikoksr/notify" "github.com/nikoksr/notify/service/telegram" "github.com/urfave/cli/v2" @@ -20,11 +21,11 @@ type teleGram struct { 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. // If multiple channels are provided they the string is split with "," separator and // each channelID is added to receiver. -func SendToTelegram() *cli.Command { +func Send() *cli.Command { var telegramOpts teleGram return &cli.Command{ Name: "telegram", @@ -60,7 +61,7 @@ All configuration options are also available via environment variables.`, &cli.StringFlag{ Destination: &telegramOpts.Title, Name: "title", - Value: TimeValue, + Value: helpers.TimeValue, Usage: "Title of the message.", EnvVars: []string{"TELEGRAM_TITLE"}, }, @@ -75,7 +76,7 @@ All configuration options are also available via environment variables.`, chn := strings.Split(telegramOpts.Channel, ",") for _, v := range chn { if len(v) <= 0 { - return fmt.Errorf(EmptyChannel) + return helpers.ErrChannel } k, errStr := strconv.Atoi(v) if errStr != nil {