Skip to content

Commit df5427b

Browse files
authored
Merge pull request #50 from araceae101/add_wechat_service
feat(service): add wechat service
2 parents 24242b5 + 68d5917 commit df5427b

File tree

8 files changed

+190
-16
lines changed

8 files changed

+190
-16
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ platforms.
6565
- *Telegram*
6666
- *Twillio*
6767
- *Zulip*
68+
- *Wechat*
6869

6970
## Install
7071

@@ -168,6 +169,7 @@ COMMANDS:
168169
zulip Send message to zulip
169170
mastodon Set status message for mastodon
170171
line Send message to line messenger
172+
wechat Send message to wechat official account
171173
help, h Shows a list of commands or help for one command
172174

173175
GLOBAL OPTIONS:

docs/contribution.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ possible.
1414
- `service/telegram` - Telegram notification service.
1515
- `service/pushover` - Pushover Notification service.
1616
- `service/line` - Line notification service.
17+
- `service/wechat` - Wechat Official Account notification service.
1718

1819
### Documentation
1920

docs/home.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ platforms.
5959
- *Telegram*
6060
- *Twillio*
6161
- *Line Messenger*
62+
- *Wechat*
6263

6364
## Demo
6465

docs/services.md

+55
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,58 @@ pingme email \
643643
| EMAIL_PORT | "587" |
644644
| EMAIL_MESSAGE | "" |
645645
| EMAIL_SUBJECT | "" |
646+
647+
648+
## Wechat Official Account
649+
650+
Wechat uses appid, appsecret, chatbot server token and encoding AES key for authentication, and sends messages.
651+
652+
```bash
653+
pingme wechat
654+
--appid "xxxxxxxx" \
655+
--appsecret 'xxxxxxxxxx' \
656+
--token 'xxxxxxxxxx' \
657+
--aes 'IGNORED-IN-SANDBOX' \
658+
--msg 'content of message' \
659+
--receivers 'some receivers'
660+
```
661+
662+
- GitHub Action
663+
664+
```yaml
665+
on: [push]
666+
667+
jobs:
668+
pingme-job:
669+
runs-on: ubuntu-latest
670+
name: PingMe
671+
steps:
672+
- name: Checkout
673+
uses: actions/checkout@v2
674+
675+
- name: Ping me On
676+
uses: kha7iq/pingme-action@v1
677+
env:
678+
WECHAT_APPID: ${{ secrets.WECHAT_APPID }}
679+
WECHAT_APPSECRET: ${{ secrets.WECHAT_APPSECRET }}
680+
WECHAT_TOKEN: ${{ secrets.WECHAT_TOKEN }}
681+
WECHAT_ENCODINGAESKEY: ${{ secrets.WECHAT_ENCODINGAESKEY }}
682+
WECHAT_RECEIVER_IDS: ${{ secrets.WECHAT_RECEIVER_IDS }}
683+
WECHAT_MSG_TITLE: 'Reference: ${{ github.ref }}'
684+
WECHAT_MESSAGE: 'Event is triggered by ${{ github.event_name }}'
685+
686+
with:
687+
service: wechat
688+
```
689+
690+
- **Variables**
691+
692+
| Variables | Default Value |
693+
| -------------------------- | :----------------: |
694+
| WECHAT_APPID | "" |
695+
| WECHAT_APPSECRET | "" |
696+
| WECHAT_TOKEN | "" |
697+
| WECHAT_ENCODINGAESKEY | "" |
698+
| WECHAT_RECEIVER_IDS | "" |
699+
| WECHAT_MSG_TITLE | "" |
700+
| WECHAT_MESSAGE | "" |

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/nikoksr/notify v0.17.0
99
github.com/russross/blackfriday/v2 v2.1.0 // indirect
1010
github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5
11+
github.com/silenceper/wechat/v2 v2.0.6
1112
github.com/stretchr/testify v1.7.0
1213
github.com/urfave/cli/v2 v2.3.0
1314
)

go.sum

