Skip to content

Commit

Permalink
Merge pull request #41 from servusDei2018/add-service-line
Browse files Browse the repository at this point in the history
feat(service): add service line
  • Loading branch information
kha7iq authored Jun 1, 2021
2 parents c3069f6 + 024b150 commit 3cfd2b2
Show file tree
Hide file tree
Showing 9 changed files with 452 additions and 29 deletions.
Binary file modified .github/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/img/pingme.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/_media/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/contribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ possible.
- `service/slack` - Slack notification service.
- `service/telegram` - Telegram notification service.
- `service/pushover` - Pushover Notification service.
- `service/line` - Line notification service.

### Documentation

Expand Down
1 change: 1 addition & 0 deletions docs/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ platforms.
- *Slack*
- *Telegram*
- *Twillio*
- *Line Messenger*

## Demo

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
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.17.0
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5
github.com/stretchr/testify v1.7.0
Expand Down
375 changes: 347 additions & 28 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/kha7iq/pingme/service/discord"
"github.com/kha7iq/pingme/service/email"
"github.com/kha7iq/pingme/service/line"
"github.com/kha7iq/pingme/service/mattermost"
"github.com/kha7iq/pingme/service/msteams"
"github.com/kha7iq/pingme/service/pushbullet"
Expand Down Expand Up @@ -48,6 +49,7 @@ RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams, Twillio,
twillio.Send(),
zulip.Send(),
mastodon.Send(),
line.Send(),
}

err := app.Run(os.Args)
Expand Down
100 changes: 100 additions & 0 deletions service/line/line.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package line

import (
"context"
"log"
"strings"

"github.com/kha7iq/pingme/service/helpers"
"github.com/nikoksr/notify"
"github.com/nikoksr/notify/service/line"
"github.com/urfave/cli/v2"
)

// Line struct holds data parsed via flags for the service
type Line struct {
Secret string
Token string
Message string
Receivers string
Title string
}

// Send parses values from *cli.context and returns a *cli.Command.
// Values include channel secret, channel access token, receiver IDs (group or user), Message and Title.
// If multiple receiver IDs are provided, then the string is split with "," separator and each receiver ID is added to the receiver.
func Send() *cli.Command {
var lineOpts Line
return &cli.Command{
Name: "line",
Usage: "Send message to line messenger",
Description: `Line messenger uses a channel secret and
a channel access token to authenticate & send messages
through line to various receivers.`,
UsageText: "pingme line --secret '123' --token '123' --msg 'some message' --receivers '123,456,789'",
Flags: []cli.Flag{
&cli.StringFlag{
Destination: &lineOpts.Secret,
Name: "secret",
Required: true,
Usage: "Channel secret.",
EnvVars: []string{"LINE_SECRET"},
},
&cli.StringFlag{
Destination: &lineOpts.Token,
Name: "token",
Required: true,
Usage: "Channel access token.",
EnvVars: []string{"LINE_TOKEN"},
},
&cli.StringFlag{
Destination: &lineOpts.Message,
Name: "msg",
Required: true,
Usage: "Message content.",
EnvVars: []string{"LINE_MESSAGE"},
},
&cli.StringFlag{
Destination: &lineOpts.Title,
Name: "title",
Value: helpers.TimeValue,
Usage: "Message title.",
EnvVars: []string{"LINE_MSG_TITLE"},
},
&cli.StringFlag{
Destination: &lineOpts.Receivers,
Name: "receivers",
Required: true,
Usage: "Comma-separated list of user or group receiver IDs.",
EnvVars: []string{"LINE_RECEIVER_IDS"},
},
},
Action: func(ctx *cli.Context) error {
notifier := notify.New()
lineSvc, err := line.New(lineOpts.Secret, lineOpts.Token)
if err != nil {
return err
}

// Add receiver IDs
recv := strings.Split(lineOpts.Receivers, ",")
for _, r := range recv {
lineSvc.AddReceivers(r)
}

notifier.UseServices(lineSvc)

if err := notifier.Send(
context.Background(),
lineOpts.Title,
lineOpts.Message,
); err != nil {
return err
}

log.Println("Successfully sent!")

return nil
},
}
}

0 comments on commit 3cfd2b2

Please sign in to comment.