Skip to content

Commit

Permalink
#73 added message-ts as an output
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengill committed Mar 9, 2022
1 parent 2f8da78 commit 6f5b737
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 7 additions & 1 deletion src/slack-send.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 6f5b737

Please sign in to comment.