Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(integrations): wire frontend Slack channel picker to server-side search and pagination (#60267)

Daniel Marchuk55c1daf58a4b
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index 98840b1b00bc..f2460503f667 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -1461,12 +1461,13 @@ export class ApiRequest {
public integrationSlackChannels(
id: IntegrationType['id'],
forceRefresh: boolean,
+ params?: { search?: string; limit?: number; offset?: number },
teamId?: TeamType['id']
): ApiRequest {
return this.integrations(teamId)
.addPathComponent(id)
.addPathComponent('channels')
- .withQueryString({ force_refresh: forceRefresh })
+ .withQueryString({ force_refresh: forceRefresh, ...params })
}
public integrationSlackChannelsById(
@@ -5799,9 +5800,10 @@ const api = {
},
async slackChannels(
id: IntegrationType['id'],
- forceRefresh: boolean
- ): Promise<{ channels: SlackChannelType[]; lastRefreshedAt: string }> {
- return await new ApiRequest().integrationSlackChannels(id, forceRefresh).get()
+ forceRefresh: boolean,
+ params?: { search?: string; limit?: number; offset?: number }
+ ): Promise<{ channels: SlackChannelType[]; lastRefreshedAt: string; has_more?: boolean }> {
+ return await new ApiRequest().integrationSlackChannels(id, forceRefresh, params).get()
},
async slackChannelsById(
id: IntegrationType['id'],
diff --git a/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx b/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
index d2db9d6dc8bf..53d1d1b3a18f 100644
--- a/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
+++ b/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx
@@ -74,6 +74,7 @@ export type SlackChannelPickerProps = {
export function SlackChannelPicker({ onChange, value, integration, disabled }: SlackChannelPickerProps): JSX.Element {
const {
slackChannels,
+ allSlackChannels,
allSlackChannelsLoading,
slackChannelByIdLoading,
isMemberOfSlackChannel,
@@ -127,7 +128,10 @@ export function SlackChannelPicker({ onChange, value, integration, disabled }: S
onInputChange={(val) => {
if (val) {
loadSlackChannelById(val)
+ loadAllSlackChannels(false, val)
setLocalValue(val)
+ } else {
+ loadAllSlackChannels()
}
}}
value={modifiedValue ? [modifiedValue] : []}
@@ -163,6 +167,12 @@ export function SlackChannelPicker({ onChange, value, integration, disabled }: S
loading={allSlackChannelsLoading || slackChannelByIdLoading}
/>
+ {allSlackChannels?.has_more && !allSlackChannelsLoading ? (
+ <p className="text-secondary text-xs mt-1 mb-0">
+ Only the first 200 channels are shown — type to search for a specific channel.
+ </p>
+ ) : null}
+
{showSlackMembershipWarning ? (
<LemonBanner type="info">
<div className="flex gap-2 items-center">
diff --git a/frontend/src/lib/integrations/slackIntegrationLogic.test.ts b/frontend/src/lib/integrations/slackIntegrationLogic.test.ts
index 2865ad9bdc7d..c2deff33e7c5 100644
--- a/frontend/src/lib/integrations/slackIntegrationLogic.test.ts
+++ b/frontend/src/lib/integrations/slackIntegrationLogic.test.ts
@@ -4,11 +4,103 @@ import { dayjs } from 'lib/dayjs'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
+import { SlackChannelType } from '~/types'
import { SLACK_CHANNELS_MIN_REFRESH_INTERVAL_SECONDS, slackIntegrationLogic } from './slackIntegrationLogic'
const FIXED_NOW = new Date('2026-01-01T12:00:00Z')
+describe('slackIntegrationLogic — loadAllSlackChannels search & pagination', () => {
+ let logic: ReturnType<typeof slackIntegrationLogic.build>
+ let lastChannelsQuery: Record<string, string> = {}
+ let nextChannelsResponse: { id: string; name: string }[] = [
+ { id: 'C1', name: 'general' },
+ { id: 'C2', name: 'engineering' },
+ ]
+
+ const buildChannel = (id: string, name: string): SlackChannelType => ({
+ id,
+ name,
+ is_private: false,
+ is_member: true,
+ is_ext_shared: false,
+ is_private_without_access: false,
+ })
+
+ beforeEach(() => {
+ lastChannelsQuery = {}
+ nextChannelsResponse = [
+ { id: 'C1', name: 'general' },
+ { id: 'C2', name: 'engineering' },
+ ]
+ useMocks({
+ get: {
+ '/api/environments/:team_id/integrations/:id/channels': (req) => {
+ lastChannelsQuery = Object.fromEntries(req.url.searchParams.entries())
+ return [
+ 200,
+ {
+ channels: nextChannelsResponse.map((c) => buildChannel(c.id, c.name)),
+ lastRefreshedAt: '2026-01-01T00:00:00Z',
+ has_more: true,
+ },
+ ]
+ },
+ },
+ })
+ initKeaTests()
+ logic = slackIntegrationLogic({ id: 1 })
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ })
+
+ it('forwards search and limit to the channels endpoint when search is provided', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.loadAllSlackChannels(false, 'eng')
+ }).toFinishAllListeners()
+
+ expect(lastChannelsQuery.search).toBe('eng')
+ expect(lastChannelsQuery.limit).toBe('200')
+ expect(lastChannelsQuery.force_refresh).toBe('false')
+ expect(logic.values.allSlackChannels?.has_more).toBe(true)
+ })
+
+ it('still works with no arguments (backwards compatible)', async () => {
+ await expectLogic(logic, () => {
+ logic.actions.loadAllSlackChannels()
+ }).toFinishAllListeners()
+
+ expect(lastChannelsQuery.search).toBe('')
+ expect(lastChannelsQuery.limit).toBe('200')
+ })
+
+ it('reloads the full list when a search-then-clear sequence runs', async () => {
+ // First, narrow the cache with a search — server returns only the matching subset.
+ nextChannelsResponse = [{ id: 'C2', name: 'engineering' }]
+ await expectLogic(logic, () => {
+ logic.actions.loadAllSlackChannels(false, 'eng')
+ }).toFinishAllListeners()
+
+ expect(lastChannelsQuery.search).toBe('eng')
+ expect(logic.values.slackChannels.map((c) => c.id)).toEqual(['C2'])
+
+ // Then clear: empty search must re-fetch and restore the full visible set.
+ nextChannelsResponse = [
+ { id: 'C1', name: 'general' },
+ { id: 'C2', name: 'engineering' },
+ ]
+ await expectLogic(logic, () => {
+ logic.actions.loadAllSlackChannels()
+ }).toFinishAllListeners()
+
+ expect(lastChannelsQuery.search).toBe('')
+ expect(logic.values.slackChannels.map((c) => c.id)).toEqual(['C1', 'C2'])
+ })
+})
+
describe('slackIntegrationLogic — getChannelRefreshButtonDisabledReason', () => {
let logic: ReturnType<typeof slackIntegrationLogic.build>
let lastRefreshedAt: string
diff --git a/frontend/src/lib/integrations/slackIntegrationLogic.ts b/frontend/src/lib/integrations/slackIntegrationLogic.ts
index 987862eb5b8c..139d4a1b2758 100644
--- a/frontend/src/lib/integrations/slackIntegrationLogic.ts
+++ b/frontend/src/lib/integrations/slackIntegrationLogic.ts
@@ -19,16 +19,19 @@ export const slackIntegrationLogic = kea<slackIntegrationLogicType>([
values: [preflightLogic, ['siteUrlMisconfigured', 'preflight']],
})),
actions({
- loadAllSlackChannels: (forceRefresh: boolean = false) => ({ forceRefresh }),
+ loadAllSlackChannels: (forceRefresh: boolean = false, search: string = '') => ({ forceRefresh, search }),
loadSlackChannelById: (channelId: string) => ({ channelId }),
}),
loaders(({ props }) => ({
allSlackChannels: [
- null as { channels: SlackChannelType[]; lastRefreshedAt: string } | null,
+ null as { channels: SlackChannelType[]; lastRefreshedAt: string; has_more?: boolean } | null,
{
- loadAllSlackChannels: async ({ forceRefresh }) => {
- return await api.integrations.slackChannels(props.id, forceRefresh)
+ loadAllSlackChannels: async ({ forceRefresh, search }, breakpoint) => {
+ if (search) {
+ await breakpoint(300)
+ }
+ return await api.integrations.slackChannels(props.id, forceRefresh, { search, limit: 200 })
},
},
],
diff --git a/posthog/api/test/test_integration.py b/posthog/api/test/test_integration.py
index 6e68dda6c3fd..e0c5bb4a7b63 100644
--- a/posthog/api/test/test_integration.py
+++ b/posthog/api/test/test_integration.py
@@ -1177,6 +1177,83 @@ class TestIntegrationAPIKeyAccess:
mock_slack_instance.list_channels.assert_called_once()
+ @pytest.mark.parametrize(
+ "query_string,expected_ids,expected_has_more",
+ [
+ # Default (no params) returns all visible (non-private-without-access) channels.
+ ("", ["C1", "C2", "C3"], False),
+ # Pagination beyond the dataset returns an empty page.
+ ("?limit=10&offset=10", [], False),
+ # Search + offset combine: "e" matches general+engineering in input order, offset=1 yields engineering.
+ ("?search=e&limit=1&offset=1", ["C3"], False),
+ ],
+ ids=["default-no-params", "offset-past-end", "search-with-offset"],
+ )
+ @patch("posthog.api.integration.SlackIntegration")
+ def test_channels_action_pagination_scenarios(
+ self,
+ mock_slack_class,
+ query_string: str,
+ expected_ids: list[str],
+ expected_has_more: bool,
+ client: HttpClient,
+ ):
+ slack_integration = Integration.objects.create(
+ team=self.team,
+ kind="slack",
+ integration_id="T_PAGE",
+ config={"authed_user": {"id": "test_user_id"}},
+ sensitive_config={"access_token": "test-token-123"},
+ created_by=self.user,
+ )
+ mock_slack_instance = MagicMock()
+ mock_slack_instance.list_channels.return_value = [
+ {
+ "id": "C1",
+ "name": "general",
+ "is_private": False,
+ "is_member": True,
+ "is_ext_shared": False,
+ "is_private_without_access": False,
+ },
+ {
+ "id": "C2",
+ "name": "random",
+ "is_private": False,
+ "is_member": True,
+ "is_ext_shared": False,
+ "is_private_without_access": False,
+ },
+ {
+ "id": "C3",
+ "name": "engineering",
+ "is_private": False,
+ "is_member": True,
+ "is_ext_shared": False,
+ "is_private_without_access": False,
+ },
+ ]
+ mock_slack_class.return_value = mock_slack_instance
+
+ key_value = (
+ f"test_key_slack_page_{query_string or 'default'}".replace("?", "_").replace("&", "_").replace("=", "_")
+ )
+ PersonalAPIKey.objects.create(
+ label="Test Key",
+ user=self.user,
+ secure_value=hash_key_value(key_value),
+ scopes=["integration:read"],
+ )
+
+ response = client.get(
+ f"/api/environments/{self.team.pk}/integrations/{slack_integration.id}/channels/{query_string}",
+ HTTP_AUTHORIZATION=f"Bearer {key_value}",
+ )
+ assert response.status_code == status.HTTP_200_OK
+ data = response.json()
+ assert [channel["id"] for channel in data["channels"]] == expected_ids
+ assert data["has_more"] is expected_has_more
+
def test_channels_action_with_missing_authed_user_returns_400(self, client: HttpClient):
slack_integration = Integration.objects.create(
team=self.team,