# Function templates

Source: https://cubibase.com/docs/functions/templates

Also available: [Markdown version](https://cubibase.com/docs/functions/templates.md) · [llms.txt](https://cubibase.com/llms.txt) · [full site content](https://cubibase.com/llms-full.txt)

Eight versioned starting points with working code, preselected triggers and security defaults, and step-by-step setup instructions. Everything they generate is editable.

## The catalog

| Template | Trigger | What it does | Required secrets |
| --- | --- | --- | --- |
| Hello World | HTTP | JSON greeting; the smallest possible function | — |
| Stripe Webhook | HTTP (public, custom signature) | Verifies Stripe-Signature on the raw body; idempotent payment/subscription handling | STRIPE_WEBHOOK_SECRET (STRIPE_SECRET_KEY optional) |
| GitHub Webhook | HTTP (public, custom signature) | Verifies X-Hub-Signature-256 for push and issue events | GITHUB_WEBHOOK_SECRET |
| Send Email | HTTP (API key) or Database | Transactional email through the Resend API | RESEND_API_KEY + EMAIL_FROM variable |
| OpenAI Proxy | HTTP (JWT) | Server-side OpenAI calls so your key never ships to browsers | OPENAI_API_KEY |
| Image Processing | Storage | Processes new uploads, writes derivatives to a separate prefix | — |
| Database Change Handler | Database | Audit logging for INSERT/UPDATE/DELETE, deduped on eventId | — |
| Scheduled Cleanup | Scheduled | Nightly removal of expired rows; edit to your schema | — |

In the Console, Functions → Templates shows the catalog with code previews. “Use template” preselects the trigger type, authentication mode, signature mode, timeout and memory, and walks you through the required secrets and external configuration.

## Stripe Webhook, end to end

1. **Create from the template** — The function is created with public authentication and custom signature mode — Stripe cannot send a CubiBase JWT, and no CubiBase HMAC is forced on it.
2. **Create the dedupe table** — CREATE TABLE stripe_events (id text PRIMARY KEY, type text, processed_at timestamptz); — the handler records every processed event id.
3. **Deploy and copy the URL** — The function URL is https://{slug}.api.cubibase.com/functions/{name}. Deploy first; the endpoint is live only after a successful deployment.
4. **Configure Stripe** — Stripe Dashboard → Developers → Webhooks → Add endpoint. Paste the URL; subscribe to payment_intent.succeeded and customer.subscription.deleted (or your events).
5. **Store the signing secret** — Copy the endpoint’s signing secret (whsec_…) into the STRIPE_WEBHOOK_SECRET secret and redeploy. Optionally set STRIPE_SECRET_KEY to use the official SDK verification path.
6. **Verify with a test event** — Send a test event from the Dashboard and check Executions & Logs. The integration is connected only when a signed test delivery succeeds — the Console never claims otherwise.

> **note**: The handler verifies the signature against the exact raw bytes, rejects invalid signatures with 400, skips already-processed event ids, and returns a fast 200 so Stripe does not retry unnecessarily.

## Additional resources

- [HTTP functions](https://cubibase.com/docs/functions/http) Auth modes for webhook endpoints.
- [Secrets](https://cubibase.com/docs/functions/secrets) Storing provider credentials safely.
