Skip to content

Commit d029761

Browse files
fix(slack): preserve optional pagination defaults
1 parent bba5661 commit d029761

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

apps/sim/blocks/blocks/slack.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,8 @@ describe('Slack block release', () => {
212212
expect(() => mapSlackV2Params({ ...values, channelMaxPages: '11' })).toThrow(
213213
'Max pages must be an integer between 1 and 10'
214214
)
215+
expect(mapSlackV2Params({ ...values, channelLimit: null, channelMaxPages: ' ' })).toMatchObject(
216+
{ limit: 100 }
217+
)
215218
})
216219
})

apps/sim/blocks/blocks/slack.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,13 +2140,20 @@ Return ONLY the integer Unix timestamp - no explanations, no quotes, no extra te
21402140
case 'list_channels': {
21412141
baseParams.includePrivate = includePrivate !== 'false'
21422142
baseParams.excludeArchived = true
2143-
const parsedLimit =
2144-
channelLimit === undefined || channelLimit === '' ? 100 : Number(channelLimit)
2143+
const hasChannelLimit =
2144+
channelLimit !== undefined &&
2145+
channelLimit !== null &&
2146+
(typeof channelLimit !== 'string' || Boolean(channelLimit.trim()))
2147+
const parsedLimit = hasChannelLimit ? Number(channelLimit) : 100
21452148
if (!Number.isInteger(parsedLimit) || parsedLimit < 1 || parsedLimit > 200) {
21462149
throw new Error('Conversations per page must be an integer between 1 and 200')
21472150
}
21482151
baseParams.limit = parsedLimit
2149-
if (channelMaxPages !== undefined && channelMaxPages !== '') {
2152+
const hasChannelMaxPages =
2153+
channelMaxPages !== undefined &&
2154+
channelMaxPages !== null &&
2155+
(typeof channelMaxPages !== 'string' || Boolean(channelMaxPages.trim()))
2156+
if (hasChannelMaxPages) {
21502157
const parsedMaxPages = Number(channelMaxPages)
21512158
if (!Number.isInteger(parsedMaxPages) || parsedMaxPages < 1 || parsedMaxPages > 10) {
21522159
throw new Error('Max pages must be an integer between 1 and 10')

apps/sim/lib/internal/slack/operations/list-conversations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ function resolveBoundedInteger(
8080
label: string,
8181
maximum: number
8282
): number {
83-
if (value === undefined) return defaultValue
83+
if (value === undefined || value === null || (typeof value === 'string' && !value.trim())) {
84+
return defaultValue
85+
}
8486
const parsed = Number(value)
8587
if (!Number.isInteger(parsed) || parsed < 1 || parsed > maximum) {
8688
throw new Error(`${label} must be an integer between 1 and ${maximum}`)

apps/sim/tools/slack/list_channels.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,20 @@ describe('Slack list channels', () => {
191191
expect(fetchMock).not.toHaveBeenCalled()
192192
})
193193

194+
it('uses defaults for unresolved optional pagination values', async () => {
195+
fetchMock.mockResolvedValueOnce(
196+
slackResponse({ ok: true, channels: [], response_metadata: { next_cursor: '' } })
197+
)
198+
199+
await executeSlackListConversationsOperation({
200+
...BASE_PARAMS,
201+
limit: null as never,
202+
maxPages: ' ' as never,
203+
})
204+
205+
expect(new URL(String(fetchMock.mock.calls[0]?.[0])).searchParams.get('limit')).toBe('100')
206+
})
207+
194208
it('fails fast on malformed successful responses and repeated cursors', async () => {
195209
fetchMock.mockResolvedValueOnce(slackResponse({ ok: true }))
196210
await expect(executeSlackListConversationsOperation(BASE_PARAMS)).rejects.toThrow(

0 commit comments

Comments
 (0)