: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(cdp): shorten Slack channel refresh cooldown (#57918)
Vasco de Krijger336fb466f1d6
diff --git a/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx b/frontend/src/lib/integrations/SlackIntegrationHelpers.tsxindex dc0b8fdf9649..d2db9d6dc8bf 100644--- a/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx+++ b/frontend/src/lib/integrations/SlackIntegrationHelpers.tsx@@ -83,7 +83,9 @@ export function SlackChannelPicker({ onChange, value, integration, disabled }: Sconst { loadAllSlackChannels, loadSlackChannelById } = useActions(slackIntegrationLogic({ id: integration.id }))const [localValue, setLocalValue] = useState<string | null>(null)- usePeriodicRerender(15000) // Re-render every 15 seconds for up-to-date `getChannelRefreshButtonDisabledReason`+ const channelRefreshButtonDisabledReason = getChannelRefreshButtonDisabledReason()+ // 1s tick while the cooldown is active so the countdown updates; otherwise idle the rerender (60s, picker is short-lived).+ usePeriodicRerender(channelRefreshButtonDisabledReason ? 1000 : 60_000)// If slackChannels aren't loaded, make sure we display only the channel name and not the actual underlying valueconst rawSlackChannelOptions = useMemo(() => getSlackChannelOptions(slackChannels), [slackChannels])@@ -137,7 +139,7 @@ export function SlackChannelPicker({ onChange, value, integration, disabled }: Saction={{children: <span className="Link">Refresh channels</span>,onClick: () => loadAllSlackChannels(true),- disabledReason: getChannelRefreshButtonDisabledReason(),+ disabledReason: channelRefreshButtonDisabledReason,}}emptyStateComponent={<p className="text-secondary italic p-1">diff --git a/frontend/src/lib/integrations/slackIntegrationLogic.test.ts b/frontend/src/lib/integrations/slackIntegrationLogic.test.tsnew file mode 100644index 000000000000..2865ad9bdc7d--- /dev/null+++ b/frontend/src/lib/integrations/slackIntegrationLogic.test.ts@@ -0,0 +1,73 @@+import { expectLogic } from 'kea-test-utils'++import { dayjs } from 'lib/dayjs'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { SLACK_CHANNELS_MIN_REFRESH_INTERVAL_SECONDS, slackIntegrationLogic } from './slackIntegrationLogic'++const FIXED_NOW = new Date('2026-01-01T12:00:00Z')++describe('slackIntegrationLogic — getChannelRefreshButtonDisabledReason', () => {+ let logic: ReturnType<typeof slackIntegrationLogic.build>+ let lastRefreshedAt: string++ beforeEach(() => {+ // Only fake `Date` so dayjs() reads a fixed wall clock; keep timers real so kea-test-utils async helpers run.+ jest.useFakeTimers({+ now: FIXED_NOW,+ doNotFake: [+ 'hrtime',+ 'nextTick',+ 'performance',+ 'queueMicrotask',+ 'requestAnimationFrame',+ 'cancelAnimationFrame',+ 'requestIdleCallback',+ 'cancelIdleCallback',+ 'setImmediate',+ 'clearImmediate',+ 'setInterval',+ 'clearInterval',+ 'setTimeout',+ 'clearTimeout',+ ],+ })+ lastRefreshedAt = ''+ useMocks({+ get: {+ '/api/environments/:team_id/integrations/:id/channels': () => [200, { channels: [], lastRefreshedAt }],+ },+ })+ initKeaTests()+ logic = slackIntegrationLogic({ id: 1 })+ logic.mount()+ })++ afterEach(() => {+ logic.unmount()+ jest.useRealTimers()+ })++ const refreshAt = async (timestamp: string): Promise<void> => {+ lastRefreshedAt = timestamp+ await expectLogic(logic, () => {+ logic.actions.loadAllSlackChannels()+ }).toFinishAllListeners()+ }++ it.each<[string, number, boolean]>([+ ['stays disabled immediately after a refresh', 0, false],+ ['stays disabled just before the cooldown elapses', SLACK_CHANNELS_MIN_REFRESH_INTERVAL_SECONDS - 1, false],+ ['enables once the cooldown has elapsed', SLACK_CHANNELS_MIN_REFRESH_INTERVAL_SECONDS + 1, true],+ ])('refresh button %s', async (_label, secondsAgo, expectEnabled) => {+ await refreshAt(dayjs(FIXED_NOW).subtract(secondsAgo, 'seconds').toISOString())+ const reason = logic.values.getChannelRefreshButtonDisabledReason()+ if (expectEnabled) {+ expect(reason).toBe('')+ } else {+ expect(reason).not.toBe('')+ }+ })+})diff --git a/frontend/src/lib/integrations/slackIntegrationLogic.ts b/frontend/src/lib/integrations/slackIntegrationLogic.tsindex 0ffbef3d9a6f..987862eb5b8c 100644--- a/frontend/src/lib/integrations/slackIntegrationLogic.ts+++ b/frontend/src/lib/integrations/slackIntegrationLogic.ts@@ -9,7 +9,7 @@ import { SlackChannelType } from '~/types'import type { slackIntegrationLogicType } from './slackIntegrationLogicType'-export const SLACK_CHANNELS_MIN_REFRESH_INTERVAL_MINUTES = 5+export const SLACK_CHANNELS_MIN_REFRESH_INTERVAL_SECONDS = 30export const slackIntegrationLogic = kea<slackIntegrationLogicType>([props({} as { id: number }),@@ -94,11 +94,14 @@ export const slackIntegrationLogic = kea<slackIntegrationLogicType>([const now = dayjs()if (allSlackChannels) {const earliestRefresh = dayjs(allSlackChannels.lastRefreshedAt).add(- SLACK_CHANNELS_MIN_REFRESH_INTERVAL_MINUTES,- 'minutes'+ SLACK_CHANNELS_MIN_REFRESH_INTERVAL_SECONDS,+ 'seconds')if (now.isBefore(earliestRefresh)) {- return `You can refresh the channels again ${earliestRefresh.from(now)}`+ const secondsLeft = Math.ceil(earliestRefresh.diff(now) / 1000)+ return `You can refresh the channels again in ${secondsLeft} second${+ secondsLeft === 1 ? '' : 's'+ }`}}return ''diff --git a/posthog/api/test/test_integration.py b/posthog/api/test/test_integration.pyindex 08a40b49c2b4..55a9d0babedf 100644--- a/posthog/api/test/test_integration.py+++ b/posthog/api/test/test_integration.py@@ -83,10 +83,10 @@ class TestSlackIntegration:channels = slack.list_channels(True, "test_user_id")mock_client.conversations_list.assert_called_once_with(- exclude_archived=True, types="public_channel", limit=200, cursor=None+ exclude_archived=True, types="public_channel", limit=1000, cursor=None)mock_client.users_conversations.assert_called_once_with(- exclude_archived=True, types="private_channel", limit=200, cursor=None, user="test_user_id"+ exclude_archived=True, types="private_channel", limit=1000, cursor=None, user="test_user_id")assert len(channels) == 4@@ -126,10 +126,10 @@ class TestSlackIntegration:channels = slack.list_channels(False, "test_user_id")mock_client.conversations_list.assert_called_once_with(- exclude_archived=True, types="public_channel", limit=200, cursor=None+ exclude_archived=True, types="public_channel", limit=1000, cursor=None)mock_client.users_conversations.assert_called_once_with(- exclude_archived=True, types="private_channel", limit=200, cursor=None, user="test_user_id"+ exclude_archived=True, types="private_channel", limit=1000, cursor=None, user="test_user_id")assert len(channels) == 4diff --git a/posthog/models/integration.py b/posthog/models/integration.pyindex 41a5e3d7d161..ec4a11f64ae4 100644--- a/posthog/models/integration.py+++ b/posthog/models/integration.py@@ -1117,6 +1117,9 @@ class SlackIntegrationError(Exception):SLACK_INTEGRATION_KINDS: tuple[str, ...] = ("slack", "slack-posthog-code")+SLACK_CHANNELS_PAGE_SIZE = 1000+SLACK_CHANNELS_MAX_PAGES = 10+class SlackIntegration:integration: Integration@@ -1176,17 +1179,23 @@ class SlackIntegration:should_include_private_channels: bool = False,authed_user: str | None = None,) -> list[dict]:- max_page = 50+ max_page = SLACK_CHANNELS_MAX_PAGESchannels = []cursor = Nonewhile max_page > 0:max_page -= 1if type == "public_channel":- res = self.client.conversations_list(exclude_archived=True, types=type, limit=200, cursor=cursor)+ res = self.client.conversations_list(+ exclude_archived=True, types=type, limit=SLACK_CHANNELS_PAGE_SIZE, cursor=cursor+ )else:res = self.client.users_conversations(- exclude_archived=True, types=type, limit=200, cursor=cursor, user=authed_user+ exclude_archived=True,+ types=type,+ limit=SLACK_CHANNELS_PAGE_SIZE,+ cursor=cursor,+ user=authed_user,)for channel in res["channels"]: