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); }