+6-15
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ github.com/aws/aws-sdk-go-v2/service/ses v1.3.1/go.mod h1:6WbvZTnH6a1YzeMZDi/hSj
5757
github.com/aws/aws-sdk-go-v2/service/sso v1.2.1/go.mod h1:VimPFPltQ/920i1X0Sb0VJBROLIHkDg2MNP10D46OGs=
5858
github.com/aws/aws-sdk-go-v2/service/sts v1.4.1/go.mod h1:G9osDWA52WQ38BDcj65VY1cNmcAQXAXTsE8IWH8j81w=
5959
github.com/aws/smithy-go v1.4.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E=
60+
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
6061
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
6162
github.com/bwmarrin/discordgo v0.23.2 h1:BzrtTktixGHIu9Tt7dEE6diysEF9HWnXeHuoJEt2fH4=
6263
github.com/bwmarrin/discordgo v0.23.2/go.mod h1:c1WtWUGN6nREDmzIpyTp/iD3VYt4Fpx+bVyfBG7JE+M=
@@ -77,7 +78,6 @@ github.com/cschomburg/go-pushbullet v0.0.0-20171206132031-67759df45fbb/go.mod h1
7778
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7879
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7980
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
80-
github.com/deckarep/golang-set v1.7.1 h1:SCQV0S6gTtp6itiFrTqI+pfmJ4LN85S1YzhDf9rTHJQ=
8181
github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
8282
github.com/dghubble/go-twitter v0.0.0-20201011215211-4b180d0cc78d/go.mod h1:xfg4uS5LEzOj8PgZV7SQYRHbG7jPUnelEiaAVJxmhJE=
8383
github.com/dghubble/oauth1 v0.7.0/go.mod h1:8pFdfPkv/jr8mkChVbNVuJ0suiHe278BtWI4Tk1ujxk=
@@ -91,9 +91,9 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
9191
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
9292
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
9393
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
94+
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
9495
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
9596
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
96-
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
9797
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
9898
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
9999
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
@@ -128,8 +128,8 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq
128128
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
129129
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
130130
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
131-
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
132131
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
132+
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
133133
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
134134
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
135135
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
@@ -141,11 +141,9 @@ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
141141
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
142142
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
143143
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
144-
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
145144
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
146145
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
147146
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
148-
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
149147
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
150148
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
151149
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
@@ -210,15 +208,12 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
210208
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
211209
github.com/nikoksr/notify v0.17.0 h1:Pi5lXgbE8LIEda9mbPJb3GwSCVQL5lbyXkLaj3VvICE=
212210
github.com/nikoksr/notify v0.17.0/go.mod h1:INe8kALt/rpdYhYzOuu/pQr3xdVA5Azr1IbiAvSIzPc=
213-
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
214211
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
215212
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
216213
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
217-
github.com/onsi/ginkgo v1.14.1 h1:jMU0WaQrP0a/YAEq8eJmJKjBoMs+pClEr1vDMlM/Do4=
218214
github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
219215
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
220216
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
221-
github.com/onsi/gomega v1.10.2 h1:aY/nuoWlKJud2J6U0E3NWsjlg+0GtwXxgEqthRdzlcs=
222217
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
223218
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
224219
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -237,6 +232,7 @@ github.com/sendgrid/sendgrid-go v3.10.0+incompatible/go.mod h1:QRQt+LX/NmgVEvmdR
237232
github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5 h1:76NN4jha0iT2Qwfth8Xf8q2LlQEG7jiZ86dFDKHN9l8=
238233
github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5/go.mod h1:dhtsjtHOWmTLjCOyNloce1diOIs9H1mvVmcOG7qmZUc=
239234
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
235+
github.com/silenceper/wechat/v2 v2.0.6 h1:/cKlckNsVzDLPRqXd11Uw4RQK9AfkAuKIoLbQdXBuDE=
240236
github.com/silenceper/wechat/v2 v2.0.6/go.mod h1:0cWAenXlYXehZTJv7wnezGrwTNMNycOHYyczkJvD8FY=
241237
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
242238
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
@@ -247,9 +243,11 @@ github.com/slack-go/slack v0.9.1 h1:pekQBs0RmrdAgoqzcMCzUCWSyIkhzUU3F83ExAdZrKo=
247243
github.com/slack-go/slack v0.9.1/go.mod h1:wWL//kk0ho+FcQXcBTmEafUI5dz4qz5f4mMk8oIkioQ=
248244
github.com/sony/sonyflake v1.0.0 h1:MpU6Ro7tfXwgn2l5eluf9xQvQJDROTBImNCfRXn/YeM=
249245
github.com/sony/sonyflake v1.0.0/go.mod h1:Jv3cfhf/UFtolOTTRd3q4Nl6ENqM+KfyZ5PseKfZGF4=
246+
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
250247
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
251248
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
252249
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
250+
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
253251
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
254252
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
255253
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -403,9 +401,7 @@ golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fq
403401
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
404402
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
405403
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
406-
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
407404
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
408-
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
409405
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
410406
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
411407
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -453,7 +449,6 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc
453449
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
454450
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
455451
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
456-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
457452
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
458453
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
459454
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
@@ -528,10 +523,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
528523
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
529524
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
530525
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
531-
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
532526
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
533527
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
534-
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
535528
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
536529
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
537530
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -540,14 +533,12 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
540533
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
541534
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
542535
gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE=
543-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
544536
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
545537
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
546538
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
547539
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
548540
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
549541
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
550-
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
551542
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
552543
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
553544
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=

main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/kha7iq/pingme/service/mastodon"
88
"github.com/kha7iq/pingme/service/twillio"
9+
"github.com/kha7iq/pingme/service/wechat"
910
"github.com/kha7iq/pingme/service/zulip"
1011

