Using the ts of a Slack message (e.g. 1234567890.123456), how can I know if that message is reply in a thread or a regular message in a channel?
This is not about how to post a message in a thread, which is easy. It is about how to identify whether a specific message is a regular message or a thread reply (because surprisingly, the Slack API documentation makes this extremely confusing).
More specifically, Slack mentions in multiple places to use the conversation.history endpoint in order to retrieve a single message, but that method is unable to retrieve messages from threads.
See more details in this GitHub issue.
The conversations.replies API endpoint is the way to go.
It's very simple, using the ts of any message:
https://slack.com/api/conversations.replies?channel=C1C1C1C1C1&ts=1234567890.123456
If the message is a regular message without thread/replies, the response will only contain ts and no thread_ts.
ts as the thread_ts to post the first reply.If the message is a regular message with a thread/replies, the response will contain ts as well as thread_ts, and both values will be the same (along with other things like reply_count, reply_users_count, and latest_reply).
ts / thread_ts to add a new reply.If the message is a reply within a thread, the response will contain ts as well as thread_ts, and the values will be different (and there won't be any other things like reply_count, reply_users_count, and latest_reply).
thread_ts to add a new reply.