File tree Expand file tree Collapse file tree 4 files changed +158
-0
lines changed
packages/notification-wecom-group-bot Expand file tree Collapse file tree 4 files changed +158
-0
lines changed Original file line number Diff line number Diff line change
1
+ # notification-wecom-group-bot
2
+
3
+ A Waline plugin that provide wecome group bot notification spport.
4
+
5
+
6
+ ## How to install
7
+ ``` shell
8
+ npm install @waline-plugins/notification-wecom-group-bot
9
+ ```
10
+
11
+ ## How to use
12
+
13
+ Edit your Waline File:
14
+
15
+ indes.js
16
+ ``` js
17
+ const Application = require (' @waline/vercel' );
18
+ const WecomGroupBot = require (' @waline-plugins/notification-wecom-group-bot' );
19
+
20
+ module .exports = Application ({
21
+ plugins: [WecomGroupBot],
22
+ async postSave (comment ) {
23
+ // do what ever you want after comment saved
24
+ },
25
+ });
26
+ ```
27
+
28
+ ### package.json
29
+ Add "@waline-plugins/notification-wecom-group-bot ": "latest" into package.json dependencies.
30
+
31
+
32
+ ## Environment Variables
33
+
34
+ - ` WECOM_GROUP_WEBHOOK ` : Wecom group bot webhook URL. e.g. ` https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b55f4f3c-478c-4256-8ba9-cf217f288987 `
35
+ - ` SITE_NAME ` : Your site name, used for display in notification message.
36
+ - ` SITE_URL ` : Your site URL, used for display in notification message.
37
+ - ` WECOM_TEMPLATE ` : (optional) Your custom notification template, please refer [ this document] ( https://waline.js.org/en/guide/features/notification.html#notification-template ) .
38
+
39
+
40
+ You need ** redeploy** after change environment variables.
Original file line number Diff line number Diff line change
1
+ # notification-wecom-group-bot
2
+
3
+ 一个Waline插件,提供 ** 企业微信群机器人** 通知功能。
4
+
5
+ ## 如何安装
6
+ ``` shell
7
+ npm install @waline-plugins/notification-wecom-group-bot
8
+ ```
9
+
10
+ ## 如何使用
11
+ 编辑你的服务端 Waline 文件:
12
+
13
+ waline.js
14
+ ``` js
15
+ const Application = require (' @waline/vercel' );
16
+ const WecomGroupBot = require (' @waline-plugins/notification-wecom-group-bot' );
17
+
18
+ module .exports = Application ({
19
+ plugins: [WecomGroupBot],
20
+ async postSave (comment ) {
21
+ // do what ever you want after comment saved
22
+ },
23
+ });
24
+ ```
25
+
26
+ ### package.json
27
+ 把 ` "@waline-plugins/notification-wecom-group-bot": "latest" ` 添加到 package.json 依赖中。
28
+
29
+
30
+ ## 环境变量
31
+
32
+ - ` WECOM_GROUP_WEBHOOK ` : Wecom group bot webhook URL. e.g. ` https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=b55f4f3c-478c-4256-8ba9-cf217f288987 `
33
+ - ` SITE_NAME ` : Your site name, used for display in notification message.
34
+ - ` SITE_URL ` : Your site URL, used for display in notification message.
35
+ - ` WECOM_TEMPLATE ` : (optional) Your custom notification template, please refer [ this document] ( https://waline.js.org/en/guide/features/notification.html#notification-template ) .
36
+
37
+
38
+ 在修改环境变量后,你需要 ** 重新部署** Waline服务端。
Original file line number Diff line number Diff line change
1
+ const fetch = require ( 'node-fetch' ) ;
2
+ const nunjucks = require ( 'nunjucks' ) ;
3
+
4
+ module . exports = {
5
+ hooks : {
6
+ async postSave ( comment , parent ) {
7
+ const { WECOM_GROUP_WEBHOOK , SITE_NAME , SITE_URL , WECOM_TEMPLATE } = process . env ;
8
+
9
+ if ( ! WECOM_GROUP_WEBHOOK ) {
10
+ return false ;
11
+ }
12
+
13
+ comment . comment = comment . comment . replace ( / ( < ( [ ^ > ] + ) > ) / gi, '' ) ;
14
+
15
+ const data = {
16
+ self : comment ,
17
+ parent,
18
+ site : {
19
+ name : SITE_NAME ,
20
+ url : SITE_URL ,
21
+ postUrl : SITE_URL + comment . url + '#' + comment . objectId ,
22
+ } ,
23
+ } ;
24
+
25
+ const template = WECOM_TEMPLATE || `{{site.name|safe}}有新评论啦
26
+ 【昵称】:{{self.nick}}
27
+ 【邮箱】:{{self.mail}}
28
+ 【内容】:{{self.comment}}
29
+ 【地址】:{{site.postUrl}}` ;
30
+
31
+ const content = nunjucks . renderString ( template , data ) ;
32
+
33
+ const msg = {
34
+ msgtype : 'text' ,
35
+ text : {
36
+ content : `${ content } ` ,
37
+ } ,
38
+ } ;
39
+
40
+ try {
41
+ const resp = await fetch ( WECOM_GROUP_WEBHOOK , {
42
+ method : 'POST' ,
43
+ headers : {
44
+ 'Content-Type' : 'application/json' ,
45
+ } ,
46
+ body : JSON . stringify ( msg ) ,
47
+ } ) . then ( ( resp ) => resp . json ( ) ) ;
48
+
49
+ if ( resp . errcode !== 0 ) {
50
+ console . log ( 'Wecom group bot notification FAILED:' , JSON . stringify ( resp ) ) ;
51
+ } else {
52
+ console . log ( 'Wecom group bot notification SUCCESS:' , JSON . stringify ( resp ) ) ;
53
+ }
54
+ } catch ( error ) {
55
+ console . error ( 'Send wecom group bot notification ERROR:' , error ) ;
56
+ }
57
+ } ,
58
+ } ,
59
+ } ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @waline-plugins/notification-wecom-group-bot" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " Notification for Wecom group bot" ,
5
+ "keywords" : [
6
+ " waline" ,
7
+ " notification" ,
8
+ " blog"
9
+ ],
10
+ "homepage" : " https://github.com/walinejs/plugins/packages/notification-wecom-group-bot#readme" ,
11
+ "bugs" : {
12
+ "url" : " https://github.com/walinejs/plugins/issues"
13
+ },
14
+ "repository" : {
15
+ "type" : " git" ,
16
+ "url" : " git+https://github.com/walinejs/plugins.git"
17
+ },
18
+ "license" : " MIT" ,
19
+ "author" : " mapxn" ,
20
+ "main" : " index.js"
21
+ }
You can’t perform that action at this time.
0 commit comments