Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/sim/app/api/help/route.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -88,13 +89,21 @@ async function compressImage(file: File): Promise<File> {
}
}

/** 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)
formData.append('message', data.message)
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)
}
Expand Down
9 changes: 9 additions & 0 deletions apps/sim/lib/api/contracts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading