Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sending threaded messages #119

Closed
4 of 10 tasks
nothingofuse opened this issue Aug 29, 2022 · 7 comments
Closed
4 of 10 tasks

Add support for sending threaded messages #119

nothingofuse opened this issue Aug 29, 2022 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@nothingofuse
Copy link

nothingofuse commented Aug 29, 2022

Description

Would like the ability to send a message into a thread by passing thread-ts from a previous message, with optional flag to broadcast the threaded message to the channel.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.
@filmaj filmaj added enhancement New feature or request help wanted good first issue Good for newcomers labels Aug 29, 2022
@filmaj
Copy link
Contributor

filmaj commented Aug 29, 2022

Great idea for an enhancement 👍

@kuboon
Copy link
Contributor

kuboon commented Sep 12, 2022

You can do it with "thread_ts" on payload.

see #74 (review)

@robgutsopedra
Copy link

Hey @kuboon, I tried this approach some time ago, and had some issues. Something does not work quite well with the output of the action. Let me explain my situation:

  1. First I send the message (which is properly and correctly sent)
     -  name: Slack Notification for deployment
        id: slack_notif
        uses: slackapi/slack-github-action@v1.23.0
        with:
          payload: "{\"text\":\"Manual deployment\", \"blocks\":[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Deployment of X to Y by Z , V1 to V2\"}}]}"
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
          SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
  1. And then I check the outputs of this previous step:
      - name: Run tests
        run: |-
          echo "Slack message outputs"
          echo "Ts --> " ${{ steps.slack_notif.outputs.ts }}
          echo "thread_ts --> " ${{ steps.slack_notif.outputs.thread_ts }}
          echo "time --> ${{ steps.slack_notif.outputs.time }}"
        id: run_tests

This is the result:
image

As you can see, there is no thread_ts nor ts which could help me send a threaded message.

Checking the code of the action itself, I see thread_ts or ts are only outputed in this scenario:

 if (webResponse && webResponse.ok) {
      core.setOutput('ts', webResponse.ts);
      // return the thread_ts if it exists, if not return the ts
      const thread_ts = webResponse.thread_ts ? webResponse.thread_ts : webResponse.ts;
      core.setOutput('thread_ts', thread_ts);
    }

And webResponse is only used IF bot_token is being used, never when using INCOMING_WEBHOOK / SLACK_WEBHOOK_URL

if (typeof botToken !== 'undefined' && botToken.length > 0) {
      const message = core.getInput('slack-message') || '';
      const channelIds = core.getInput('channel-id') || '';
      const web = new WebClient(botToken);

      if (channelIds.length <= 0) {
        console.log('Channel ID is required to run this action. An empty one has been provided');
        throw new Error('Channel ID is required to run this action. An empty one has been provided');
      }

      if (message.length > 0 || payload) {
        const ts = core.getInput('update-ts');
        await Promise.all(channelIds.split(',').map(async (channelId) => {
          if (ts) {
          // update message
            webResponse = await web.chat.update({ ts, channel: channelId.trim(), text: message, ...(payload || {}) });
          } else {
          // post message
            webResponse = await web.chat.postMessage({ channel: channelId.trim(), text: message, ...(payload || {}) });
          }
        }));
      } else {
        console.log('Missing slack-message or payload! Did not send a message via chat.postMessage with botToken', { channel: channelIds, text: message, ...(payload) });
        throw new Error('Missing message content, please input a valid payload or message to send. No Message has been send.');
      }
    }

@seratch seratch modified the milestones: 1.21, 1.19 Oct 18, 2022
@seratch
Copy link
Member

seratch commented Oct 18, 2022

@robgutsopedra Using thread-ts does not work along with incoming webhooks. It works only with bot token + chat.postMessage API call. Here is an example demonstrating how to use it:

- name: Post message to Slack via botToken
id: slackToken
uses: ./
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
slack-message: 'CI Post from slack-send GitHub Action! Succeeded!!'
# payload: "{\"key\":\"value\",\"foo\":\"bar\"}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
# Use the output from the `slackToken` step
- name: Check Action output is not empty
run: test -n "${{ steps.slackToken.outputs.time }}"
- name: Post Threaded Response
id: slackThreadResponse
uses: ./
with:
channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
payload: |
{
"text": "This message should be posted as a response in thread",
"thread_ts": "${{ steps.slackToken.outputs.thread_ts }}"
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

Also, this feature request is resolved in v1.19. Let me close this issue now.

@digi0pz
Copy link

digi0pz commented Aug 11, 2024

Hey @seratch,
Is there any reason thread_ts doesn't work along with Incoming Webhooks?

@seratch
Copy link
Member

seratch commented Aug 19, 2024

When you use Incoming Webhooks alone, there is no way to learn a specific message's ts (this operation requires channels:history, etc.). Therefore, to me, not supporting thread_ts for Incoming Webhooks is a reasonable API design to align with its minimal permission model. If you need to post a message, please use a combination of regular web APIs (meaning chat.postMessage + conversations.history).

@maeghan-porter
Copy link

It would be helpful if this was noted in the readme as I had to come searching and find this issue to figure out why this wasn't working for me, since the readme currently says "Incoming Webhooks conform to the same rules and functionality as any of Slack's other messaging APIs" without noting any exceptions :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

7 participants