'Where do I get `thread_ts` to start a Slack thread with an incoming webhook?

On Slack's incoming webhook documentation, they mention including the thread_ts in the request body to start a thread.

{
    "text": "Hello, world.",
    "thread_ts": "12345.6789"
}

When I make the POST request to my incoming webhook url, the response body does not include the thread_ts. I was expecting the thread_ts to be in the response body, but the response body just says ok and does not include any json.

Is it possible to get the thread_ts without another app or authentication token? Do I have to use another Slack API? I only have the incoming webhook configured right now.


As a side note, if this is easier to do with Slack's new Block Kit API, that would work as well.



Solution 1:[1]

To take full control of all messaging features of Slack including threads you want to use the API.

When posting messages with chat.postMessage you get the thread_ts value and can start creating threads.

Also check out this official documentation on threads. It clears up a lot.

I am not an export on the new blocks yet, but as far as I understand it replaced the attachments and provides a more flexible way for message layouts. It does however not change the way threading works.

Solution 2:[2]

from slack_sdk import WebClient
slack_client = WebClient(token='token_value')    
response = slack_client.chat_postMessage(channel=receiver, text=message)
print(response.data)
thread_ts = response.data['ts']

Solution 3:[3]

In case of Bolt api (js) you can check ts value from callback arguments.

app.message(
    "link please",
    async ({ message, say }) => { // You can also get ts from `payload`
        console.log(message);
        await say({
            text: "you can check this link",
            thread_ts: message.ts, // you can get ts from message
        });
    });

message content:

{
  client_msg_id: 'xxxxx',
  type: 'message',
  text: 'xxxx',
  user: 'UxxR',
  ts: '1650249299.335499',
  team: 'xxxx',
  blocks: [ { type: 'rich_text', block_id: 'adOR', elements: [Array] } ],
  thread_ts: '1650249116.347219',
  parent_user_id: 'UxxxxxR',
  channel: 'C01TNEN8SSK',
  event_ts: '1650249299.335499',
  channel_type: 'group'
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Erik Kalkoken
Solution 2 Adrian Mole
Solution 3 Zimin Byun