Skip to content

Commit

Permalink
fix: xx
Browse files Browse the repository at this point in the history
  • Loading branch information
akinoccc committed Aug 30, 2024
1 parent aca982b commit 31d557c
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 31d557c

Please sign in to comment.