Skip to content

Add optional Google Sheets submission mirror#23

Open
Spbd1 wants to merge 1 commit into
codex/add-replay-game-feature-to-study-flowfrom
codex/add-google-sheets-webhook-for-submissions
Open

Add optional Google Sheets submission mirror#23
Spbd1 wants to merge 1 commit into
codex/add-replay-game-feature-to-study-flowfrom
codex/add-google-sheets-webhook-for-submissions

Conversation

@Spbd1

@Spbd1 Spbd1 commented May 11, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide an optional secondary mirror of completed research submissions to a Google Sheets Apps Script webhook while keeping PostgreSQL as the primary source of truth.
  • Ensure the mirror is non-blocking so webhook failures do not prevent participant submissions from returning success once the DB save succeeds.

Description

  • Add lib/googleSheetsWebhook.ts with sendSubmissionToGoogleSheets(payload, metadata): Promise<void> that flattens a ValidResearchExport into a concise JSON row, posts to GOOGLE_SHEETS_WEBHOOK_URL with a 5s AbortController timeout, and sets Authorization: Bearer <secret> when GOOGLE_SHEETS_WEBHOOK_SECRET is present.
  • The helper omits payloadJson if the full payload is too large, logs concise success or warning messages on failure, and no-ops when GOOGLE_SHEETS_WEBHOOK_URL is unset.
  • Call the helper from POST /api/submissions (app/api/submissions/route.ts) after the Prisma researchSubmission.create completes so DB storage remains authoritative and webhook errors do not change the API response.
  • Add GOOGLE_SHEETS_WEBHOOK_URL and GOOGLE_SHEETS_WEBHOOK_SECRET to .env.example and add a README section documenting setup steps and a minimal Apps Script receiver that validates the shared secret.

Testing

  • Ran npm run typecheck and it completed successfully.
  • Ran npm run lint and it passed; output included an existing ParticipantBackgroundForm hook dependency warning (unchanged by this PR).
  • Ran npm run build and the production build completed successfully; the same existing hook dependency warning appears but did not block the build.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant