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.

feat(tasks): send comment slack dms to the task in the desktop app (#82722)

Shy Alter5857085d4cc9
diff --git a/frontend/src/scenes/appScenes.ts b/frontend/src/scenes/appScenes.ts
index 68c4718a3adf..d476f358340c 100644
--- a/frontend/src/scenes/appScenes.ts
+++ b/frontend/src/scenes/appScenes.ts
@@ -123,6 +123,7 @@ export const appScenes: Record<Scene | string, () => any> = {
[Scene.Unsubscribe]: () => import('./Unsubscribe/Unsubscribe'),
[Scene.CodeCanvasLink]: () => import('./code-canvas/CodeCanvasLink'),
[Scene.CodeChannelLink]: () => import('./code-canvas/CodeChannelLink'),
+ [Scene.CodeTaskLink]: () => import('./code-canvas/CodeTaskLink'),
[Scene.VercelConnect]: () => import('./authentication/vercel/VercelConnect'),
[Scene.VercelLinkError]: () => import('./authentication/vercel/VercelLinkError'),
[Scene.AgenticAccountMismatch]: () => import('./authentication/account/AgenticAccountMismatch'),
diff --git a/frontend/src/scenes/code-canvas/CodeTaskLink.tsx b/frontend/src/scenes/code-canvas/CodeTaskLink.tsx
new file mode 100644
index 000000000000..f447f2073244
--- /dev/null
+++ b/frontend/src/scenes/code-canvas/CodeTaskLink.tsx
@@ -0,0 +1,81 @@
+import { useEffect } from 'react'
+
+import { IconLaptop } from '@posthog/icons'
+
+import { BridgePage } from 'lib/components/BridgePage/BridgePage'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { SceneExport } from 'scenes/sceneTypes'
+
+import { DESKTOP_SCHEME } from './desktopScheme'
+
+export interface CodeTaskLinkProps {
+ taskId: string
+ commentId?: string
+ commentScope?: string
+ commentItemId?: string
+}
+
+export const scene: SceneExport<CodeTaskLinkProps> = {
+ component: CodeTaskLink,
+ paramsToProps: ({ params: { taskId }, searchParams }) => ({
+ taskId: taskId ?? '',
+ commentId: searchParams.comment || undefined,
+ commentScope: searchParams.scope || undefined,
+ commentItemId: searchParams.item || undefined,
+ }),
+}
+
+function taskDeepLink({ taskId, commentId, commentScope, commentItemId }: CodeTaskLinkProps): string {
+ const params = new URLSearchParams()
+ if (commentId) {
+ params.set('comment', commentId)
+ }
+ if (commentScope) {
+ params.set('scope', commentScope)
+ }
+ if (commentItemId) {
+ params.set('item', commentItemId)
+ }
+ const query = params.toString()
+ return `${DESKTOP_SCHEME}://task/${encodeURIComponent(taskId)}${query ? `?${query}` : ''}`
+}
+
+export function CodeTaskLink(props: CodeTaskLinkProps): JSX.Element {
+ const deepLink = props.taskId ? taskDeepLink(props) : null
+
+ useEffect(() => {
+ if (deepLink) {
+ window.location.href = deepLink
+ }
+ }, [deepLink])
+
+ return (
+ <BridgePage view="code-task-link">
+ <div className="flex flex-col items-center gap-4 text-center max-w-lg mx-auto">
+ <IconLaptop className="text-5xl shrink-0" />
+ <h2 className="text-xl font-semibold m-0">Opening in PostHog Desktop…</h2>
+ <p className="text-muted mb-0">
+ This task lives in the PostHog Desktop app. If it's installed, it should open automatically. If it
+ didn't, use the button below, or download the app.
+ </p>
+ <div className="flex flex-col items-center gap-2">
+ {deepLink && (
+ <LemonButton
+ type="primary"
+ onClick={() => {
+ window.location.href = deepLink
+ }}
+ >
+ Open in PostHog Desktop
+ </LemonButton>
+ )}
+ <LemonButton type="secondary" to="https://posthog.com/desktop" targetBlank>
+ Download PostHog Desktop
+ </LemonButton>
+ </div>
+ </div>
+ </BridgePage>
+ )
+}
+
+export default CodeTaskLink
diff --git a/frontend/src/scenes/sceneTypes.ts b/frontend/src/scenes/sceneTypes.ts
index 5c7098bc659e..b326cc1091fc 100644
--- a/frontend/src/scenes/sceneTypes.ts
+++ b/frontend/src/scenes/sceneTypes.ts
@@ -184,6 +184,7 @@ export enum Scene {
Unsubscribe = 'Unsubscribe',
CodeCanvasLink = 'CodeCanvasLink',
CodeChannelLink = 'CodeChannelLink',
+ CodeTaskLink = 'CodeTaskLink',
UserInterview = 'UserInterview',
UserInterviewResponse = 'UserInterviewResponse',
UserInterviews = 'UserInterviews',
diff --git a/frontend/src/scenes/scenes.ts b/frontend/src/scenes/scenes.ts
index 20a49be43ef0..4ac34a13b503 100644
--- a/frontend/src/scenes/scenes.ts
+++ b/frontend/src/scenes/scenes.ts
@@ -540,6 +540,7 @@ export const sceneConfigurations: Record<Scene | string, SceneConfig> = {
[Scene.Unsubscribe]: { allowUnauthenticated: true, layout: 'app-raw' },
[Scene.CodeCanvasLink]: { allowUnauthenticated: true, layout: 'app-raw' },
[Scene.CodeChannelLink]: { allowUnauthenticated: true, layout: 'app-raw' },
+ [Scene.CodeTaskLink]: { allowUnauthenticated: true, layout: 'app-raw' },
[Scene.VerifyEmail]: { allowUnauthenticated: true, layout: 'plain' },
[Scene.WebAnalyticsPageReports]: {
projectBased: true,
@@ -884,6 +885,7 @@ export const routes: Record<string, [Scene | string, string]> = {
[urls.codeCanvasLink(':channelId', ':dashboardId')]: [Scene.CodeCanvasLink, 'codeCanvasLink'],
[urls.codeChannelLink(':channelId')]: [Scene.CodeChannelLink, 'codeChannelLink'],
[urls.codeChannelLink(':channelId', ':taskId')]: [Scene.CodeChannelLink, 'codeChannelThreadLink'],
+ [urls.codeTaskLink(':taskId')]: [Scene.CodeTaskLink, 'codeTaskLink'],
[urls.integrationsRedirect(':kind')]: [Scene.IntegrationsRedirect, 'integrationsRedirect'],
[urls.integration(':slug')]: [Scene.IntegrationsLanding, 'integrationsLanding'],
[urls.stripeConfirmInstall()]: [Scene.StripeConfirmInstall, 'stripeConfirmInstall'],
diff --git a/frontend/src/scenes/urls.ts b/frontend/src/scenes/urls.ts
index 271815589075..261c57a39f87 100644
--- a/frontend/src/scenes/urls.ts
+++ b/frontend/src/scenes/urls.ts
@@ -257,6 +257,7 @@ export const urls = {
codeCanvasLink: (channelId: string, dashboardId: string): string => `/code/canvas/${channelId}/${dashboardId}`,
codeChannelLink: (channelId: string, taskId?: string): string =>
`/code/channel/${channelId}${taskId ? `/tasks/${taskId}` : ''}`,
+ codeTaskLink: (taskId: string): string => `/code/task/${taskId}`,
integration: (slug: string): string => `/integrations/${slug}`,
integrationsRedirect: (kind: string): string => `/integrations/${kind}/callback`,
stripeConfirmInstall: (): string => '/integrations/stripe/confirm-install',
diff --git a/posthog/urls.py b/posthog/urls.py
index c2cc0865e395..97c8f7c86d02 100644
--- a/posthog/urls.py
+++ b/posthog/urls.py
@@ -781,8 +781,9 @@ frontend_unauthenticated_routes = [
"organization/confirm-creation",
"login",
"unsubscribe",
- # Public bridge for desktop-app canvas share links — deep-links into PostHog Desktop.
+ # Public bridges for desktop-app share links — deep-link into PostHog Desktop.
r"code/canvas/[^/]+/[^/]+",
+ r"code/task/[^/]+",
"verify_email",
r"agentic/account-mismatch",
# OAuth redirect target when logging the local frontend into a remote cloud region;
diff --git a/products/tasks/backend/logic/services/comment_slack_dm.py b/products/tasks/backend/logic/services/comment_slack_dm.py
index 56c8d815492f..939e2b3a972d 100644
--- a/products/tasks/backend/logic/services/comment_slack_dm.py
+++ b/products/tasks/backend/logic/services/comment_slack_dm.py
@@ -11,6 +11,7 @@ a per-recipient sent marker to store.
"""
from collections.abc import Callable, Mapping
+from urllib.parse import urlencode
from uuid import UUID
from django.conf import settings
@@ -334,6 +335,14 @@ def _author_name(comment: Comment) -> str:
return f"{author.first_name} {author.last_name}".strip() or author.email or "Someone"
+def _bridge_url(*, comment: Comment, task: Task) -> str:
+ params = {"comment": str(comment.source_comment_id or comment.id)}
+ if comment.scope in _LOCATIONS and comment.item_id:
+ params["scope"] = comment.scope
+ params["item"] = comment.item_id
+ return f"{settings.SITE_URL}/code/task/{task.id}?{urlencode(params)}"
+
+
def _message(
*,
kind: str,
@@ -342,7 +351,7 @@ def _message(
organization_id: str | UUID | None,
slack_user_id_by_email: Callable[[str], str | None] | None = None,
) -> tuple[str, list[dict]]:
- url = f"{settings.SITE_URL}/project/{task.team_id}/tasks/{task.id}"
+ url = _bridge_url(comment=comment, task=task)
title = task.title or "a task"
author = _author_name(comment)
template = _HEADINGS.get(kind, _HEADINGS[TaskCommentActivity.Kind.MENTION])
diff --git a/products/tasks/backend/tests/test_comment_slack_dm.py b/products/tasks/backend/tests/test_comment_slack_dm.py
index d48dfaa74401..63438cf90008 100644
--- a/products/tasks/backend/tests/test_comment_slack_dm.py
+++ b/products/tasks/backend/tests/test_comment_slack_dm.py
@@ -207,6 +207,16 @@ class TestCommentSlackDm(CommentActivityTestCase):
self._record_activity(comment, [self.author.id])
assert self._dm_channels() == ["U-author"]
+ assert (
+ f"/code/task/{self.task.id}?comment={comment.id}&scope=desktop_canvas&item={canvas.id}" in self._dm_text()
+ )
+
+ def test_dm_links_to_the_desktop_task_bridge_anchored_on_the_comment(self):
+ comment = self._comment()
+
+ self._record_activity(comment, [self.author.id])
+
+ assert f"/code/task/{self.task.id}?comment={comment.id}" in self._dm_text()
def test_canvas_comment_does_not_dm_a_recipient_without_canvas_access(self):
personal_channel = Channel.objects.unscoped().create(