Skip to main content

Clix + Supabase Integration

This guide shows how to integrate Clix push notifications into a Supabase project using Edge Functions and Postgres triggers. You will:
  • Add a reusable ClixClient inside supabase/functions/_shared
  • (Recommended) Create helper builders for ClixNotification payloads
  • Deploy Edge Functions that send notifications
  • Optionally wire automatic dispatch via database triggers with pg_net
Supabase Edge Functions run in Deno on the Supabase infrastructure and can securely access secrets you store with supabase secrets. See the official docs: Edge Functionshttps://supabase.com/docs/guides/functions

1. Prerequisites

  • A Supabase project (with CLI installed) – https://supabase.com/docs/guides/cli
  • A Clix project (obtain Project ID + Secret API Key)
  • Supabase CLI authenticated: supabase login
  • (If using triggers) Postgres extension pg_net enabled (we’ll cover this below)

2. Configure Secrets / Environment Variables

Store credentials as Supabase Function secrets (never hard‑code keys):
Set Supabase Edge Function secrets
Docs:

3. Add the Shared Clix Client

Create the file below at supabase/functions/_shared/clix_client.ts.
supabase/functions/_shared/clix_client.ts
Instead of hand‑crafting notification objects each time, centralize builders for consistent structure and future enrichment.
supabase/functions/_shared/notification_scenarios.ts
These helpers can evolve to insert A/B test metadata, analytics tags, localization, etc. Centralizing keeps Edge Function logic lean.

5. Edge Function: Notify Todo Completion

Minimal example: accept a todo_id and a target project_user_id, build a notification, and send it via ClixClient (no database lookup logic included here).
supabase/functions/notify-todo/index.ts

Deploy the Function

(You can require JWT if only your backend calls this. See auth function docs: https://supabase.com/docs/guides/functions/auth)

6. Calling the Edge Function (Invocation Options)

You can integrate notify-todo in three primary ways—choose based on coupling, complexity, and operational preferences. (Code snippets intentionally omitted.)
  1. Database Trigger (pg_net): Attach a lightweight trigger to the todos table so when a row transitions to completed, Postgres performs an HTTP POST to the deployed Edge Function. Pros: automatic, low latency, no extra app call. Cons: trigger logic inside SQL, needs pg_net and careful key handling.
  2. Direct API Call: From your backend (or another Edge Function) perform an authenticated POST with the todo_id. Pros: simplest to reason about in application code, easier to add conditional logic or retries. Cons: requires your app layer to explicitly invoke for every event.
  3. Scheduled / Batch Orchestrator: Periodic job (cron, scheduled function, worker) queries for recently completed todos and sends notifications in batches (reduces per-event overhead). Pros: efficient for high volume; can deduplicate. Cons: not real-time; added scheduling complexity.
Selection guidance:
  • Want instant, automatic dispatch on state change? Use a trigger.
  • Need business rules (feature flags, throttling, analytics gating)? Use direct API call.
  • Need aggregation (daily digests, rate limiting)? Use scheduled batch.

7. Testing the Flow

  1. Insert / update a todo to status completed
  2. Confirm notification_dispatch_log entries
  3. Verify successful HTTP responses & Clix dashboard reception
  4. For manual test call the function:

8. Security & Best Practices

  • Put your Clix Secret API Key only in Supabase secrets (never ship to clients)
  • Prefer trigger-based automation for reliability; fall back to client calls when immediacy or dynamic logic is required
  • Use structured builders to evolve payloads without touching every function
  • Log responses (already in examples) for observability; consider adding retention policies

9. Useful Supabase Docs

10. Summary

You now have:
  • A reusable ClixClient consuming environment secrets
  • Scenario helpers for consistent notifications
  • Edge Functions (notify-todo) to send messages
  • Optional Postgres triggers to automatically invoke those functions
Iterate by adding more scenario builders (e.g. silent data sync, milestone achievements) and enrich payloads with custom analytics fields.