Form webhook → Postgres → Resend digest

Save form submissions to Postgres through an inbound webhook, then email your team a daily summary with Resend.

On this page

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

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

AdapterPurpose
postgresStore and read submissions
resendSend the digest email

Install each one from MCP → Add connectors (click the connector, then Add to workspace), then connect it on Instance config.

Part 1: save submissions

  1. Create the workflow

    In Workflow Studio, create a workflow named form-submission-ingest.

  2. Add the validate step

    Add a lua step that requires email and tidies the input.

  3. Add the Postgres step

    Add an mcp step with the postgres_exec tool on your postgres instance, to insert a row.

  4. 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.

  5. 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.

Warning

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.

  1. Query the last 24 hours

    Add an mcp step with postgres_query.

  2. Summarize with an LLM

    Add an LLM step. Its prompt includes {{steps.query-submissions.result.rows}} and asks for a short HTML bullet list.

  3. Send the email

    Add an mcp step with resend_send_email on your resend instance. Use the LLM's text as the html.

  4. 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

ProblemWhat to check
The webhook returns 400The signature or Idempotency-Key header is missing or wrong. See Inbound webhooks
The run fails on Save submissionThe Postgres instance has no connection, the table does not exist, or the database user cannot INSERT
email required errorThe request body has no email field
The digest email never arrivesThe Resend domain is not verified, or to is not a list
The digest is emptyNo 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_row instead of using a database.
  • Add a human approval step before the digest sends. See Approve then send.

Next steps

Edit this pageagentruntime-io/agentruntime-docs