diff --git a/apps/sim/app/api/help/route.ts b/apps/sim/app/api/help/route.ts index e190ac5dfd4..2bef9371f07 100644 --- a/apps/sim/app/api/help/route.ts +++ b/apps/sim/app/api/help/route.ts @@ -1,7 +1,7 @@ -import { createLogger } from '@sim/logger' +import { createLogger, getRequestContext } from '@sim/logger' import { type NextRequest, NextResponse } from 'next/server' import { getRequestConfirmationSubject, renderHelpConfirmationEmail } from '@/components/emails' -import { helpFormBodySchema } from '@/lib/api/contracts/common' +import { helpFormBodySchema, helpReportPageSchema } from '@/lib/api/contracts/common' import { validationErrorResponse } from '@/lib/api/server' import { getSession } from '@/lib/auth' import { @@ -46,6 +46,7 @@ export const POST = withRouteHandler(async (req: NextRequest) => { const workflowId = formData.get('workflowId') as string | null const workspaceId = formData.get('workspaceId') as string const userAgent = formData.get('userAgent') as string | null + const page = helpReportPageSchema.safeParse(formData.get('page')).data logger.info('Processing help request', { type, @@ -83,12 +84,16 @@ export const POST = withRouteHandler(async (req: NextRequest) => { } const userId = session.user.id + const client = getRequestContext()?.client + const app = client ? [client.surface, client.version].filter(Boolean).join(' ') : 'N/A' let emailText = ` Type: ${type} From: ${email} User ID: ${userId} Workspace ID: ${workspaceId ?? 'N/A'} Workflow ID: ${workflowId ?? 'N/A'} +Page: ${page ?? 'N/A'} +App: ${app} Browser: ${userAgent ?? 'N/A'} ${message} diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/help-modal/help-modal.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/help-modal/help-modal.tsx index 33ec2732321..50090c4f99d 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/help-modal/help-modal.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/help-modal/help-modal.tsx @@ -16,6 +16,7 @@ import imageCompression from 'browser-image-compression' import Image from 'next/image' import { Controller, useForm } from 'react-hook-form' import { z } from 'zod' +import { resourceParam } from '@/app/workspace/[workspaceId]/home/search-params' const logger = createLogger('HelpModal') @@ -88,6 +89,13 @@ async function compressImage(file: File): Promise { } } +/** The path the form was sent from, plus the open chat tab, so a report names the screen it is about. */ +function currentPage(): string { + const { pathname, search } = window.location + const resource = new URLSearchParams(search).get(resourceParam.key) + return resource ? `${pathname}?${resourceParam.key}=${encodeURIComponent(resource)}` : pathname +} + async function submitHelpRequest({ data, images, workflowId, workspaceId }: SubmitHelpVariables) { const formData = new FormData() formData.append('subject', data.subject) @@ -95,6 +103,7 @@ async function submitHelpRequest({ data, images, workflowId, workspaceId }: Subm formData.append('type', data.type) if (workspaceId) formData.append('workspaceId', workspaceId) formData.append('userAgent', navigator.userAgent) + formData.append('page', currentPage()) if (workflowId) { formData.append('workflowId', workflowId) } diff --git a/apps/sim/lib/api/contracts/common.ts b/apps/sim/lib/api/contracts/common.ts index b846d3407ae..5f3909233e3 100644 --- a/apps/sim/lib/api/contracts/common.ts +++ b/apps/sim/lib/api/contracts/common.ts @@ -14,6 +14,15 @@ export const helpFormBodySchema = z.object({ type: z.enum(['bug', 'feedback', 'feature_request', 'other']), }) +/** + * The in-app path a help request was sent from. Context only: a value that fails this is + * dropped from the report rather than failing the request. + */ +export const helpReportPageSchema = z + .string() + .max(2048) + .regex(/^\/[^\s\u0000-\u001F\u007F]*$/) + export const integrationRequestBodySchema = z.object({ integrationName: z .string()