From 6f5b737c9e804e2fd30d946bc5dbc706373a41cb Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Tue, 8 Mar 2022 17:18:29 -0800 Subject: [PATCH] #73 added message-ts as an output --- action.yml | 2 ++ src/slack-send.js | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2a311e5e..51bb6658 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,8 @@ inputs: outputs: time: # id of output description: 'The time' + message-ts: # timestamp on the message that was posted when using bot token + description: 'The timestamp on the message that was posted into Slack when using bot token' runs: using: 'node12' main: 'dist/index.js' diff --git a/src/slack-send.js b/src/slack-send.js index bd6054a6..2e4316d2 100644 --- a/src/slack-send.js +++ b/src/slack-send.js @@ -31,6 +31,8 @@ module.exports = async function slackSend(core) { const payloadFilePath = core.getInput('payload-file-path'); + let webResponse; + if (payloadFilePath && !payload) { try { payload = await fs.readFile(path.resolve(payloadFilePath), 'utf-8'); @@ -68,7 +70,7 @@ module.exports = async function slackSend(core) { if (message.length > 0 || payload) { // post message - await web.chat.postMessage({ channel: channelId, text: message, ...(payload || {}) }); + webResponse = await web.chat.postMessage({ channel: channelId, text: message, ...(payload || {}) }); } else { console.log('Missing slack-message or payload! Did not send a message via chat.postMessage with botToken', { channel: channelId, text: message, ...(payload) }); throw new Error('Missing message content, please input a valid payload or message to send. No Message has been send.'); @@ -114,6 +116,10 @@ module.exports = async function slackSend(core) { const time = (new Date()).toTimeString(); core.setOutput('time', time); + + if (webResponse && webResponse.ts !== undefined) { + core.setOutput('message-ts', webResponse.ts); + } } catch (error) { core.setFailed(error); }