diff --git a/post-message/action.yml b/post-message/action.yml index 585e24a..a78ec3c 100644 --- a/post-message/action.yml +++ b/post-message/action.yml @@ -3,10 +3,16 @@ name: Post Chat Message inputs: api-key: required: true + description: API key to authenticate with the Roam API chat-id: required: true - text: + description: Chat ID of the Roam group the message will be sent to + blocks: required: true + description: Blocks Array of the message contents + colour: + required: true + description: Colour of the Roam notification banner runs: using: node20 main: index.mjs diff --git a/post-message/index.mjs b/post-message/index.mjs index a9f0a59..7223a0a 100644 --- a/post-message/index.mjs +++ b/post-message/index.mjs @@ -3,12 +3,17 @@ import core from "@actions/core"; try { const apiKey = core.getInput("api-key"); const chatId = core.getInput("chat-id"); - const text = core.getInput("text"); + const color = core.getInput("colour"); + const blocks = core.getInput("blocks"); + + console.log(blocks); const body = JSON.stringify({ chat: chatId, - text, + color, + blocks: JSON.parse(blocks) }); + const response = await fetch("https://api.ro.am/v0/chat.post", { method: "POST", headers: { @@ -17,12 +22,18 @@ try { }, body, }); + if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + const errorBody = await response.text(); + core.error(`API request failed`); + core.error(`Status: ${response.status} ${response.statusText}`); + core.error(`Response body: ${errorBody}`); + throw new Error(`HTTP ${response.status}`); } const responseData = await response.json(); console.log("Response:", responseData); + } catch (error) { core.setFailed(error.message); -} +} \ No newline at end of file