From 31d557c023085152a38d7d4fc719f725a76466c8 Mon Sep 17 00:00:00 2001 From: akinocccc Date: Sat, 31 Aug 2024 00:36:25 +0800 Subject: [PATCH] fix: xx --- src/main.ts | 59 +++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/src/main.ts b/src/main.ts index 651cac1..4503454 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,6 +38,7 @@ async function sendMessageToWeComBot( break case MessageType.MARKDOWN: payload = {msgtype: 'markdown', markdown: {content: message}} + core.debug(`payload: ${payload}`) break case MessageType.IMAGE: // message should be base64 encoded image @@ -66,40 +67,36 @@ async function sendMessageToWeComBot( } async function run() { - try { - const wxWorkBotKey = core.getInput('key', {required: true}) - if (!validateBotKey(wxWorkBotKey)) { - core.setFailed('Invalid or missing wecom bot hook key.') - return - } - - // 获取消息内容和消息类型 - const msgContent = core.getInput('content', {required: true}) - const msgType = core.getInput('type', { - required: true - }) as MessageTypeValue + const wxWorkBotKey = core.getInput('key', {required: true}) + if (!validateBotKey(wxWorkBotKey)) { + core.setFailed('Invalid or missing wecom bot hook key.') + return + } - // 验证消息类型 - if ( - ![ - MessageType.TEXT, - MessageType.IMAGE, - MessageType.MARKDOWN, - MessageType.NEWS, - MessageType.TEMPLATE_CARD - ].includes(msgType) - ) { - core.setFailed( - 'Invalid message type. Allowed types are "text", "markdown", "image", and "news".' - ) - return - } + // 获取消息内容和消息类型 + const msgContent = core.getInput('content', {required: true}) + const msgType = core.getInput('type', { + required: true + }) as MessageTypeValue - // 发送消息 - await sendMessageToWeComBot(wxWorkBotKey, msgType, msgContent) - } catch (error: any) { - core.setFailed(`An unexpected error occurred: ${error.message}`) + // 验证消息类型 + if ( + ![ + MessageType.TEXT, + MessageType.IMAGE, + MessageType.MARKDOWN, + MessageType.NEWS, + MessageType.TEMPLATE_CARD + ].includes(msgType) + ) { + core.setFailed( + 'Invalid message type. Allowed types are "text", "markdown", "image", and "news".' + ) + return } + + // 发送消息 + await sendMessageToWeComBot(wxWorkBotKey, msgType, msgContent) } run()