mirror of https://github.com/kha7iq/pingme
commit
5a94dd9048
@ -0,0 +1,36 @@
|
|||||||
|
on: pull_request
|
||||||
|
|
||||||
|
env:
|
||||||
|
PUSHOVER_TOKEN: ${{ secrets.PUSHOVER_TOKEN }}
|
||||||
|
PUSHOVER_USER: ${{ secrets.PUSHOVER_USER }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint-code:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Perform Checks
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: v1.29
|
||||||
|
|
||||||
|
- name: Notify on failure
|
||||||
|
uses: kha7iq/pingme-action@v1
|
||||||
|
if: failure()
|
||||||
|
env:
|
||||||
|
PUSHOVER_TITLE: '🟢 New Request: ${{ github.ref }}'
|
||||||
|
PUSHOVER_MESSAGE: 'Event is triggerd by ${{ github.event_name }} Checks ❌ ${{ job.status }}'
|
||||||
|
with:
|
||||||
|
service: pushover
|
||||||
|
|
||||||
|
- name: Notify on success
|
||||||
|
uses: kha7iq/pingme-action@v1
|
||||||
|
if: success()
|
||||||
|
env:
|
||||||
|
PUSHOVER_TITLE: '🟢 New Request: ${{ github.ref }}'
|
||||||
|
PUSHOVER_MESSAGE: 'Event is triggerd by ${{ github.event_name }} Checks ✅ ${{ job.status }}'
|
||||||
|
with:
|
||||||
|
service: pushover
|
@ -0,0 +1,71 @@
|
|||||||
|
linters-settings:
|
||||||
|
depguard:
|
||||||
|
list-type: blacklist
|
||||||
|
funlen:
|
||||||
|
lines: 120
|
||||||
|
statements: 50
|
||||||
|
gci:
|
||||||
|
local-prefixes: github.com/golangci/golangci-lint
|
||||||
|
goconst:
|
||||||
|
min-len: 2
|
||||||
|
min-occurrences: 2
|
||||||
|
gocyclo:
|
||||||
|
min-complexity: 15
|
||||||
|
goimports:
|
||||||
|
local-prefixes: github.com/golangci/golangci-lint
|
||||||
|
golint:
|
||||||
|
min-confidence: 0
|
||||||
|
govet:
|
||||||
|
check-shadowing: true
|
||||||
|
settings:
|
||||||
|
printf:
|
||||||
|
funcs:
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
|
||||||
|
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
|
||||||
|
lll:
|
||||||
|
line-length: 140
|
||||||
|
maligned:
|
||||||
|
suggest-new: true
|
||||||
|
misspell:
|
||||||
|
locale: US
|
||||||
|
nolintlint:
|
||||||
|
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
|
||||||
|
allow-unused: false # report any unused nolint directives
|
||||||
|
require-explanation: false # don't require an explanation for nolint directives
|
||||||
|
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
|
||||||
|
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- bodyclose
|
||||||
|
- deadcode
|
||||||
|
- depguard
|
||||||
|
- dogsled
|
||||||
|
- errcheck
|
||||||
|
- funlen
|
||||||
|
- gochecknoinits
|
||||||
|
- goconst
|
||||||
|
- gocyclo
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- golint
|
||||||
|
- goprintffuncname
|
||||||
|
- gosec
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- lll
|
||||||
|
- misspell
|
||||||
|
- nakedret
|
||||||
|
- rowserrcheck
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- stylecheck
|
||||||
|
- typecheck
|
||||||
|
- unconvert
|
||||||
|
- unparam
|
||||||
|
- unused
|
||||||
|
- varcheck
|
||||||
|
- whitespace
|
@ -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.
|
@ -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)
|
||||||
|
)
|
@ -0,0 +1,136 @@
|
|||||||
|
package pushbullet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/kha7iq/pingme/service/helpers"
|
||||||
|
|
||||||
|
"github.com/nikoksr/notify"
|
||||||
|
"github.com/nikoksr/notify/service/pushbullet"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// pushBullet struct holds data parsed via flags for pushbullet service.
|
||||||
|
type pushBullet struct {
|
||||||
|
Token string
|
||||||
|
Message string
|
||||||
|
Title string
|
||||||
|
Device string
|
||||||
|
PhoneNumber string
|
||||||
|
SMS bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 Send() *cli.Command {
|
||||||
|
var pushBulletOpts pushBullet
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "pushbullet",
|
||||||
|
Usage: "Send message to pushbullet",
|
||||||
|
Description: `Pushbullet uses API token to authenticate & send messages to defined devices.
|
||||||
|
Multiple device nicknames or numbers can be used separated by comma.`,
|
||||||
|
UsageText: "pingme pushbullet --token '123' --device 'Web123, myAndroid' --msg 'some message'\n" +
|
||||||
|
"pingme pushbullet --token '123' --sms true --device 'Web123' --msg 'some message' --number '00123456789'",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &pushBulletOpts.Token,
|
||||||
|
Name: "token",
|
||||||
|
Aliases: []string{"t"},
|
||||||
|
Required: true,
|
||||||
|
Usage: "Token of pushbullet api used for sending message.",
|
||||||
|
EnvVars: []string{"PUSHBULLET_TOKEN"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &pushBulletOpts.Device,
|
||||||
|
Name: "device",
|
||||||
|
Aliases: []string{"d"},
|
||||||
|
Required: true,
|
||||||
|
Usage: "Device's nickname of pushbullet.",
|
||||||
|
EnvVars: []string{"PUSHBULLET_DEVICE"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &pushBulletOpts.PhoneNumber,
|
||||||
|
Name: "number",
|
||||||
|
Aliases: []string{"n"},
|
||||||
|
Usage: "Target phone number",
|
||||||
|
EnvVars: []string{"PUSHBULLET_NUMBER"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &pushBulletOpts.Message,
|
||||||
|
Name: "msg",
|
||||||
|
Aliases: []string{"m"},
|
||||||
|
Usage: "Message content.",
|
||||||
|
EnvVars: []string{"PUSHBULLET_MESSAGE"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &pushBulletOpts.Title,
|
||||||
|
Name: "title",
|
||||||
|
Value: helpers.TimeValue,
|
||||||
|
Usage: "Title of the message.",
|
||||||
|
EnvVars: []string{"PUSHBULLET_TITLE"},
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Destination: &pushBulletOpts.SMS,
|
||||||
|
Name: "sms",
|
||||||
|
Value: false,
|
||||||
|
Usage: "To send sms message set the value to 'true'",
|
||||||
|
EnvVars: []string{"PUSHBULLET_SMS"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) error {
|
||||||
|
notifier := notify.New()
|
||||||
|
|
||||||
|
switch pushBulletOpts.SMS {
|
||||||
|
case true:
|
||||||
|
pushBulletSmsSvc, err := pushbullet.NewSMS(pushBulletOpts.Token, pushBulletOpts.Device)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
devices := strings.Split(pushBulletOpts.PhoneNumber, ",")
|
||||||
|
for _, v := range devices {
|
||||||
|
if len(v) <= 0 {
|
||||||
|
return helpers.ErrChannel
|
||||||
|
}
|
||||||
|
pushBulletSmsSvc.AddReceivers(v)
|
||||||
|
|
||||||
|
notifier.UseServices(pushBulletSmsSvc)
|
||||||
|
|
||||||
|
if err := notifier.Send(
|
||||||
|
context.Background(),
|
||||||
|
pushBulletOpts.Title,
|
||||||
|
pushBulletOpts.Message,
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
pushBulletSvc := pushbullet.New(pushBulletOpts.Token)
|
||||||
|
|
||||||
|
devices := strings.Split(pushBulletOpts.Device, ",")
|
||||||
|
for _, v := range devices {
|
||||||
|
if len(v) <= 0 {
|
||||||
|
return helpers.ErrChannel
|
||||||
|
}
|
||||||
|
pushBulletSvc.AddReceivers(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
notifier.UseServices(pushBulletSvc)
|
||||||
|
|
||||||
|
if err := notifier.Send(
|
||||||
|
context.Background(),
|
||||||
|
pushBulletOpts.Title,
|
||||||
|
pushBulletOpts.Message,
|
||||||
|
); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Println("Successfully sent!")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,102 @@
|
|||||||
|
package twillio
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/kha7iq/pingme/service/helpers"
|
||||||
|
"github.com/sfreiberg/gotwilio"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Twillio struct holds data parsed via flags for the service
|
||||||
|
type Twillio struct {
|
||||||
|
Title string
|
||||||
|
Token string
|
||||||
|
AccountSid string
|
||||||
|
Sender string
|
||||||
|
Receiver string
|
||||||
|
Message string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send parse values from *cli.context and return *cli.Command
|
||||||
|
// and send messages to target numbers.
|
||||||
|
// If multiple receivers are provided then the string is split with "," separator and
|
||||||
|
// message is sent to each number.
|
||||||
|
func Send() *cli.Command {
|
||||||
|
var twillioOpts Twillio
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "twillio",
|
||||||
|
Usage: "Send sms via twillio",
|
||||||
|
UsageText: "pingme twillio --token 'tokenabc' --account 'sid123' " +
|
||||||
|
"--sender '+140001442' --receiver '+140001442'' --msg 'some message'",
|
||||||
|
Description: `Twillio provides ability to send sms to multiple numbers.
|
||||||
|
You can specify multiple receivers by separating the value with a comma.`,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &twillioOpts.Token,
|
||||||
|
Name: "token",
|
||||||
|
Aliases: []string{"t"},
|
||||||
|
Required: true,
|
||||||
|
Usage: "Auth token for twillio account.",
|
||||||
|
EnvVars: []string{"TWILLIO_TOKEN"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &twillioOpts.AccountSid,
|
||||||
|
Name: "account",
|
||||||
|
Required: true,
|
||||||
|
Aliases: []string{"a"},
|
||||||
|
Usage: "Twillio account sid",
|
||||||
|
EnvVars: []string{"TWILLIO_ACCOUNT_SID"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &twillioOpts.Message,
|
||||||
|
Name: "msg",
|
||||||
|
Aliases: []string{"m"},
|
||||||
|
Usage: "Message content.",
|
||||||
|
EnvVars: []string{"TWILLIO_MESSAGE"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &twillioOpts.Title,
|
||||||
|
Name: "title",
|
||||||
|
Usage: "Title of the message.",
|
||||||
|
EnvVars: []string{"TWILLIO_TITLE"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &twillioOpts.Sender,
|
||||||
|
Name: "sender",
|
||||||
|
Aliases: []string{"s"},
|
||||||
|
Usage: "Sender's phone number",
|
||||||
|
EnvVars: []string{"TWILLIO_SENDER"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Destination: &twillioOpts.Receiver,
|
||||||
|
Name: "receiver",
|
||||||
|
Aliases: []string{"r"},
|
||||||
|
Usage: "Receiver's phone number",
|
||||||
|
EnvVars: []string{"TWILLIO_RECEIVER"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) error {
|
||||||
|
client := gotwilio.NewTwilioClient(twillioOpts.AccountSid, twillioOpts.Token)
|
||||||
|
fullMessage := twillioOpts.Title + "\n" + twillioOpts.Message
|
||||||
|
|
||||||
|
numbers := strings.Split(twillioOpts.Receiver, ",")
|
||||||
|
for _, v := range numbers {
|
||||||
|
if len(v) == 0 {
|
||||||
|
return helpers.ErrChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
_, exception, err := client.SendSMS(twillioOpts.Sender, twillioOpts.Receiver, fullMessage, "", "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exception != nil {
|
||||||
|
return exception
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Println("Successfully sent!")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue