Skip to content

Commit 3570a60

Browse files
authored
Merge pull request #28 from kha7iq/add-support-for-twillio-chat
Add support for twillio chat
2 parents b78c708 + 20e4b8e commit 3570a60

File tree

8 files changed

+168
-1
lines changed

8 files changed

+168
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ as message, and most of all this serves as a swiss army knife sort of tool which
5858
- *RocketChat*
5959
- *Slack*
6060
- *Telegram*
61+
- *Twillio*
6162

6263
## Install
6364

docs/home.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ as message, and most of all this serves as a swiss army knife sort of tool which
5252
- *RocketChat*
5353
- *Slack*
5454
- *Telegram*
55+
- *Twillio*
5556

5657

5758

docs/install.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ brew install kha7iq/tap/pingme
99
wget -q https://github.com/kha7iq/pingme/releases/download/v0.1.6/pingme_Linux_x86_64.tar.gz
1010
tar -xf pingme_Linux_x86_64.tar.gz
1111
chmod +x pingme
12-
sudo mv
12+
sudo mv pingme /usr/local/bin/pingme
1313
```
1414

1515
## Go Get

docs/services.md

+46
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,52 @@ jobs:
382382
| PUSHBULLET_TITLE | "" |
383383
384384
385+
386+
## Twillio SMS
387+
SMS can be sent via twillio to multiple numbers, you can add multiple receivers separated by a comma.
388+
389+
```bash
390+
pingme twillio --token 'tokenabc' --account 'sid123' --sender '+140001442' --receiver '+140001442'' --msg 'some message'
391+
```
392+
393+
- GitHub Action
394+
395+
```yaml
396+
on: [push]
397+
398+
jobs:
399+
pingme-job:
400+
runs-on: ubuntu-latest
401+
name: PingMe
402+
steps:
403+
- name: Checkout
404+
uses: actions/checkout@v2
405+
406+
- name: Ping me On
407+
uses: kha7iq/pingme-action@v1
408+
env:
409+
TWILLIO_TOKEN: ${{ secrets.TWILLIO_TOKEN }}
410+
TWILLIO_ACCOUNT_SID: ${{ secrets.TWILLIO_ACCOUNT_SID }}
411+
TWILLIO_SENDER: ${{ secrets.TWILLIO_SENDER }}
412+
TWILLIO_RECEIVER: ${{ secrets.TWILLIO_RECEIVER }}
413+
TWILLIO_TITLE: 'Reference: ${{ github.ref }}'
414+
TWILLIO_MESSAGE: 'Event is triggered by ${{ github.event_name }}'
415+
with:
416+
# Chose the messaging platform.
417+
# slack / telegram / rocketchat / teams / pushover / discord / email / mattermost / twillio
418+
service: twillio
419+
```
420+
- **Variables**
421+
422+
| Variables | Default Value |
423+
| -------------------------- | :----------------: |
424+
| TWILLIO_TOKEN | "" |
425+
| TWILLIO_ACCOUNT_SID | "" |
426+
| TWILLIO_SENDER | "" |
427+
| TWILLIO_RECEIVER | "" |
428+
| TWILLIO_TITLE | "" |
429+
| TWILLIO_MESSAGE | "" |
430+
385431
## Email
386432
Email uses username & password to authenticate for sending emails.
387433
SMTP hostname i.e smtp.gmail.com and port i.e (587) should be provided as well for the server.

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ require (
77
github.com/gregdel/pushover v0.0.0-20210216095829-2131362cb888
88
github.com/nikoksr/notify v0.15.0
99
github.com/russross/blackfriday/v2 v2.1.0 // indirect
10+
github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5 // indirect
1011
github.com/urfave/cli/v2 v2.3.0
1112
)

go.sum

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14y
4141
github.com/dghubble/go-twitter v0.0.0-20201011215211-4b180d0cc78d/go.mod h1:xfg4uS5LEzOj8PgZV7SQYRHbG7jPUnelEiaAVJxmhJE=
4242
github.com/dghubble/oauth1 v0.7.0/go.mod h1:8pFdfPkv/jr8mkChVbNVuJ0suiHe278BtWI4Tk1ujxk=
4343
github.com/dghubble/sling v1.3.0/go.mod h1:XXShWaBWKzNLhu2OxikSNFrlsvowtz4kyRuXUG7oQKY=
44+
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
45+
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
4446
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
4547
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
4648
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
@@ -71,11 +73,14 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
7173
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7274
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
7375
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
76+
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
7477
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
7578
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
7679
github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4 h1:4EZlYQIiyecYJlUbVkFXCXHz1QPhVXcHnQKAzBTPfQo=
7780
github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4/go.mod h1:lEO7XoHJ/xNRBCxrn4h/CEB67h0kW1B0t4ooP2yrjUA=
7881
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
82+
github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY=
83+
github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
7984
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
8085
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
8186
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
@@ -88,6 +93,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
8893
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
8994
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
9095
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
96+
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
97+
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
9198
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
9299
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
93100
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
@@ -124,7 +131,10 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
124131
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
125132
github.com/sendgrid/rest v2.6.3+incompatible/go.mod h1:kXX7q3jZtJXK5c5qK83bSGMdV6tsOE70KbHoqJls4lE=
126133
github.com/sendgrid/sendgrid-go v3.8.0+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8=
134+
github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5 h1:76NN4jha0iT2Qwfth8Xf8q2LlQEG7jiZ86dFDKHN9l8=
135+
github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5/go.mod h1:dhtsjtHOWmTLjCOyNloce1diOIs9H1mvVmcOG7qmZUc=
127136
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
137+
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
128138
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
129139
github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo=
130140
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
@@ -133,6 +143,7 @@ github.com/slack-go/slack v0.8.1/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs
133143
github.com/sony/sonyflake v1.0.0 h1:MpU6Ro7tfXwgn2l5eluf9xQvQJDROTBImNCfRXn/YeM=
134144
github.com/sony/sonyflake v1.0.0/go.mod h1:Jv3cfhf/UFtolOTTRd3q4Nl6ENqM+KfyZ5PseKfZGF4=
135145
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
146+
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
136147
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
137148
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
138149
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -176,6 +187,8 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
176187
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
177188
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
178189
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
190+
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
191+
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
179192
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
180193
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
181194
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

main.go

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"log"
55
"os"
66

7+
"github.com/kha7iq/pingme/service/twillio"
8+
79
"github.com/kha7iq/pingme/service/discord"
810
"github.com/kha7iq/pingme/service/email"
911
"github.com/kha7iq/pingme/service/mattermost"
@@ -41,6 +43,7 @@ RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams and email
4143
email.Send(),
4244
mattermost.Send(),
4345
pushbullet.Send(),
46+
twillio.Send(),
4447
}
4548

4649
err := app.Run(os.Args)

service/twillio/twillio.go

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package twillio
2+
3+
import (
4+
"log"
5+
"strings"
6+
7+
"github.com/kha7iq/pingme/service/helpers"
8+
"github.com/sfreiberg/gotwilio"
9+
"github.com/urfave/cli/v2"
10+
)
11+
12+
// Twillio struct holds data parsed via flags for the service
13+
type Twillio struct {
14+
Title string
15+
Token string
16+
AccountSid string
17+
Sender string
18+
Receiver string
19+
Message string
20+
}
21+
22+
// Send parse values from *cli.context and return *cli.Command
23+
// and send messages to target numbers.
24+
// If multiple receivers are provided then the string is split with "," separator and
25+
// message is sent to each number.
26+
func Send() *cli.Command {
27+
var twillioOpts Twillio
28+
return &cli.Command{
29+
Name: "twillio",
30+
Usage: "Send sms via twillio",
31+
UsageText: "pingme twillio --token 'tokenabc' --account 'sid123' " +
32+
"--sender '+140001442' --receiver '+140001442'' --msg 'some message'",
33+
Description: `Twillio provides ability to send sms to multiple numbers.
34+
You can specify multiple receivers by separating the value with a comma.`,
35+
Flags: []cli.Flag{
36+
&cli.StringFlag{
37+
Destination: &twillioOpts.Token,
38+
Name: "token",
39+
Aliases: []string{"t"},
40+
Required: true,
41+
Usage: "Auth token for twillio account.",
42+
EnvVars: []string{"TWILLIO_TOKEN"},
43+
},
44+
&cli.StringFlag{
45+
Destination: &twillioOpts.AccountSid,
46+
Name: "account",
47+
Required: true,
48+
Aliases: []string{"a"},
49+
Usage: "Twillio account sid",
50+
EnvVars: []string{"TWILLIO_ACCOUNT_SID"},
51+
},
52+
&cli.StringFlag{
53+
Destination: &twillioOpts.Message,
54+
Name: "msg",
55+
Aliases: []string{"m"},
56+
Usage: "Message content.",
57+
EnvVars: []string{"TWILLIO_MESSAGE"},
58+
},
59+
&cli.StringFlag{
60+
Destination: &twillioOpts.Title,
61+
Name: "title",
62+
Usage: "Title of the message.",
63+
EnvVars: []string{"TWILLIO_TITLE"},
64+
},
65+
&cli.StringFlag{
66+
Destination: &twillioOpts.Sender,
67+
Name: "sender",
68+
Aliases: []string{"s"},
69+
Usage: "Sender's phone number",
70+
EnvVars: []string{"TWILLIO_SENDER"},
71+
},
72+
&cli.StringFlag{
73+
Destination: &twillioOpts.Receiver,
74+
Name: "receiver",
75+
Aliases: []string{"r"},
76+
Usage: "Receiver's phone number",
77+
EnvVars: []string{"TWILLIO_RECEIVER"},
78+
},
79+
},
80+
Action: func(ctx *cli.Context) error {
81+
client := gotwilio.NewTwilioClient(twillioOpts.AccountSid, twillioOpts.Token)
82+
fullMessage := twillioOpts.Title + "\n" + twillioOpts.Message
83+
84+
numbers := strings.Split(twillioOpts.Receiver, ",")
85+
for _, v := range numbers {
86+
if len(v) == 0 {
87+
return helpers.ErrChannel
88+
}
89+
90+
_, exception, err := client.SendSMS(twillioOpts.Sender, twillioOpts.Receiver, fullMessage, "", "")
91+
if err != nil {
92+
return err
93+
}
94+
if exception != nil {
95+
return exception
96+
}
97+
}
98+
log.Println("Successfully sent!")
99+
return nil
100+
},
101+
}
102+
}

0 commit comments

Comments
 (0)