Form webhook → Postgres → Resend digest
Save form submissions to Postgres through an inbound webhook, then email your team a daily summary with Resend.
En esta página
In this guide you build two small workflows. The first saves every form submission to a Postgres table. The second emails your team a daily summary of what came in, written by an LLM.
It is for people who collect leads or requests through a form and want them stored and summarized without manual work. It takes about 30 minutes.
Outcome: every submission is stored with a timestamp, and each morning your team gets an HTML email listing the last day's submissions.
Prerequisites
- The
project_contributorrole in your project - A Postgres connection that can
INSERTinto andSELECTfrom aform_submissionstable - A Resend connection with a verified sending domain
- A model your workspace can use. See LLM providers
Create the table
Run this once against your database:
CREATE TABLE IF NOT EXISTS form_submissions (
id SERIAL PRIMARY KEY,
email TEXT NOT NULL,
name TEXT,
message TEXT,
source TEXT DEFAULT 'webhook',
created_at TIMESTAMPTZ DEFAULT NOW()
);Connectors to install
Install each one from MCP → Add connectors (click the connector, then Add to workspace), then connect it on Instance config.
Part 1: save submissions
- Create the workflow
In Workflow Studio, create a workflow named
form-submission-ingest. - Add the validate step
Add a
luastep that requiresemailand tidies the input. - Add the Postgres step
Add an
mcpstep with thepostgres_exectool on yourpostgresinstance, to insert a row. - Add an inbound webhook
Open Workflow setup → Inbound and create a subscription for this workflow. Copy the ingress URL and the signing secret (shown once). See Inbound webhooks.
- Send a test
Send a signed test request (see below). What you should see: a successful run in Command Center, and a new row in
form_submissions.
Inbound webhooks only accept requests signed with your signing secret and sent with an Idempotency-Key header. Most form tools cannot sign requests this way. Post the form data from your own server code or a small serverless function, which signs it. Inbound webhooks shows how.
Validate step
{
"id": "validate",
"type": "lua",
"name": "Validate submission",
"script": "if not input.email or input.email == '' then error('email required') end\nreturn {\n email = input.email,\n name = input.name or '',\n message = input.message or '',\n source = input.source or 'webhook'\n}",
"timeout_s": 10
}Insert step
{
"id": "insert-row",
"type": "mcp",
"name": "Save submission",
"instance_id": "REPLACE_POSTGRES_INSTANCE",
"tool_name": "postgres_exec",
"tool_args": {
"sql": "INSERT INTO form_submissions (email, name, message, source) VALUES ($1, $2, $3, $4)",
"args": [
"{{steps.validate.result.email}}",
"{{steps.validate.result.name}}",
"{{steps.validate.result.message}}",
"{{steps.validate.result.source}}"
]
},
"depends_on": ["validate"],
"timeout_s": 30
}Example body
The JSON body of your request becomes the run's input, so email is read as {{input.email}}:
{
"email": "alex@example.com",
"name": "Alex Kim",
"message": "Interested in enterprise plan",
"source": "landing-page"
}Part 2: the daily digest
Create a second workflow named form-daily-digest.
- Query the last 24 hours
Add an
mcpstep withpostgres_query. - Summarize with an LLM
Add an LLM step. Its prompt includes
{{steps.query-submissions.result.rows}}and asks for a short HTML bullet list. - Send the email
Add an
mcpstep withresend_send_emailon yourresendinstance. Use the LLM's text as thehtml. - Schedule it
Open Workflow setup → Cron, pick a preset such as Daily 09:00, choose a Timezone, choose an Automation API key, and click Add schedule. See External triggers.
What you should see: the schedule under Active schedules with the time of the next run.
Query step
{
"id": "query-submissions",
"type": "mcp",
"name": "Fetch today's submissions",
"instance_id": "REPLACE_POSTGRES_INSTANCE",
"tool_name": "postgres_query",
"tool_args": {
"sql": "SELECT email, name, message, source, created_at FROM form_submissions WHERE created_at >= NOW() - INTERVAL '1 day' ORDER BY created_at DESC"
},
"timeout_s": 30
}postgres_query returns at most 200 rows (100 by default). Add "limit" to tool_args to change it.
LLM step
{
"id": "summarize",
"type": "llm",
"name": "Write digest narrative",
"model_ref": "REPLACE_MODEL_REF",
"prompt": "You are an ops assistant. Given these form submissions as JSON, write a concise HTML email body with a bullet per submission (email, name, message). Submissions: {{steps.query-submissions.result.rows}}",
"depends_on": ["query-submissions"],
"timeout_s": 120
}Send step
{
"id": "send-digest",
"type": "mcp",
"name": "Email team digest",
"instance_id": "REPLACE_RESEND_INSTANCE",
"tool_name": "resend_send_email",
"tool_args": {
"to": ["team@example.com"],
"subject": "Daily form submissions",
"html": "{{steps.summarize.result.text}}"
},
"depends_on": ["summarize"],
"timeout_s": 30
}to is a list of addresses. Use a sender address on the domain you verified in Resend.
Full workflow graphs
Paste each into the JSON editor, then replace each REPLACE_POSTGRES_INSTANCE and REPLACE_RESEND_INSTANCE with the id of your postgres and resend instance, and REPLACE_MODEL_REF with a model from your Providers catalog.
Ingest workflow
{
"steps": [
{
"id": "validate",
"type": "lua",
"name": "Validate submission",
"script": "if not input.email or input.email == '' then error('email required') end\nreturn {\n email = input.email,\n name = input.name or '',\n message = input.message or '',\n source = input.source or 'webhook'\n}",
"timeout_s": 10
},
{
"id": "insert-row",
"type": "mcp",
"name": "Save submission",
"instance_id": "REPLACE_POSTGRES_INSTANCE",
"tool_name": "postgres_exec",
"tool_args": {
"sql": "INSERT INTO form_submissions (email, name, message, source) VALUES ($1, $2, $3, $4)",
"args": [
"{{steps.validate.result.email}}",
"{{steps.validate.result.name}}",
"{{steps.validate.result.message}}",
"{{steps.validate.result.source}}"
]
},
"depends_on": ["validate"],
"timeout_s": 30
}
]
}Digest workflow
{
"steps": [
{
"id": "query-submissions",
"type": "mcp",
"name": "Fetch today's submissions",
"instance_id": "REPLACE_POSTGRES_INSTANCE",
"tool_name": "postgres_query",
"tool_args": {
"sql": "SELECT email, name, message, source, created_at FROM form_submissions WHERE created_at >= NOW() - INTERVAL '1 day' ORDER BY created_at DESC"
},
"timeout_s": 30
},
{
"id": "summarize",
"type": "llm",
"name": "Write digest narrative",
"model_ref": "REPLACE_MODEL_REF",
"prompt": "You are an ops assistant. Given these form submissions as JSON, write a concise HTML email body with a bullet per submission (email, name, message). Submissions: {{steps.query-submissions.result.rows}}",
"depends_on": ["query-submissions"],
"timeout_s": 120
},
{
"id": "send-digest",
"type": "mcp",
"name": "Email team digest",
"instance_id": "REPLACE_RESEND_INSTANCE",
"tool_name": "resend_send_email",
"tool_args": {
"to": ["team@example.com"],
"subject": "Daily form submissions",
"html": "{{steps.summarize.result.text}}"
},
"depends_on": ["summarize"],
"timeout_s": 30
}
]
}Handle repeated deliveries
Senders sometimes retry. AgentRuntime ignores a repeated Idempotency-Key, so a retry with the same key does not start a second run. To also protect against two different keys for the same submission, add a unique submission_id column and use ON CONFLICT DO NOTHING in the insert.
Common problems
| Problem | What to check |
|---|---|
The webhook returns 400 | The signature or Idempotency-Key header is missing or wrong. See Inbound webhooks |
| The run fails on Save submission | The Postgres instance has no connection, the table does not exist, or the database user cannot INSERT |
email required error | The request body has no email field |
| The digest email never arrives | The Resend domain is not verified, or to is not a list |
| The digest is empty | No rows in the last day. The LLM is given an empty list |
Variations
- Swap Resend for Gmail with
gmail_send_email. - Append rows to Google Sheets with
google_sheets_insert_rowinstead of using a database. - Add a
humanapproval step before the digest sends. See Approve then send.