Skip to content

Commit 6c56d48

Browse files
authored
feat(slack): added slack full message object in response (#1987)
1 parent 1082e55 commit 6c56d48

File tree

8 files changed

+304
-47
lines changed

8 files changed

+304
-47
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ Send messages to Slack channels or users through the Slack API. Supports Slack m
7373

7474
| Parameter | Type | Description |
7575
| --------- | ---- | ----------- |
76+
| `message` | object | Complete message object with all properties returned by Slack |
7677
| `ts` | string | Message timestamp |
7778
| `channel` | string | Channel ID where message was sent |
79+
| `fileCount` | number | Number of files uploaded \(when files are attached\) |
7880

7981
### `slack_canvas`
8082

@@ -157,6 +159,7 @@ Update a message previously sent by the bot in Slack
157159

158160
| Parameter | Type | Description |
159161
| --------- | ---- | ----------- |
162+
| `message` | object | Complete updated message object with all properties returned by Slack |
160163
| `content` | string | Success message |
161164
| `metadata` | object | Updated message metadata |
162165

apps/sim/app/api/tools/slack/send-message/route.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,16 @@ export async function POST(request: NextRequest) {
7878
}
7979

8080
logger.info(`[${requestId}] Message sent successfully`)
81+
const messageObj = data.message || {
82+
type: 'message',
83+
ts: data.ts,
84+
text: validatedData.text,
85+
channel: data.channel,
86+
}
8187
return NextResponse.json({
8288
success: true,
8389
output: {
90+
message: messageObj,
8491
ts: data.ts,
8592
channel: data.channel,
8693
},
@@ -107,9 +114,16 @@ export async function POST(request: NextRequest) {
107114
})
108115

109116
const data = await response.json()
117+
const messageObj = data.message || {
118+
type: 'message',
119+
ts: data.ts,
120+
text: validatedData.text,
121+
channel: data.channel,
122+
}
110123
return NextResponse.json({
111124
success: true,
112125
output: {
126+
message: messageObj,
113127
ts: data.ts,
114128
channel: data.channel,
115129
},
@@ -174,9 +188,16 @@ export async function POST(request: NextRequest) {
174188
})
175189

176190
const data = await response.json()
191+
const messageObj = data.message || {
192+
type: 'message',
193+
ts: data.ts,
194+
text: validatedData.text,
195+
channel: data.channel,
196+
}
177197
return NextResponse.json({
178198
success: true,
179199
output: {
200+
message: messageObj,
180201
ts: data.ts,
181202
channel: data.channel,
182203
},
@@ -211,10 +232,28 @@ export async function POST(request: NextRequest) {
211232

212233
logger.info(`[${requestId}] Files uploaded and shared successfully`)
213234

235+
// For file uploads, construct a message object
236+
const fileTs = completeData.files?.[0]?.created?.toString() || (Date.now() / 1000).toString()
237+
const fileMessage = {
238+
type: 'message',
239+
ts: fileTs,
240+
text: validatedData.text,
241+
channel: validatedData.channel,
242+
files: completeData.files?.map((file: any) => ({
243+
id: file?.id,
244+
name: file?.name,
245+
mimetype: file?.mimetype,
246+
size: file?.size,
247+
url_private: file?.url_private,
248+
permalink: file?.permalink,
249+
})),
250+
}
251+
214252
return NextResponse.json({
215253
success: true,
216254
output: {
217-
ts: completeData.files?.[0]?.created || Date.now() / 1000,
255+
message: fileMessage,
256+
ts: fileTs,
218257
channel: validatedData.channel,
219258
fileCount: uploadedFileIds.length,
220259
},

apps/sim/app/api/tools/slack/update-message/route.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,22 @@ export async function POST(request: NextRequest) {
7878
timestamp: data.ts,
7979
})
8080

81+
const messageObj = data.message || {
82+
type: 'message',
83+
ts: data.ts,
84+
text: data.text || validatedData.text,
85+
channel: data.channel,
86+
}
87+
8188
return NextResponse.json({
8289
success: true,
8390
output: {
91+
message: messageObj,
8492
content: 'Message updated successfully',
8593
metadata: {
8694
channel: data.channel,
8795
timestamp: data.ts,
88-
text: data.text,
96+
text: data.text || validatedData.text,
8997
},
9098
},
9199
})

apps/sim/blocks/blocks/slack.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,18 +464,29 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
464464
thread_ts: { type: 'string', description: 'Thread timestamp for reply' },
465465
},
466466
outputs: {
467-
// slack_message outputs
467+
// slack_message outputs (send operation)
468+
message: {
469+
type: 'json',
470+
description:
471+
'Complete message object with all properties: ts, text, user, channel, reactions, threads, files, attachments, blocks, stars, pins, and edit history',
472+
},
473+
// Legacy properties for send operation (backward compatibility)
468474
ts: { type: 'string', description: 'Message timestamp returned by Slack API' },
469475
channel: { type: 'string', description: 'Channel identifier where message was sent' },
476+
fileCount: {
477+
type: 'number',
478+
description: 'Number of files uploaded (when files are attached)',
479+
},
470480

471481
// slack_canvas outputs
472482
canvas_id: { type: 'string', description: 'Canvas identifier for created canvases' },
473483
title: { type: 'string', description: 'Canvas title' },
474484

475-
// slack_message_reader outputs
485+
// slack_message_reader outputs (read operation)
476486
messages: {
477487
type: 'json',
478-
description: 'Array of message objects with text, user, timestamp, and file attachments',
488+
description:
489+
'Array of message objects with comprehensive properties: text, user, timestamp, reactions, threads, files, attachments, blocks, stars, pins, and edit history',
479490
},
480491

481492
// slack_download outputs
@@ -484,6 +495,13 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
484495
description: 'Downloaded file stored in execution files',
485496
},
486497

498+
// slack_update_message outputs (update operation)
499+
content: { type: 'string', description: 'Success message for update operation' },
500+
metadata: {
501+
type: 'json',
502+
description: 'Updated message metadata (legacy, use message object instead)',
503+
},
504+
487505
// Trigger outputs (when used as webhook trigger)
488506
event_type: { type: 'string', description: 'Type of Slack event that triggered the workflow' },
489507
channel_name: { type: 'string', description: 'Human-readable channel name' },

apps/sim/tools/slack/message.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,16 @@ export const slackMessageTool: ToolConfig<SlackMessageParams, SlackMessageRespon
8787
},
8888

8989
outputs: {
90+
message: {
91+
type: 'object',
92+
description: 'Complete message object with all properties returned by Slack',
93+
},
94+
// Legacy properties for backward compatibility
9095
ts: { type: 'string', description: 'Message timestamp' },
9196
channel: { type: 'string', description: 'Channel ID where message was sent' },
97+
fileCount: {
98+
type: 'number',
99+
description: 'Number of files uploaded (when files are attached)',
100+
},
92101
},
93102
}

apps/sim/tools/slack/message_reader.ts

Lines changed: 120 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,59 @@ export const slackMessageReaderTool: ToolConfig<
8989
const data = await response.json()
9090

9191
const messages = (data.messages || []).map((message: any) => ({
92+
// Core properties
93+
type: message.type || 'message',
9294
ts: message.ts,
9395
text: message.text || '',
94-
user: message.user || message.bot_id || 'unknown',
95-
type: message.type || 'message',
96+
user: message.user,
97+
bot_id: message.bot_id,
98+
username: message.username,
99+
channel: message.channel,
100+
team: message.team,
101+
102+
// Thread properties
103+
thread_ts: message.thread_ts,
104+
parent_user_id: message.parent_user_id,
105+
reply_count: message.reply_count,
106+
reply_users_count: message.reply_users_count,
107+
latest_reply: message.latest_reply,
108+
subscribed: message.subscribed,
109+
last_read: message.last_read,
110+
unread_count: message.unread_count,
111+
112+
// Message subtype
96113
subtype: message.subtype,
114+
115+
// Reactions and interactions
116+
reactions: message.reactions?.map((reaction: any) => ({
117+
name: reaction.name,
118+
count: reaction.count,
119+
users: reaction.users || [],
120+
})),
121+
is_starred: message.is_starred,
122+
pinned_to: message.pinned_to,
123+
124+
// Content attachments
97125
files: message.files?.map((file: any) => ({
98126
id: file.id,
99127
name: file.name,
100128
mimetype: file.mimetype,
101129
size: file.size,
102130
url_private: file.url_private,
131+
permalink: file.permalink,
132+
mode: file.mode,
103133
})),
134+
attachments: message.attachments,
135+
blocks: message.blocks,
136+
137+
// Metadata
138+
edited: message.edited
139+
? {
140+
user: message.edited.user,
141+
ts: message.edited.ts,
142+
}
143+
: undefined,
144+
permalink: message.permalink,
104145
}))
105146

106147
return {
@@ -118,24 +159,91 @@ export const slackMessageReaderTool: ToolConfig<
118159
items: {
119160
type: 'object',
120161
properties: {
121-
ts: { type: 'string' },
122-
text: { type: 'string' },
123-
user: { type: 'string' },
124-
type: { type: 'string' },
125-
subtype: { type: 'string' },
162+
// Core properties
163+
type: { type: 'string', description: 'Message type' },
164+
ts: { type: 'string', description: 'Message timestamp' },
165+
text: { type: 'string', description: 'Message text content' },
166+
user: { type: 'string', description: 'User ID who sent the message' },
167+
bot_id: { type: 'string', description: 'Bot ID if sent by a bot' },
168+
username: { type: 'string', description: 'Display username' },
169+
channel: { type: 'string', description: 'Channel ID' },
170+
team: { type: 'string', description: 'Team ID' },
171+
172+
// Thread properties
173+
thread_ts: { type: 'string', description: 'Thread parent message timestamp' },
174+
parent_user_id: { type: 'string', description: 'User ID of thread parent' },
175+
reply_count: { type: 'number', description: 'Number of thread replies' },
176+
reply_users_count: { type: 'number', description: 'Number of users who replied' },
177+
latest_reply: { type: 'string', description: 'Timestamp of latest reply' },
178+
subscribed: { type: 'boolean', description: 'Whether user is subscribed to thread' },
179+
last_read: { type: 'string', description: 'Last read timestamp' },
180+
unread_count: { type: 'number', description: 'Number of unread messages' },
181+
182+
// Message subtype
183+
subtype: { type: 'string', description: 'Message subtype' },
184+
185+
// Reactions and interactions
186+
reactions: {
187+
type: 'array',
188+
description: 'Array of reactions on this message',
189+
items: {
190+
type: 'object',
191+
properties: {
192+
name: { type: 'string', description: 'Emoji name' },
193+
count: { type: 'number', description: 'Number of reactions' },
194+
users: {
195+
type: 'array',
196+
description: 'Array of user IDs who reacted',
197+
items: { type: 'string' },
198+
},
199+
},
200+
},
201+
},
202+
is_starred: { type: 'boolean', description: 'Whether message is starred' },
203+
pinned_to: {
204+
type: 'array',
205+
description: 'Array of channel IDs where message is pinned',
206+
items: { type: 'string' },
207+
},
208+
209+
// Content attachments
126210
files: {
127211
type: 'array',
212+
description: 'Array of files attached to message',
128213
items: {
129214
type: 'object',
130215
properties: {
131-
id: { type: 'string' },
132-
name: { type: 'string' },
133-
mimetype: { type: 'string' },
134-
size: { type: 'number' },
135-
url_private: { type: 'string' },
216+
id: { type: 'string', description: 'File ID' },
217+
name: { type: 'string', description: 'File name' },
218+
mimetype: { type: 'string', description: 'MIME type' },
219+
size: { type: 'number', description: 'File size in bytes' },
220+
url_private: { type: 'string', description: 'Private download URL' },
221+
permalink: { type: 'string', description: 'Permanent link to file' },
222+
mode: { type: 'string', description: 'File mode' },
136223
},
137224
},
138225
},
226+
attachments: {
227+
type: 'array',
228+
description: 'Array of legacy attachments',
229+
items: { type: 'object' },
230+
},
231+
blocks: {
232+
type: 'array',
233+
description: 'Array of Block Kit blocks',
234+
items: { type: 'object' },
235+
},
236+
237+
// Metadata
238+
edited: {
239+
type: 'object',
240+
description: 'Edit information if message was edited',
241+
properties: {
242+
user: { type: 'string', description: 'User ID who edited' },
243+
ts: { type: 'string', description: 'Edit timestamp' },
244+
},
245+
},
246+
permalink: { type: 'string', description: 'Permanent link to message' },
139247
},
140248
},
141249
},

0 commit comments

Comments
 (0)