@@ -9,9 +9,8 @@ const utils = require("../utils/index");
9
9
const moment = require ( 'moment-timezone' ) ;
10
10
11
11
const TZ = 'Asia/Shanghai'
12
-
13
- const NOTIFY_FEISHU_GROUPS = process . env [ "NOTIFY_FEISHU_GROUPS" ] ? process . env [ "NOTIFY_FEISHU_GROUPS" ] . split ( "," ) : null ;
14
-
12
+ const FEISHU_GROUP_GITHUB_BOTS = process . env [ "FEISHU_GROUP_GITHUB_BOTS" ] ? process . env [ "FEISHU_GROUP_GITHUB_BOTS" ] . split ( "," ) : null ;
13
+ const FEISHU_GROUP_W3_BOTS = process . env [ "FEISHU_GROUP_W3_BOTS" ] ? process . env [ "FEISHU_GROUP_W3_BOTS" ] . split ( "," ) : null ;
15
14
16
15
/**
17
16
* Compose Push Event Content
@@ -58,8 +57,8 @@ async function sendPushEventNotification(payload) {
58
57
} )
59
58
60
59
61
- if ( NOTIFY_FEISHU_GROUPS && NOTIFY_FEISHU_GROUPS . length > 0 ) {
62
- for ( let notify_feishu_group of NOTIFY_FEISHU_GROUPS ) {
60
+ if ( FEISHU_GROUP_GITHUB_BOTS && FEISHU_GROUP_GITHUB_BOTS . length > 0 ) {
61
+ for ( let notify_feishu_group of FEISHU_GROUP_GITHUB_BOTS ) {
63
62
// Check out payload body for message conent with
64
63
// https://github.com/cskefu/cskefu.sync/issues/2
65
64
let response = await axios . post ( notify_feishu_group , {
@@ -81,11 +80,10 @@ async function sendPushEventNotification(payload) {
81
80
debug ( "[sendPushEventNotification] resp %j" , response . data )
82
81
}
83
82
} else {
84
- debug ( "[sendPushEventNotification] No notify group defined with ENV NOTIFY_FEISHU_GROUPS " ) ;
83
+ debug ( "[sendPushEventNotification] No notify group defined with ENV FEISHU_GROUP_GITHUB_BOTS " ) ;
85
84
}
86
85
}
87
86
88
-
89
87
/**
90
88
* Get Issue lable string
91
89
* @param {* } labels
@@ -170,8 +168,8 @@ async function sendIssuesEventNotification(payload) {
170
168
} )
171
169
172
170
173
- if ( NOTIFY_FEISHU_GROUPS && NOTIFY_FEISHU_GROUPS . length > 0 ) {
174
- for ( let notify_feishu_group of NOTIFY_FEISHU_GROUPS ) {
171
+ if ( FEISHU_GROUP_GITHUB_BOTS && FEISHU_GROUP_GITHUB_BOTS . length > 0 ) {
172
+ for ( let notify_feishu_group of FEISHU_GROUP_GITHUB_BOTS ) {
175
173
// Check out payload body for message conent with
176
174
// https://github.com/cskefu/cskefu.sync/issues/2
177
175
let response = await axios . post ( notify_feishu_group , {
@@ -193,7 +191,7 @@ async function sendIssuesEventNotification(payload) {
193
191
debug ( "[sendIssuesEventNotification] resp %j" , response . data )
194
192
}
195
193
} else {
196
- debug ( "[sendIssuesEventNotification] No notify group defined with ENV NOTIFY_FEISHU_GROUPS " ) ;
194
+ debug ( "[sendIssuesEventNotification] No notify group defined with ENV FEISHU_GROUP_GITHUB_BOTS " ) ;
197
195
}
198
196
}
199
197
@@ -242,8 +240,8 @@ async function sendIssueCommentEventNotification(payload) {
242
240
} )
243
241
244
242
245
- if ( NOTIFY_FEISHU_GROUPS && NOTIFY_FEISHU_GROUPS . length > 0 ) {
246
- for ( let notify_feishu_group of NOTIFY_FEISHU_GROUPS ) {
243
+ if ( FEISHU_GROUP_GITHUB_BOTS && FEISHU_GROUP_GITHUB_BOTS . length > 0 ) {
244
+ for ( let notify_feishu_group of FEISHU_GROUP_GITHUB_BOTS ) {
247
245
// Check out payload body for message conent with
248
246
// https://github.com/cskefu/cskefu.sync/issues/2
249
247
let response = await axios . post ( notify_feishu_group , {
@@ -265,7 +263,7 @@ async function sendIssueCommentEventNotification(payload) {
265
263
debug ( "[sendIssueCommentEventNotification] resp %j" , response . data )
266
264
}
267
265
} else {
268
- debug ( "[sendIssueCommentEventNotification] No notify group defined with ENV NOTIFY_FEISHU_GROUPS " ) ;
266
+ debug ( "[sendIssueCommentEventNotification] No notify group defined with ENV FEISHU_GROUP_GITHUB_BOTS " ) ;
269
267
}
270
268
}
271
269
@@ -300,8 +298,8 @@ async function sendForkEventNotification(payload) {
300
298
} )
301
299
302
300
303
- if ( NOTIFY_FEISHU_GROUPS && NOTIFY_FEISHU_GROUPS . length > 0 ) {
304
- for ( let notify_feishu_group of NOTIFY_FEISHU_GROUPS ) {
301
+ if ( FEISHU_GROUP_GITHUB_BOTS && FEISHU_GROUP_GITHUB_BOTS . length > 0 ) {
302
+ for ( let notify_feishu_group of FEISHU_GROUP_GITHUB_BOTS ) {
305
303
// Check out payload body for message conent with
306
304
// https://github.com/cskefu/cskefu.sync/issues/2
307
305
let response = await axios . post ( notify_feishu_group , {
@@ -323,7 +321,7 @@ async function sendForkEventNotification(payload) {
323
321
debug ( "[sendForkEventNotification] resp %j" , response . data )
324
322
}
325
323
} else {
326
- debug ( "[sendForkEventNotification] No notify group defined with ENV NOTIFY_FEISHU_GROUPS " ) ;
324
+ debug ( "[sendForkEventNotification] No notify group defined with ENV FEISHU_GROUP_GITHUB_BOTS " ) ;
327
325
}
328
326
}
329
327
@@ -394,8 +392,8 @@ async function sendPullRequestEventNotification(payload) {
394
392
} )
395
393
396
394
397
- if ( NOTIFY_FEISHU_GROUPS && NOTIFY_FEISHU_GROUPS . length > 0 ) {
398
- for ( let notify_feishu_group of NOTIFY_FEISHU_GROUPS ) {
395
+ if ( FEISHU_GROUP_GITHUB_BOTS && FEISHU_GROUP_GITHUB_BOTS . length > 0 ) {
396
+ for ( let notify_feishu_group of FEISHU_GROUP_GITHUB_BOTS ) {
399
397
// Check out payload body for message conent with
400
398
// https://github.com/cskefu/cskefu.sync/issues/2
401
399
let response = await axios . post ( notify_feishu_group , {
@@ -417,7 +415,7 @@ async function sendPullRequestEventNotification(payload) {
417
415
debug ( "[sendPullRequestEventNotification] resp %j" , response . data )
418
416
}
419
417
} else {
420
- debug ( "[sendPullRequestEventNotification] No notify group defined with ENV NOTIFY_FEISHU_GROUPS " ) ;
418
+ debug ( "[sendPullRequestEventNotification] No notify group defined with ENV FEISHU_GROUP_GITHUB_BOTS " ) ;
421
419
}
422
420
}
423
421
@@ -466,8 +464,8 @@ async function sendMilestoneEventNotification(payload) {
466
464
} )
467
465
468
466
469
- if ( NOTIFY_FEISHU_GROUPS && NOTIFY_FEISHU_GROUPS . length > 0 ) {
470
- for ( let notify_feishu_group of NOTIFY_FEISHU_GROUPS ) {
467
+ if ( FEISHU_GROUP_GITHUB_BOTS && FEISHU_GROUP_GITHUB_BOTS . length > 0 ) {
468
+ for ( let notify_feishu_group of FEISHU_GROUP_GITHUB_BOTS ) {
471
469
// Check out payload body for message conent with
472
470
// https://github.com/cskefu/cskefu.sync/issues/2
473
471
let response = await axios . post ( notify_feishu_group , {
@@ -489,10 +487,86 @@ async function sendMilestoneEventNotification(payload) {
489
487
debug ( "[sendMilestoneEventNotification] resp %j" , response . data )
490
488
}
491
489
} else {
492
- debug ( "[sendMilestoneEventNotification] No notify group defined with ENV NOTIFY_FEISHU_GROUPS " ) ;
490
+ debug ( "[sendMilestoneEventNotification] No notify group defined with ENV FEISHU_GROUP_GITHUB_BOTS " ) ;
493
491
}
494
492
}
495
493
494
+ /**
495
+ * 获得 W3 文章标签分类信息
496
+ * @param {* } payload
497
+ */
498
+ function getW3PostCategories ( payload ) {
499
+ if ( payload . categories && payload . categories . length > 0 ) {
500
+ let ret = [ ] ;
501
+
502
+ for ( let x of payload . categories ) {
503
+ ret . push ( x . name ) ;
504
+ }
505
+
506
+ return ret . join ( "_" )
507
+ } else {
508
+ return "未分类"
509
+ }
510
+ }
511
+
512
+
513
+ /**
514
+ * Send W3 Post Events into Feishu Groups
515
+ * @param {* } payload
516
+ */
517
+ async function sendW3BroadcastNotification ( payload ) {
518
+ debug ( "[sendW3BroadcastNotification]" , JSON . stringify ( payload ) ) ;
519
+ let elements = [ ] ;
520
+
521
+ elements . push ( {
522
+ "tag" : "div" ,
523
+ "text" : {
524
+ "content" : `**标题** ${ payload . post_title } \n**作者** [${ payload . display_name } (${ payload . user_email } )](${ payload . user_profile } )` ,
525
+ "tag" : "lark_md"
526
+ }
527
+ } )
528
+
529
+ elements . push ( {
530
+ "actions" : [ {
531
+ "tag" : "button" ,
532
+ "text" : {
533
+ "content" : "✅ 阅读原文" ,
534
+ "tag" : "lark_md"
535
+ } ,
536
+ "url" : `${ payload . link } ` ,
537
+ "type" : "default" ,
538
+ "value" : { }
539
+ } ] ,
540
+ "tag" : "action"
541
+ } )
542
+
543
+
544
+ if ( FEISHU_GROUP_W3_BOTS && FEISHU_GROUP_W3_BOTS . length > 0 ) {
545
+ for ( let notify_feishu_group of FEISHU_GROUP_W3_BOTS ) {
546
+ // Check out payload body for message conent with
547
+ // https://github.com/cskefu/cskefu.sync/issues/2
548
+ let response = await axios . post ( notify_feishu_group , {
549
+ "msg_type" : "interactive" ,
550
+ "card" : {
551
+ "config" : {
552
+ "wide_screen_mode" : true ,
553
+ "enable_forward" : true
554
+ } ,
555
+ "elements" : elements ,
556
+ "header" : {
557
+ "title" : {
558
+ "content" : utils . capitalizeFirstLetter ( getW3PostCategories ( payload ) + " - " ) + payload . post_title + " | 春松客服 W3" ,
559
+ "tag" : "plain_text"
560
+ }
561
+ }
562
+ }
563
+ } ) ;
564
+ debug ( "[sendW3BroadcastNotification] resp %j" , response . data )
565
+ }
566
+ } else {
567
+ debug ( "[sendW3BroadcastNotification] No notify group defined with ENV FEISHU_GROUP_W3_BOTS" ) ;
568
+ }
569
+ }
496
570
497
571
498
572
exports = module . exports = {
@@ -501,5 +575,6 @@ exports = module.exports = {
501
575
sendIssueCommentEventNotification,
502
576
sendForkEventNotification,
503
577
sendPullRequestEventNotification,
504
- sendMilestoneEventNotification
578
+ sendMilestoneEventNotification,
579
+ sendW3BroadcastNotification
505
580
}
0 commit comments