Skip to content

Commit 65c16e1

Browse files
committed
added get thread
1 parent ad0d250 commit 65c16e1

File tree

7 files changed

+347
-5
lines changed

7 files changed

+347
-5
lines changed

apps/docs/content/docs/en/tools/slack.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,26 @@ Retrieve a specific message by its timestamp. Useful for getting a thread parent
143143
| --------- | ---- | ----------- |
144144
| `message` | object | The retrieved message object |
145145

146+
### `slack_get_thread`
147+
148+
Retrieve an entire thread including the parent message and all replies. Useful for getting full conversation context.
149+
150+
#### Input
151+
152+
| Parameter | Type | Required | Description |
153+
| --------- | ---- | -------- | ----------- |
154+
| `authMethod` | string | No | Authentication method: oauth or bot_token |
155+
| `botToken` | string | No | Bot token for Custom Bot |
156+
| `channel` | string | Yes | Slack channel ID \(e.g., C1234567890\) |
157+
| `threadTs` | string | Yes | Thread timestamp \(thread_ts\) to retrieve \(e.g., 1405894322.002768\) |
158+
| `limit` | number | No | Maximum number of messages to return \(default: 100, max: 200\) |
159+
160+
#### Output
161+
162+
| Parameter | Type | Description |
163+
| --------- | ---- | ----------- |
164+
| `parentMessage` | object | The thread parent message |
165+
146166
### `slack_list_channels`
147167

148168
List all channels in a Slack workspace. Returns public and private channels the bot has access to.

