: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
fix(workflows): send transactional emails regardless of opt-out status (#69340)
Harley Alexander44a5866d6532
diff --git a/nodejs/src/cdp/services/messaging/recipient-preferences.service.test.ts b/nodejs/src/cdp/services/messaging/recipient-preferences.service.test.tsindex f33794555491..d17a343aabbf 100644--- a/nodejs/src/cdp/services/messaging/recipient-preferences.service.test.ts+++ b/nodejs/src/cdp/services/messaging/recipient-preferences.service.test.ts@@ -101,7 +101,8 @@ describe('RecipientPreferencesService', () => {describe('for email actions', () => {const createEmailAction = (to: string = '[email protected]',- categoryId: string+ categoryId: string,+ categoryType?: 'marketing' | 'transactional'): Extract<HogFlowAction, { type: 'function_email' }> => ({id: 'email',name: 'Send email',@@ -111,6 +112,7 @@ describe('RecipientPreferencesService', () => {config: {template_id: 'template-email',message_category_id: categoryId,+ message_category_type: categoryType,inputs: {email: {value: {@@ -246,6 +248,29 @@ describe('RecipientPreferencesService', () => {expect(mockRecipientsManagerGetAllMarketingMessagingPreference).toHaveBeenCalledWith(recipient)})+ it.each([+ ['the specific category', { '123e4567-e89b-12d3-a456-426614174000': 'OPTED_OUT' }],+ ['all marketing messaging', { $all: 'OPTED_OUT' }],+ ])(+ 'should return false for a transactional email even when recipient is opted out of %s',+ async (_label, preferences) => {+ const action = createEmailAction(+ '[email protected]',+ '123e4567-e89b-12d3-a456-426614174000',+ 'transactional'+ )+ const invocation = createFunctionStepInvocation(action)++ mockRecipientsManagerGet.mockResolvedValue(createRecipient('[email protected]', preferences))++ const result = await service.shouldSkipAction(invocation, action)++ expect(result).toBe(false)+ // Transactional messages bypass the opt-out lookup entirely+ expect(mockRecipientsManagerGet).not.toHaveBeenCalled()+ }+ )+it('should return true if recipient is opted out of specific category even when opted in to all marketing', async () => {const action = createEmailAction('[email protected]', '123e4567-e89b-12d3-a456-426614174000')const invocation = createFunctionStepInvocation(action)diff --git a/nodejs/src/cdp/services/messaging/recipient-preferences.service.ts b/nodejs/src/cdp/services/messaging/recipient-preferences.service.tsindex bf90f11310fd..dcdc2478fe9e 100644--- a/nodejs/src/cdp/services/messaging/recipient-preferences.service.ts+++ b/nodejs/src/cdp/services/messaging/recipient-preferences.service.ts@@ -15,9 +15,17 @@ export class RecipientPreferencesService {invocation: CyclotronJobInvocationHogFunction,action: HogFlowAction): Promise<boolean> {- return (- this.isSubjectToRecipientPreferences(action) && (await this.isRecipientOptedOutOfAction(invocation, action))- )+ if (!this.isSubjectToRecipientPreferences(action)) {+ return false+ }++ // Transactional messages are not eligible for opt-outs, so they send regardless of+ // whether the recipient has opted out of this category or of all marketing messaging.+ if (action.config.message_category_type === 'transactional') {+ return false+ }++ return await this.isRecipientOptedOutOfAction(invocation, action)}private isSubjectToRecipientPreferences(action: HogFlowAction): action is MessageAction {