Skip to content

Commit

Permalink
feat: Add ability to create message in another message thread
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudRinquin committed Jul 3, 2020
1 parent 2b5b9c3 commit c18828d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
ts:
description: "If passed, update matching message instead of posting a new one"
required: false
threadTs:
description: "If passed, add message to thread to the message referenced"
required: false
text:
description: "The message's base text"
required: false
Expand Down
21 changes: 21 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4066,6 +4066,7 @@ async function run() {
const token = core.getInput("token", { required: true });
const channel = core.getInput("channel", { required: true });
const ts = core.getInput("ts", { required: false });
const threadTs = core.getInput("threadTs", { required: false });

const text = core.getInput("text", { required: false }) || undefined;
const blocksRaw = core.getInput("blocks", { required: false }) || undefined;
Expand Down Expand Up @@ -4117,6 +4118,26 @@ async function run() {
return;
}

if (threadTs) {
// just post a new message but as an thread
const message = {
channel,
text,
blocks,
attachments,
thread_ts: threadTs,
};
const result = await client.chat.postMessage(message);
if (result.error) {
throw new Error(
`Error while posting slack message as thread: ${result.error}`
);
}
const { ts } = result;
core.setOutput("ts", ts);
return;
}

// retrive the original message
const response = await client.conversations.history({
token,
Expand Down
21 changes: 21 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function run() {
const token = core.getInput("token", { required: true });
const channel = core.getInput("channel", { required: true });
const ts = core.getInput("ts", { required: false });
const threadTs = core.getInput("threadTs", { required: false });

const text = core.getInput("text", { required: false }) || undefined;
const blocksRaw = core.getInput("blocks", { required: false }) || undefined;
Expand Down Expand Up @@ -60,6 +61,26 @@ async function run() {
return;
}

if (threadTs) {
// just post a new message but as an thread
const message = {
channel,
text,
blocks,
attachments,
thread_ts: threadTs,
};
const result = await client.chat.postMessage(message);
if (result.error) {
throw new Error(
`Error while posting slack message as thread: ${result.error}`
);
}
const { ts } = result;
core.setOutput("ts", ts);
return;
}

// retrive the original message
const response = await client.conversations.history({
token,
Expand Down

0 comments on commit c18828d

Please sign in to comment.