Skip to content

Commit f22e0ad

Browse files
committed
fix(search): say a filtered Slack channel is missing only after the whole lookup, and only when no result page remains
1 parent f653786 commit f22e0ad

2 files changed

Lines changed: 42 additions & 5 deletions

File tree

‎apps/sim/lib/sim-search/live/providers.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,37 @@ describe('Slack channels', () => {
454454
)
455455
})
456456

457+
it('does not call a channel missing while the lookup has more channels to return', async () => {
458+
const api = client()
459+
api.json.mockResolvedValueOnce(rts([])).mockResolvedValueOnce({
460+
...rts([channel('C7', 'company-announcements')]),
461+
response_metadata: { next_cursor: 'more' },
462+
})
463+
const result = await searchSlack(api, {
464+
...input,
465+
query: '',
466+
scopes,
467+
filters: { startDate: '2026-10-30T00:00:00Z' },
468+
native: { provider: 'slack', query: '', modifiers: 'in:#announcements' },
469+
})
470+
expect(api.json.mock.calls[1]?.[1]?.body).toMatchObject({ limit: 20 })
471+
expect(result.message).not.toContain('No channel named')
472+
expect(result.message).toContain('Channels with similar names: #company-announcements')
473+
})
474+
475+
it('says nothing about the filtered channel while Slack has another page of results', async () => {
476+
const api = client()
477+
api.json.mockResolvedValueOnce({ ...rts([]), response_metadata: { next_cursor: 'page-2' } })
478+
const result = await searchSlack(api, {
479+
...input,
480+
query: '',
481+
scopes,
482+
filters: { startDate: '2026-10-30T00:00:00Z' },
483+
native: { provider: 'slack', query: '', modifiers: 'in:#announcements' },
484+
})
485+
expect(result.message).not.toContain('#announcements')
486+
})
487+
457488
it('keeps the empty search when the channel lookup fails', async () => {
458489
const api = client()
459490
api.json

‎apps/sim/lib/sim-search/live/slack.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async function channelFilterNote(
9191
channel_types: channelTypes,
9292
include_archived_channels: input.policy?.includeArchived ?? true,
9393
content_types: ['channels'],
94-
limit: MAX_LISTED_CHANNELS,
94+
limit: SLACK_PAGE_SIZE,
9595
},
9696
})
9797
.then(slackResult)
@@ -104,9 +104,12 @@ async function channelFilterNote(
104104
const named = channels.find((channel) => channel.name.toLowerCase() === name)
105105
if (named)
106106
return `${channelLabel(named)} exists; none of its messages matched this query and date window.`
107+
/** A lookup with another page has not ruled the name out, so it only names what it found. */
108+
const complete = !string(object(data.response_metadata).next_cursor)
109+
const similar = channels.slice(0, MAX_LISTED_CHANNELS).map(channelLabel).join(', ')
107110
return joinMessages([
108-
`No channel named #${name} is visible to this account.`,
109-
channels.length ? `Channels with similar names: ${channels.map(channelLabel).join(', ')}.` : '',
111+
complete ? `No channel named #${name} is visible to this account.` : '',
112+
similar ? `Channels with similar names: ${similar}.` : '',
110113
])
111114
}
112115

@@ -295,10 +298,13 @@ async function searchSlackPage(
295298
})
296299
}
297300
const listed = listChannels ? searchableChannels(data, input).slice(0, MAX_LISTED_CHANNELS) : []
298-
const filtered = !documents.length && !cursor ? filteredChannelName(input) : undefined
301+
const nextCursor = string(object(data.response_metadata).next_cursor) || undefined
302+
/** Only a search with no result on any page can say what its channel filter matched. */
303+
const filtered =
304+
!documents.length && !cursor && !nextCursor ? filteredChannelName(input) : undefined
299305
return {
300306
documents,
301-
nextCursor: string(object(data.response_metadata).next_cursor) || undefined,
307+
nextCursor,
302308
message: joinMessages([
303309
`Slack RTS searches ${channels.join(', ')} with your user token. Semantic matching depends on your Slack plan; date ordering uses keyword retrieval. Message timestamps are posting dates; edits may not be reflected in date filtering.`,
304310
listed.length ? `Channels matching the query: ${listed.map(channelLabel).join(', ')}.` : '',

0 commit comments

Comments
 (0)