Skip to content

Commit bc15a88

Browse files
author
aadamgough
committed
fix(slack): respect message limit, remove duplicate canonical representations
1 parent a2f14ca commit bc15a88

File tree

5 files changed

+29
-56
lines changed

5 files changed

+29
-56
lines changed

apps/sim/app/api/tools/slack/read-messages/route.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ const SlackReadMessagesSchema = z
1414
accessToken: z.string().min(1, 'Access token is required'),
1515
channel: z.string().optional().nullable(),
1616
userId: z.string().optional().nullable(),
17-
limit: z.number().optional().nullable(),
17+
limit: z.coerce
18+
.number()
19+
.min(1, 'Limit must be at least 1')
20+
.max(15, 'Limit cannot exceed 15')
21+
.optional()
22+
.nullable(),
1823
oldest: z.string().optional().nullable(),
1924
latest: z.string().optional().nullable(),
2025
})
@@ -62,8 +67,8 @@ export async function POST(request: NextRequest) {
6267

6368
const url = new URL('https://slack.com/api/conversations.history')
6469
url.searchParams.append('channel', channel!)
65-
const limit = validatedData.limit ? Number(validatedData.limit) : 10
66-
url.searchParams.append('limit', String(Math.min(limit, 15)))
70+
const limit = validatedData.limit ?? 10
71+
url.searchParams.append('limit', String(limit))
6772

6873
if (validatedData.oldest) {
6974
url.searchParams.append('oldest', validatedData.oldest)

apps/sim/blocks/blocks/microsoft_planner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ export const MicrosoftPlannerBlock: BlockConfig<MicrosoftPlannerResponse> = {
134134
placeholder: 'Enter the bucket ID',
135135
condition: { field: 'operation', value: ['read_bucket', 'update_bucket', 'delete_bucket'] },
136136
dependsOn: ['credential'],
137-
canonicalParamId: 'bucketId',
138137
},
139138

140139
// ETag for update/delete operations

apps/sim/blocks/blocks/slack.ts

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { SlackIcon } from '@/components/icons'
2+
import { createLogger } from '@/lib/logs/console/logger'
23
import type { BlockConfig } from '@/blocks/types'
34
import { AuthMode } from '@/blocks/types'
45
import type { SlackResponse } from '@/tools/slack/types'
56
import { getTrigger } from '@/triggers'
67

8+
const logger = createLogger('SlackBlock')
9+
710
export const SlackBlock: BlockConfig<SlackResponse> = {
811
type: 'slack',
912
name: 'Slack',
@@ -181,7 +184,6 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
181184
id: 'threadTs',
182185
title: 'Thread Timestamp',
183186
type: 'short-input',
184-
canonicalParamId: 'thread_ts',
185187
placeholder: 'Reply to thread (e.g., 1405894322.002768)',
186188
condition: {
187189
field: 'operation',
@@ -263,7 +265,6 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
263265
id: 'channelLimit',
264266
title: 'Channel Limit',
265267
type: 'short-input',
266-
canonicalParamId: 'limit',
267268
placeholder: '100',
268269
condition: {
269270
field: 'operation',
@@ -275,7 +276,6 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
275276
id: 'memberLimit',
276277
title: 'Member Limit',
277278
type: 'short-input',
278-
canonicalParamId: 'limit',
279279
placeholder: '100',
280280
condition: {
281281
field: 'operation',
@@ -301,7 +301,6 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
301301
id: 'userLimit',
302302
title: 'User Limit',
303303
type: 'short-input',
304-
canonicalParamId: 'limit',
305304
placeholder: '100',
306305
condition: {
307306
field: 'operation',
@@ -358,7 +357,6 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
358357
id: 'updateTimestamp',
359358
title: 'Message Timestamp',
360359
type: 'short-input',
361-
canonicalParamId: 'timestamp',
362360
placeholder: 'Message timestamp (e.g., 1405894322.002768)',
363361
condition: {
364362
field: 'operation',
@@ -382,7 +380,6 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
382380
id: 'deleteTimestamp',
383381
title: 'Message Timestamp',
384382
type: 'short-input',
385-
canonicalParamId: 'timestamp',
386383
placeholder: 'Message timestamp (e.g., 1405894322.002768)',
387384
condition: {
388385
field: 'operation',
@@ -395,7 +392,6 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
395392
id: 'reactionTimestamp',
396393
title: 'Message Timestamp',
397394
type: 'short-input',
398-
canonicalParamId: 'timestamp',
399395
placeholder: 'Message timestamp (e.g., 1405894322.002768)',
400396
condition: {
401397
field: 'operation',
@@ -407,7 +403,6 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
407403
id: 'emojiName',
408404
title: 'Emoji Name',
409405
type: 'short-input',
410-
canonicalParamId: 'name',
411406
placeholder: 'Emoji name without colons (e.g., thumbsup, heart, eyes)',
412407
condition: {
413408
field: 'operation',
@@ -554,47 +549,35 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
554549
baseParams.content = content
555550
break
556551

557-
case 'read':
558-
if (limit) {
559-
const parsedLimit = Number.parseInt(limit, 10)
560-
baseParams.limit = !Number.isNaN(parsedLimit) ? parsedLimit : 10
561-
} else {
562-
baseParams.limit = 10
552+
case 'read': {
553+
const parsedLimit = limit ? Number.parseInt(limit, 10) : 10
554+
if (Number.isNaN(parsedLimit) || parsedLimit < 1 || parsedLimit > 15) {
555+
throw new Error('Message limit must be between 1 and 15')
563556
}
557+
baseParams.limit = parsedLimit
564558
if (oldest) {
565559
baseParams.oldest = oldest
566560
}
567561
break
562+
}
568563

569-
case 'list_channels':
564+
case 'list_channels': {
570565
baseParams.includePrivate = includePrivate !== 'false'
571566
baseParams.excludeArchived = true
572-
if (channelLimit) {
573-
const parsedLimit = Number.parseInt(channelLimit, 10)
574-
baseParams.limit = !Number.isNaN(parsedLimit) ? parsedLimit : 100
575-
} else {
576-
baseParams.limit = 100
577-
}
567+
baseParams.limit = channelLimit ? Number.parseInt(channelLimit, 10) : 100
578568
break
569+
}
579570

580-
case 'list_members':
581-
if (memberLimit) {
582-
const parsedLimit = Number.parseInt(memberLimit, 10)
583-
baseParams.limit = !Number.isNaN(parsedLimit) ? parsedLimit : 100
584-
} else {
585-
baseParams.limit = 100
586-
}
571+
case 'list_members': {
572+
baseParams.limit = memberLimit ? Number.parseInt(memberLimit, 10) : 100
587573
break
574+
}
588575

589-
case 'list_users':
576+
case 'list_users': {
590577
baseParams.includeDeleted = includeDeleted === 'true'
591-
if (userLimit) {
592-
const parsedLimit = Number.parseInt(userLimit, 10)
593-
baseParams.limit = !Number.isNaN(parsedLimit) ? parsedLimit : 100
594-
} else {
595-
baseParams.limit = 100
596-
}
578+
baseParams.limit = userLimit ? Number.parseInt(userLimit, 10) : 100
597579
break
580+
}
598581

599582
case 'get_user':
600583
if (!userId) {

apps/sim/blocks/blocks/wealthbox.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ export const WealthboxBlock: BlockConfig<WealthboxResponse> = {
7070
title: 'Task ID',
7171
type: 'short-input',
7272
placeholder: 'Enter Task ID',
73-
mode: 'basic',
74-
canonicalParamId: 'taskId',
75-
condition: { field: 'operation', value: ['read_task'] },
76-
},
77-
{
78-
id: 'manualTaskId',
79-
title: 'Task ID',
80-
type: 'short-input',
81-
canonicalParamId: 'taskId',
82-
placeholder: 'Enter Task ID',
83-
mode: 'advanced',
8473
condition: { field: 'operation', value: ['read_task'] },
8574
},
8675
{
@@ -167,12 +156,10 @@ export const WealthboxBlock: BlockConfig<WealthboxResponse> = {
167156
}
168157
},
169158
params: (params) => {
170-
const { credential, operation, contactId, manualContactId, taskId, manualTaskId, ...rest } =
171-
params
159+
const { credential, operation, contactId, manualContactId, taskId, ...rest } = params
172160

173-
// Handle both selector and manual inputs
161+
// Handle both selector and manual inputs for contactId
174162
const effectiveContactId = (contactId || manualContactId || '').trim()
175-
const effectiveTaskId = (taskId || manualTaskId || '').trim()
176163

177164
const baseParams = {
178165
...rest,
@@ -225,7 +212,6 @@ export const WealthboxBlock: BlockConfig<WealthboxResponse> = {
225212
contactId: { type: 'string', description: 'Contact identifier' },
226213
manualContactId: { type: 'string', description: 'Manual contact identifier' },
227214
taskId: { type: 'string', description: 'Task identifier' },
228-
manualTaskId: { type: 'string', description: 'Manual task identifier' },
229215
content: { type: 'string', description: 'Content text' },
230216
firstName: { type: 'string', description: 'First name' },
231217
lastName: { type: 'string', description: 'Last name' },

apps/sim/tools/slack/message_reader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const slackMessageReaderTool: ToolConfig<
5151
type: 'number',
5252
required: false,
5353
visibility: 'user-or-llm',
54-
description: 'Number of messages to retrieve (default: 10, max: 100)',
54+
description: 'Number of messages to retrieve (default: 10, max: 15)',
5555
},
5656
oldest: {
5757
type: 'string',

0 commit comments

Comments
 (0)