apps/sim/blocks/blocks/slack.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
2727
{ label: 'Create Canvas', id: 'canvas' },
2828
{ label: 'Read Messages', id: 'read' },
2929
{ label: 'Get Message', id: 'get_message' },
30+
{ label: 'Get Thread', id: 'get_thread' },
3031
{ label: 'List Channels', id: 'list_channels' },
3132
{ label: 'List Channel Members', id: 'list_members' },
3233
{ label: 'List Users', id: 'list_users' },
@@ -343,6 +344,42 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
343344
generationType: 'timestamp',
344345
},
345346
},
347+
// Get Thread specific fields
348+
{
349+
id: 'getThreadTimestamp',
350+
title: 'Thread Timestamp',
351+
type: 'short-input',
352+
placeholder: 'Thread timestamp (thread_ts, e.g., 1405894322.002768)',
353+
condition: {
354+
field: 'operation',
355+
value: 'get_thread',
356+
},
357+
required: true,
358+
wandConfig: {
359+
enabled: true,
360+
prompt: `Extract or generate a Slack thread timestamp from the user's input.
361+
Slack thread timestamps (thread_ts) are in the format: XXXXXXXXXX.XXXXXX (seconds.microseconds since Unix epoch).
362+
Examples:
363+
- "1405894322.002768" -> 1405894322.002768 (already a valid timestamp)
364+
- "thread_ts from the trigger" -> The user wants to reference a variable, output the original text
365+
- A URL like "https://slack.com/archives/C123/p1405894322002768" -> Extract 1405894322.002768 (remove 'p' prefix, add decimal after 10th digit)
366+
367+
If the input looks like a reference to another block's output (contains < and >) or a variable, return it as-is.
368+
Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
369+
placeholder: 'Paste a Slack thread URL or thread_ts...',
370+
generationType: 'timestamp',
371+
},
372+
},
373+
{
374+
id: 'threadLimit',
375+
title: 'Message Limit',
376+
type: 'short-input',
377+
placeholder: '100',
378+
condition: {
379+
field: 'operation',
380+
value: 'get_thread',
381+
},
382+
},
346383
{
347384
id: 'oldest',
348385
title: 'Oldest Timestamp',
@@ -458,6 +495,7 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
458495
'slack_canvas',
459496
'slack_message_reader',
460497
'slack_get_message',
498+
'slack_get_thread',
461499
'slack_list_channels',
462500
'slack_list_members',
463501
'slack_list_users',
@@ -478,6 +516,8 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
478516
return 'slack_message_reader'
479517
case 'get_message':
480518
return 'slack_get_message'
519+
case 'get_thread':
520+
return 'slack_get_thread'
481521
case 'list_channels':
482522
return 'slack_list_channels'
483523
case 'list_members':
@@ -529,6 +569,8 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
529569
userLimit,
530570
userId,
531571
getMessageTimestamp,
572+
getThreadTimestamp,
573+
threadLimit,
532574
...rest
533575
} = params
534576

@@ -612,6 +654,20 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
612654
baseParams.timestamp = getMessageTimestamp
613655
break
614656

657+
case 'get_thread': {
658+
if (!getThreadTimestamp) {
659+
throw new Error('Thread timestamp is required for get thread operation')
660+
}
661+
baseParams.threadTs = getThreadTimestamp
662+
if (threadLimit) {
663+
const parsedLimit = Number.parseInt(threadLimit, 10)
664+
if (!Number.isNaN(parsedLimit) && parsedLimit > 0) {
665+
baseParams.limit = Math.min(parsedLimit, 200)
666+
}
667+
}
668+
break
669+
}
670+
615671
case 'list_channels': {
616672
baseParams.includePrivate = includePrivate !== 'false'
617673
baseParams.excludeArchived = true
@@ -719,6 +775,12 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
719775
userId: { type: 'string', description: 'User ID to look up' },
720776
// Get Message inputs
721777
getMessageTimestamp: { type: 'string', description: 'Message timestamp to retrieve' },
778+
// Get Thread inputs
779+
getThreadTimestamp: { type: 'string', description: 'Thread timestamp to retrieve' },
780+
threadLimit: {
781+
type: 'string',
782+
description: 'Maximum number of messages to return from thread',
783+
},
722784
},
723785
outputs: {
724786
// slack_message outputs (send operation)
@@ -746,6 +808,24 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
746808
'Array of message objects with comprehensive properties: text, user, timestamp, reactions, threads, files, attachments, blocks, stars, pins, and edit history',
747809
},
748810

811+
// slack_get_thread outputs (get_thread operation)
812+
parentMessage: {
813+
type: 'json',
814+
description: 'The thread parent message with all properties',
815+
},
816+
replies: {
817+
type: 'json',
818+
description: 'Array of reply messages in the thread (excluding the parent)',
819+
},
820+
replyCount: {
821+
type: 'number',
822+
description: 'Number of replies returned in this response',
823+
},
824+
hasMore: {
825+
type: 'boolean',
826+
description: 'Whether there are more messages in the thread',
827+
},
828+
749829
// slack_list_channels outputs (list_channels operation)
750830
channels: {
751831
type: 'json',

apps/sim/tools/registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ import {
11811181
slackDeleteMessageTool,
11821182
slackDownloadTool,
11831183
slackGetMessageTool,
1184+
slackGetThreadTool,
11841185
slackGetUserTool,
11851186
slackListChannelsTool,
11861187
slackListMembersTool,
@@ -1733,6 +1734,7 @@ export const tools: Record<string, ToolConfig> = {
17331734
slack_list_users: slackListUsersTool,
17341735
slack_get_user: slackGetUserTool,
17351736
slack_get_message: slackGetMessageTool,
1737+
slack_get_thread: slackGetThreadTool,
17361738
slack_canvas: slackCanvasTool,
17371739
slack_download: slackDownloadTool,
17381740
slack_update_message: slackUpdateMessageTool,

apps/sim/tools/slack/get_message.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export const slackGetMessageTool: ToolConfig<SlackGetMessageParams, SlackGetMess
4848

4949
request: {
5050
url: (params: SlackGetMessageParams) => {
51-
const url = new URL('https://slack.com/api/conversations.replies')
51+
const url = new URL('https://slack.com/api/conversations.history')
5252
url.searchParams.append('channel', params.channel?.trim() ?? '')
53-
url.searchParams.append('ts', params.timestamp?.trim() ?? '')
53+
url.searchParams.append('oldest', params.timestamp?.trim() ?? '')
5454
url.searchParams.append('limit', '1')
5555
url.searchParams.append('inclusive', 'true')
5656
return url.toString()
@@ -77,9 +77,6 @@ export const slackGetMessageTool: ToolConfig<SlackGetMessageParams, SlackGetMess
7777
if (data.error === 'channel_not_found') {
7878
throw new Error('Channel not found. Please check the channel ID.')
7979
}
80-
if (data.error === 'thread_not_found') {
81-
throw new Error('Message not found. Please check the timestamp.')
82-
}
8380
throw new Error(data.error || 'Failed to get message from Slack')
8481
}
8582

0 commit comments

Comments
 (0)