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(subscriptions): guide Teams webhook setup (#103896)

Matt Puaa377a5681625
diff --git a/ee/tasks/subscriptions/teams_subscriptions.py b/ee/tasks/subscriptions/teams_subscriptions.py
index b81e463a4a3d..35abb9e5c2b1 100644
--- a/ee/tasks/subscriptions/teams_subscriptions.py
+++ b/ee/tasks/subscriptions/teams_subscriptions.py
@@ -27,8 +27,9 @@ TEAMS_WEBHOOK_URL_MASKED_ERROR = (
)
TEAMS_WEBHOOK_URL_ERROR = (
- "This does not look like a Microsoft Teams webhook URL. Create one with the Workflows app in the "
- "channel you want reports in, then paste the URL it gives you. Microsoft's setup guide: "
+ "Paste the full URL generated by a Teams workflow. In the channel, open Workflows and create a workflow that "
+ "posts when a webhook request is received. The URL usually starts with https://...logic.azure.com/.... "
+ "Learn how to create a Teams webhook: "
"https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook"
)
diff --git a/products/subscriptions/frontend/components/Subscriptions/SubscriptionWizard.tsx b/products/subscriptions/frontend/components/Subscriptions/SubscriptionWizard.tsx
index 74afb63c25be..20436f66164b 100644
--- a/products/subscriptions/frontend/components/Subscriptions/SubscriptionWizard.tsx
+++ b/products/subscriptions/frontend/components/Subscriptions/SubscriptionWizard.tsx
@@ -114,6 +114,7 @@ export function SubscriptionWizard({
subscriptionInitialized,
isSubscriptionSubmitting,
subscriptionChanged,
+ subscriptionValidationErrors,
} = useValues(subscriptionFormLogic)
const { generatePreview, resetSubscription } = useActions(subscriptionFormLogic)
const { preflight } = useValues(preflightLogic)
@@ -152,9 +153,11 @@ export function SubscriptionWizard({
contentDisabledReason = 'Select at least one insight'
}
const emailAvailable = subscription.target_type !== 'email' || Boolean(preflight?.email_service_available)
+ const targetValueValidationError = subscriptionValidationErrors.target_value
const destinationReady = Boolean(
emailAvailable &&
subscription.target_value &&
+ !targetValueValidationError &&
(subscription.target_type !== 'slack' || subscription.integration_id)
)
const requiresDeliveryDays = shouldShowDayPicker(subscription.frequency, subscription.interval)
@@ -166,9 +169,11 @@ export function SubscriptionWizard({
)
let destinationDisabledReason: string | undefined
if (!destinationReady) {
- destinationDisabledReason = emailAvailable
- ? 'Choose a destination and recipient'
- : 'Email delivery is not configured for this PostHog instance'
+ destinationDisabledReason = !emailAvailable
+ ? 'Email delivery is not configured for this PostHog instance'
+ : typeof targetValueValidationError === 'string'
+ ? targetValueValidationError
+ : 'Choose a destination and recipient'
}
const currentStepIndex = steps.findIndex((step) => step.key === currentStep)
const goToStep = (step: SubscriptionWizardStep): void => {
@@ -427,6 +432,39 @@ function SubscriptionDeliveryStep({
</>
)
) : null}
+ {subscription.target_type === 'teams' ? (
+ <LemonField
+ name="target_value"
+ label="Microsoft Teams webhook URL"
+ help={
+ <div>
+ <p className="m-0 mb-2">
+ In Teams, open the channel's Workflows menu. Create a workflow that posts when a webhook
+ request is received.
+ </p>
+ <p className="m-0 mb-2">
+ Paste the URL it gives you here. It usually starts with{' '}
+ <code>https://...logic.azure.com/...</code>.{' '}
+ <Link
+ to="https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook"
+ target="_blank"
+ targetBlankIcon
+ >
+ Learn how to create a Teams webhook
+ </Link>
+ .
+ </p>
+ <p className="m-0">Keep this URL private. Anyone with it can post to the channel.</p>
+ </div>
+ }
+ >
+ <LemonInput
+ placeholder="https://prod-00.westeurope.logic.azure.com/workflows/..."
+ autoComplete="off"
+ data-attr="subscription-teams-webhook-url"
+ />
+ </LemonField>
+ ) : null}
</div>
)
}
@@ -717,7 +755,13 @@ function SubscriptionReviewStep({
},
]
: []),
- { label: 'Sends to', value: subscription.target_value },
+ {
+ label: 'Sends to',
+ value:
+ subscription.target_type === 'teams'
+ ? 'Microsoft Teams webhook URL (not shown)'
+ : subscription.target_value,
+ },
{ label: 'Runs', value: formatSubscriptionSchedule(subscription) },
...(dashboard
? [
diff --git a/products/subscriptions/frontend/components/Subscriptions/subscriptionLogic.test.ts b/products/subscriptions/frontend/components/Subscriptions/subscriptionLogic.test.ts
index c82de2e77690..2d761dd8e61d 100644
--- a/products/subscriptions/frontend/components/Subscriptions/subscriptionLogic.test.ts
+++ b/products/subscriptions/frontend/components/Subscriptions/subscriptionLogic.test.ts
@@ -31,6 +31,13 @@ const Insight1 = '1' as InsightShortId
const TEAMS_WEBHOOK_URL =
'https://prod-12.westeurope.logic.azure.com/workflows/00000000/triggers/manual/paths/invoke?api-version=2016-06-01&sig=not-a-real-signature'
+const TEAMS_WEBHOOK_URLS = [
+ TEAMS_WEBHOOK_URL,
+ 'https://tenant.webhook.office.com/webhookb2/id/IncomingWebhook/id/id',
+ 'https://region.powerautomate.com/workflows/id',
+ 'https://tenant.environment.api.powerplatform.com:443/powerautomate/automations/direct/cluster/workflows/id',
+ 'https://tenant.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/id',
+]
export const fixtureSubscriptionResponse = (id: number, args: Partial<SubscriptionType> = {}): SubscriptionType =>
({
@@ -813,13 +820,36 @@ describe('subscriptionLogic', () => {
})
it.each<[string, string, string | undefined]>([
- ['accepts a webhook URL', TEAMS_WEBHOOK_URL, undefined],
+ ...TEAMS_WEBHOOK_URLS.map((url): [string, string, string | undefined] => [
+ 'accepts a Teams webhook URL',
+ url,
+ undefined,
+ ]),
['accepts a webhook URL pasted with stray whitespace', ` ${TEAMS_WEBHOOK_URL}\n`, undefined],
- ['rejects a channel name', 'reports', 'The webhook URL must start with https://'],
+ [
+ 'rejects a channel name',
+ 'reports',
+ 'Paste the full URL generated by Teams. It usually starts with https://...logic.azure.com/...',
+ ],
[
'rejects a plain-HTTP URL',
'http://prod-12.westeurope.logic.azure.com/workflows/1',
- 'The webhook URL must start with https://',
+ 'Paste the full URL generated by Teams. It usually starts with https://...logic.azure.com/...',
+ ],
+ [
+ 'rejects a URL without a domain',
+ 'https://adada',
+ 'Paste the full URL generated by Teams. It usually starts with https://...logic.azure.com/...',
+ ],
+ [
+ 'rejects a non-Teams URL',
+ 'https://google.ca',
+ 'Paste the full URL generated by Teams. It usually starts with https://...logic.azure.com/...',
+ ],
+ [
+ 'rejects an incomplete Azure Logic Apps URL',
+ 'https://us-west-2.logic.azure.com/adada',
+ 'Paste the full URL generated by Teams. It usually starts with https://...logic.azure.com/...',
],
['rejects an empty value', '', 'A webhook URL is required'],
['rejects a whitespace-only value', ' ', 'A webhook URL is required'],
diff --git a/products/subscriptions/frontend/components/Subscriptions/subscriptionLogic.ts b/products/subscriptions/frontend/components/Subscriptions/subscriptionLogic.ts
index cc2cd9d85843..cad7f4b8f95d 100644
--- a/products/subscriptions/frontend/components/Subscriptions/subscriptionLogic.ts
+++ b/products/subscriptions/frontend/components/Subscriptions/subscriptionLogic.ts
@@ -4,6 +4,7 @@ import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from
import { loaders } from 'kea-loaders'
import { beforeUnload, router, urlToAction } from 'kea-router'
import posthog from 'posthog-js'
+import { z } from 'zod'
import api, { ApiError } from 'lib/api'
import { dayjs } from 'lib/dayjs'
@@ -13,7 +14,7 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { getCurrentTeamId } from 'lib/utils/getAppContext'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { objectsEqual } from 'lib/utils/objects'
-import { isEmail, isHttpsUrl } from 'lib/utils/url'
+import { isEmail } from 'lib/utils/url'
import { getInsightId } from 'scenes/insights/utils'
import { organizationLogic } from 'scenes/organizationLogic'
import { userLogic } from 'scenes/userLogic'
@@ -123,6 +124,26 @@ const MISSING_TARGET_VALUE_ERROR: Record<SubscriptionTargetType, string> = {
[SubscriptionTargetEnumApi.Teams]: 'A webhook URL is required',
}
+const TEAMS_WEBHOOK_URL_ERROR =
+ 'Paste the full URL generated by Teams. It usually starts with https://...logic.azure.com/...'
+
+const teamsWebhookUrlSchema = z
+ .httpUrl()
+ .refine(
+ (url) =>
+ /^https:\/\/(?:[a-z0-9-]+\.)+logic\.azure\.com(?::443)?\/workflows\/.+\/triggers\/manual\/paths\/invoke(?:[/?#]|$)/i.test(
+ url
+ ) ||
+ /^https:\/\/(?:[a-z0-9-]+\.)+webhook\.office\.com(?::443)?\/webhookb2\/.+\/IncomingWebhook\/.+/i.test(
+ url
+ ) ||
+ /^https:\/\/(?:[a-z0-9-]+\.)+(?:powerautomate\.com|flow\.microsoft\.com)(?::443)?\/.+/i.test(url) ||
+ /^https:\/\/(?:[a-z0-9-]+\.)+environment\.api\.powerplatform\.com(?::443)?\/powerautomate\/automations\/direct(?:\/[^/]+)*\/workflows\/.+/i.test(
+ url
+ ),
+ TEAMS_WEBHOOK_URL_ERROR
+ )
+
function isTeamsWebhookKept(target_type: string, storedTeamsWebhookHost: string | null): boolean {
return target_type === SubscriptionTargetEnumApi.Teams && storedTeamsWebhookHost !== null
}
@@ -149,10 +170,10 @@ function validateTargetValue(
if (target_type === SubscriptionTargetEnumApi.Email && !trimmed.split(',').every((email) => isEmail(email))) {
return 'All emails must be valid'
}
- // The serializer owns the host allowlist and reports its own error on save. This check stays
- // loose on purpose, so it cannot reject a URL the backend would have accepted.
- if (target_type === SubscriptionTargetEnumApi.Teams && !isHttpsUrl(trimmed)) {
- return 'The webhook URL must start with https://'
+ // The serializer owns the host allowlist and reports its own error on save. This check only
+ // mirrors the supported URL shapes so invalid destinations cannot advance through the wizard.
+ if (target_type === SubscriptionTargetEnumApi.Teams && !teamsWebhookUrlSchema.safeParse(trimmed).success) {
+ return TEAMS_WEBHOOK_URL_ERROR
}
return undefined
}