1112
"github.com/kha7iq/pingme/service/discord"
@@ -34,7 +35,8 @@ func main() {
3435
app.Description = `PingMe is a CLI tool which provides the ability to send messages or alerts to multiple
3536
messaging platforms and also email, everything is configurable via environment
3637
variables and command line switches.Currently supported platforms include Slack, Telegram,
37-
RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams, Twillio, Mastodon and email address.`
38+
RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams, Twillio, Mastodon,
39+
email address, Line, and Wechat official account.`
3840
// app.Commands contains the subcommands as functions which return []*cli.Command.
3941
app.Commands = []*cli.Command{
4042
telegram.Send(),
@@ -50,6 +52,7 @@ RocketChat, Discord, Pushover, Mattermost, Pushbullet, Microsoft Teams, Twillio,
5052
zulip.Send(),
5153
mastodon.Send(),
5254
line.Send(),
55+
wechat.Send(),
5356
}
5457

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

service/wechat/wechat.go

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package wechat
2+
3+
import (
4+
"context"
5+
"log"
6+
"strings"
7+
8+
"github.com/kha7iq/pingme/service/helpers"
9+
"github.com/nikoksr/notify"
10+
"github.com/nikoksr/notify/service/wechat"
11+
"github.com/silenceper/wechat/v2/cache"
12+
"github.com/urfave/cli/v2"
13+
)
14+
15+
// Wechat struct holds data parsed via flags for the service.
16+
type Wechat struct {
17+
AppID string
18+
AppSecret string
19+
Token string
20+
EncodingAESKey string
21+
Title string
22+
Message string
23+
Receivers string
24+
}
25+
26+
// Send parse values from *cli.context and return *cli.Command.
27+
// Values include wechat official account id, secret, server token, encoding AES key,
28+
// Message, Title, and Receivers.
29+
// If multiple receivers are provided then the string is split with "," separator and
30+
// each receiverID is added to receiver.
31+
func Send() *cli.Command {
32+
var wechatOpts Wechat
33+
return &cli.Command{
34+
Name: "wechat",
35+
Usage: "Send message to wechat official account",
36+
Description: `Wechat sends message to Wechat Official Account using appid, appsecrete
37+
and server token to authenticate
38+
AND then send messages to defined account.
39+
Multiple receiverss can be used separated by comma.`,
40+
UsageText: "pingme wechat --appid '123' --appsecret '123' --token '123' --aes '123' --msg 'some message' --receivers 'aaa,bbb,ccc'",
41+
Flags: []cli.Flag{
42+
&cli.StringFlag{
43+
Destination: &wechatOpts.AppID,
44+
Name: "appid",
45+
Required: true,
46+
Usage: "AppID of wechat official account.",
47+
EnvVars: []string{"WECHAT_APPID"},
48+
},
49+
&cli.StringFlag{
50+
Destination: &wechatOpts.AppSecret,
51+
Name: "appsecret",
52+
Required: true,
53+
Usage: "AppSecret of wechat official account.",
54+
EnvVars: []string{"WECHAT_APPSECRET"},
55+
},
56+
&cli.StringFlag{
57+
Destination: &wechatOpts.Token,
58+
Name: "token",
59+
Required: true,
60+
Usage: "Token of server used for sending message.",
61+
EnvVars: []string{"WECHAT_TOKEN"},
62+
},
63+
&cli.StringFlag{
64+
Destination: &wechatOpts.EncodingAESKey,
65+
Name: "aes",
66+
Required: true,
67+
Usage: "Encoding AES Key of server used for sending message.",
68+
EnvVars: []string{"WECHAT_ENCODING_AES_KEY"},
69+
},
70+
&cli.StringFlag{
71+
Destination: &wechatOpts.Receivers,
72+
Name: "receivers",
73+
Required: true,
74+
Usage: "Comma-separated list of receiver IDs.",
75+
EnvVars: []string{"WECHAT_RECEIVERS"},
76+
},
77+
&cli.StringFlag{
78+
Destination: &wechatOpts.Message,
79+
Name: "msg",
80+
Required: true,
81+
Usage: "Message content.",
82+
EnvVars: []string{"WECHAT_MESSAGE"},
83+
},
84+
&cli.StringFlag{
85+
Destination: &wechatOpts.Title,
86+
Name: "title",
87+
Value: helpers.TimeValue,
88+
Usage: "Title of the message.",
89+
EnvVars: []string{"WECHAT_TITLE"},
90+
},
91+
},
92+
Action: func(ctx *cli.Context) error {
93+
wechatSvc := wechat.New(&wechat.Config{
94+
AppID: wechatOpts.AppID,
95+
AppSecret: wechatOpts.AppSecret,
96+
Token: wechatOpts.Token,
97+
EncodingAESKey: wechatOpts.EncodingAESKey,
98+
Cache: cache.NewMemory(),
99+
})
100+
101+
// Add receiver IDs
102+
recv := strings.Split(wechatOpts.Receivers, ",")
103+
for _, r := range recv {
104+
wechatSvc.AddReceivers(r)
105+
}
106+
107+
notifier := notify.New()
108+
notifier.UseServices(wechatSvc)
109+
110+
err := notifier.Send(context.Background(), wechatOpts.Title, wechatOpts.Message)
111+
if err != nil {
112+
log.Fatalf("notifier.Send() failed: %s", err.Error())
113+
}
114+
115+
log.Println("Successfully sent!")
116+
117+
return nil
118+
},
119+
}
120+
}

0 commit comments

Comments
 (0)