@@ -24,20 +24,18 @@ function validateBotKey(botKey: string): boolean {
24
24
25
25
// 发送消息到企业微信机器人的函数,支持多种消息类型
26
26
async function sendMessageToWeComBot (
27
- botKey : string ,
27
+ botKey : string [ ] ,
28
28
type : MessageTypeValue ,
29
29
message : string
30
30
) : Promise < void > {
31
- const url = `${ WeComBotHookBaseUrl } ?key=${ encodeURIComponent ( botKey ) } `
32
- let payload
31
+ let payload : any
33
32
34
33
switch ( type ) {
35
34
case MessageType . TEXT :
36
35
payload = { msgtype : 'text' , text : { content : message } }
37
36
break
38
37
case MessageType . MARKDOWN :
39
38
payload = { msgtype : 'markdown' , markdown : { content : message } }
40
- core . debug ( `payload: ${ payload } ` )
41
39
break
42
40
case MessageType . IMAGE :
43
41
// message should be base64 encoded image
@@ -57,11 +55,23 @@ async function sendMessageToWeComBot(
57
55
}
58
56
59
57
try {
60
- const res = await axios . post ( url , payload )
61
- // core.info('Message sent to WeCom Bot successfully.')
62
- core . info (
63
- `${ MessageType . MARKDOWN } ${ type } ${ JSON . stringify ( payload ) } ${ JSON . stringify ( res . data ) } `
64
- )
58
+ // 发送消息到企业微信机器人
59
+ core . info ( 'Sending message to WeCom Bot...' )
60
+ const tasks = botKey . map ( key => {
61
+ return async ( ) => {
62
+ if ( ! validateBotKey ( key ) ) {
63
+ core . setFailed ( 'Invalid or missing wecom bot hook key.' )
64
+ return
65
+ }
66
+ const url = `${ WeComBotHookBaseUrl } ?key=${ encodeURIComponent ( key ) } `
67
+ const res = await axios . post ( url , payload )
68
+ core . info ( 'Message sent to WeCom Bot successfully.' )
69
+ core . info (
70
+ `${ MessageType . MARKDOWN } ${ type } ${ JSON . stringify ( payload ) } ${ JSON . stringify ( res . data ) } `
71
+ )
72
+ }
73
+ } )
74
+ await Promise . all ( tasks )
65
75
} catch ( error : any ) {
66
76
core . error ( `Failed to send message to WeCom Bot: ${ error . message } ` )
67
77
core . setFailed ( error )
@@ -70,11 +80,9 @@ async function sendMessageToWeComBot(
70
80
}
71
81
72
82
async function run ( ) {
73
- const wxWorkBotKey = core . getInput ( 'key' , { required : true } )
74
- if ( ! validateBotKey ( wxWorkBotKey ) ) {
75
- core . setFailed ( 'Invalid or missing wecom bot hook key.' )
76
- return
77
- }
83
+ const keyStr = core . getInput ( 'key' , { required : true } )
84
+
85
+ const keys = keyStr . split ( ',' )
78
86
79
87
// 获取消息内容和消息类型
80
88
const msgContent = core . getInput ( 'content' , { required : true } )
@@ -102,7 +110,7 @@ async function run() {
102
110
core . debug ( `Message Type: ${ msgType } ` )
103
111
104
112
// 发送消息
105
- await sendMessageToWeComBot ( wxWorkBotKey , msgType , msgContent )
113
+ await sendMessageToWeComBot ( keys , msgType , msgContent )
106
114
}
107
115
108
116
run ( )
0 commit comments