@@ -88,6 +88,14 @@ let GOTIFY_URL = '';
8888// 此处填你想推送的Application的Token(不包含推送时额外添加的前缀 Bearer )
8989let GOTIFY_APPKEY = '' ;
9090
91+ // =======================================飞书机器人通知设置区域===========================================
92+ // 此处填你飞书机器人的 webhook(详见文档 https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot)
93+ // 注:此处设置github action用户填写到Settings-Secrets里面(Name输入FS_BOT_WEBHOOK)
94+ let FS_BOT_WEBHOOK = '' ;
95+ // 签名密钥(如果在飞书机器人安全设置里开启了“签名校验”)
96+ // 注:此处设置github action用户填写到Settings-Secrets里面(Name输入FS_BOT_SECRET)
97+ let FS_BOT_SECRET = '' ;
98+
9199//==========================云端环境变量的判断与接收=========================
92100if ( process . env . SCKEY ) {
93101 SCKEY = process . env . SCKEY ;
@@ -211,6 +219,14 @@ if (process.env.GOTIFY_URL) {
211219 }
212220}
213221
222+ if ( process . env . FS_BOT_WEBHOOK ) {
223+ FS_BOT_WEBHOOK = process . env . FS_BOT_WEBHOOK ;
224+ }
225+
226+ if ( process . env . FS_BOT_SECRET ) {
227+ FS_BOT_SECRET = process . env . FS_BOT_SECRET ;
228+ }
229+
214230//==========================云端环境变量的判断与接收=========================
215231
216232async function sendNotify ( text , desp , params = { } ) {
@@ -246,7 +262,9 @@ async function sendNotify(text, desp, params = {}) {
246262 //电子邮件
247263 email ( text , desp ) ,
248264 // Gotify
249- gotifyNotify ( text , desp )
265+ gotifyNotify ( text , desp ) ,
266+ // 飞书机器人
267+ feishuNotify ( text , desp )
250268 ] ) ;
251269}
252270
@@ -885,6 +903,65 @@ function gotifyNotify(text, desp) {
885903 } ) ;
886904}
887905
906+ function feishuNotify ( text , desp ) {
907+ return new Promise ( resolve => {
908+ if ( FS_BOT_WEBHOOK ) {
909+ const payload = {
910+ msg_type : 'text' ,
911+ content : {
912+ text : `${ text } \n\n${ desp } `
913+ }
914+ } ;
915+
916+ if ( FS_BOT_SECRET ) {
917+ const crypto = require ( 'crypto' ) ;
918+ const timestamp = Math . floor ( Date . now ( ) / 1000 ) ;
919+ const signStr = `${ timestamp } \n${ FS_BOT_SECRET } ` ;
920+ const sign = crypto
921+ . createHmac ( 'sha256' , FS_BOT_SECRET )
922+ . update ( signStr )
923+ . digest ( 'base64' ) ;
924+ payload . timestamp = `${ timestamp } ` ;
925+ payload . sign = sign ;
926+ }
927+
928+ send ( {
929+ method : 'POST' ,
930+ url : FS_BOT_WEBHOOK ,
931+ contents : payload ,
932+ config : {
933+ retry : false
934+ } ,
935+ headers : {
936+ accept : 'application/json, text/plain, */*' ,
937+ 'content-type' : 'application/json' ,
938+ } ,
939+ success : res => {
940+ try {
941+ const data = JSON . parse ( res . body ) ;
942+ if ( data . code === 0 ) {
943+ log . info ( '发送通知' , '飞书机器人发送通知消息完成。' ) ;
944+ } else {
945+ log . error ( '发送通知' , `${ data . msg || '飞书机器人发送通知异常' } ` ) ;
946+ }
947+ } catch ( e ) {
948+ log . error ( '发送通知' , e ) ;
949+ } finally {
950+ resolve ( ) ;
951+ }
952+ } ,
953+ failure : err => {
954+ log . error ( '发送通知' , '飞书机器人发送通知消息失败!!' + err ) ;
955+ resolve ( ) ;
956+ }
957+ } ) ;
958+ } else {
959+ log . debug ( '发送通知' , '您未提供飞书机器人推送所需的FS_BOT_WEBHOOK,取消飞书机器人推送消息通知' ) ;
960+ resolve ( ) ;
961+ }
962+ } ) ;
963+ }
964+
888965async function qmsg ( text , desp ) {
889966 return new Promise ( resolve => {
890967 if ( QMSG_KEY ) {
0 commit comments