Skip to content

Commit

Permalink
Merge pull request #23 from kha7iq/add-support-for-pushbullet
Browse files Browse the repository at this point in the history
feat(service): add support for pushbullet
  • Loading branch information
kha7iq authored Apr 27, 2021
2 parents 11ca633 + 575cd2e commit efdbe12
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 42 deletions.
3 changes: 0 additions & 3 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ archives:
format_overrides:
- goos: windows
format: zip
files:
- README.md
- LICENSE.md

brews:
- tap:
Expand Down
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
</p>

<p align="center">
<a href="#about">About</a> •
<a href="https://kha7iq.github.io/pingme">Documentation</a> •
<a href="#supported-services">Supported Services</a> •
<a href="#install">Install</a> •
<a href="#github-action">Github Action</a> •
<a href="#configuration">Configuration</a> •
<a href="#contributing">Contributing</a> •
<a href="#show-your-support">Show Your Support</a>
<a href="#show-your-support">Show Your Support</a>
</p>

---
Expand All @@ -45,28 +44,36 @@ And i can ship it everywhere with ease.
Hence, the birth of PingMe.

Everything is configurable via environment variables, and you can simply export the logs or messages to a variable which will be sent
as message. And most of all this serves as a swiss army knife sort of tool which supports multiple platforms.
as message, and most of all this serves as a swiss army knife sort of tool which supports multiple platforms.



## Supported services
- *Discord*
- *Email*
- *Microsoft Teams*
- *Mattermost*
- *Pushover*
- *Pushbullet*
- *RocketChat*
- *Slack*
- *Telegram*
- *Pushover*
- *Mattermost*


## Install

### Linux & MacOs
### MacOS & Linux Homebrew
```bash
brew install kha7iq/tap/pingme
```

## Linux Binary
```bash
wget -q https://github.com/kha7iq/pingme/releases/download/v0.1.6/pingme_Linux_x86_64.tar.gz
tar -xf pingme_Linux_x86_64.tar.gz
chmod +x pingme
sudo mv pingme /usr/local/bin/pingme
```

### Go Get
```bash
go get -u github.com/kha7iq/pingme
Expand All @@ -91,7 +98,7 @@ Docker Registry
```bash
docker pull khaliq/pingme:latest
```
Gighub Registry
Github Registry
```bash
docker pull ghcr.io/kha7iq/pingme:latest
```
Expand Down Expand Up @@ -132,6 +139,7 @@ COMMANDS:
pushover Send message to pushover
email Send an email
mattermost Send message to mattermost
pushbullet Send message to pushbullet
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
Expand Down
1 change: 0 additions & 1 deletion cmd/mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ You can specify multiple channels by separating the value with ','.`,

// toJson takes strings and convert them to json byte array
func toJson(channel string, msg string) ([]byte, error) {

m := make(map[string]string, 2)
m["channel_id"] = channel
m["message"] = msg
Expand Down
137 changes: 137 additions & 0 deletions cmd/pushbullet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package cmd

import (
"context"
"fmt"
"log"
"strings"

"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
}

// SendToPushBullet 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 {
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: 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 fmt.Errorf(EmptyChannel)
}
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 fmt.Errorf(EmptyChannel)
}
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
},
}
}
9 changes: 5 additions & 4 deletions docs/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,25 @@
## About

**PingMe** is a personal project to satisfy my needs of having alerts, most major platforms have integration to send alerts
but its not always useful, either you are stuck with one particular platform, or you have to do alot of integrations. I needed a small app
but it's not always useful, either you are stuck with one particular platform, or you have to do alot of integrations. I needed a small app
which i can just call from my backup scripts, cron jobs, CI/CD pipelines or from anywhere to send a message with particular information.
And i can ship it everywhere with ease.
Hence, the birth of PingMe.

Everything is configurable via environment variables, and you can simply export the logs or messages to a variable which will be sent
as message. And most of all this serves as a swiss army knife sort of tool which supports multiple platforms.
as message, and most of all this serves as a swiss army knife sort of tool which supports multiple platforms.


## Supported services
- *Discord*
- *Email*
- *Microsoft Teams*
- *Mattermost*
- *Pushover*
- *Pushbullet*
- *RocketChat*
- *Slack*
- *Telegram*
- *Pushover*
- *Mattermost*



Expand Down
14 changes: 11 additions & 3 deletions docs/install.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@

## Linux & MacOs
## MacOS & Linux Homebrew
```bash
brew install kha7iq/tap/pingme
```

## Linux Binary
```bash
wget -q https://github.com/kha7iq/pingme/releases/download/v0.1.6/pingme_Linux_x86_64.tar.gz
tar -xf pingme_Linux_x86_64.tar.gz
chmod +x pingme
sudo mv
```

## Go Get
```bash
go get -u github.com/kha7iq/pingme
Expand All @@ -29,7 +37,7 @@ Checkout [release](https://github.com/kha7iq/pingme/releases) page for available
```bash
docker pull khaliq/pingme:latest
```
- Github Registry
- GitHub Registry
```bash
docker pull ghcr.io/kha7iq/pingme:latest
```
Expand All @@ -39,7 +47,7 @@ docker run ghcr.io/kha7iq/pingme:latest
```


## Github Action
## GitHub Action
A github action is also available now for this app, you can find it on [Github Market Place](https://github.com/marketplace/actions/pingme-action) or from this [repository](https://github.com/kha7iq/pingme-action) on github.

Usage examples for workflow are available in the repo.
Loading

0 comments on commit efdbe12

Please sign in to comment.