> ## Documentation Index
> Fetch the complete documentation index at: https://docs.grouple.pro/llms.txt
> Use this file to discover all available pages before exploring further.

# Edge Functions

> All 6 Supabase Edge Functions running serverless compute for Grouple

## Overview

Grouple has 6 Edge Functions deployed on Supabase. They handle email delivery, AI proposal generation, OCR processing, and currency updates. Most are triggered by database triggers or called directly from the frontend/API.

## Functions

### `send-lead-email`

**Last updated:** 6 days ago\
**Triggered by:** `send_enquiry_notification` DB trigger (AFTER INSERT on `enquiries`)

Sends lead notification emails to matched venues when a new enquiry is submitted. Called via HTTP from the database trigger with the enquiry payload.

**Flow:**

```
New enquiry created
        ↓
DB trigger calls this function via HTTP POST
        ↓
Function fetches matched venue_leads + merchant emails
        ↓
Sends lead notification email to each matched merchant
```

***

### `send-proposal-email`

**Last updated:** 1 day ago\
**Triggered by:** `proposal-updated-email` DB trigger (AFTER UPDATE on `proposals`)

Sends an email to the customer when a merchant updates or sends a proposal.

**Flow:**

```
Merchant sends/updates proposal → status changes
        ↓
DB trigger calls this function via HTTP POST
        ↓
Function fetches proposal + customer details
        ↓
Sends proposal notification email to customer
```

***

### `reservation-confirmation-emails`

**Last updated:** 1 day ago\
**Triggered by:** `proposal-confirmation-email` DB trigger (AFTER UPDATE on `proposals` when status = "confirmed")

Sends confirmation emails to both the customer and merchant when a booking is confirmed.

**Flow:**

```
Customer confirms proposal → status = "confirmed"
        ↓
DB trigger calls this function via HTTP POST
        ↓
Function sends confirmation email to customer
Function sends booking confirmed email to merchant
```

***

### `generate-proposal`

**Last updated:** 3 months ago\
**Triggered by:** Frontend (merchant clicks "Generate with AI")

Generates AI-powered proposal content for merchants. Calls Amazon Bedrock Claude 4.6 with venue knowledge (extracted menu data, venue details) and enquiry requirements to produce a tailored proposal.

**Flow:**

```
Merchant opens Send Proposal page → clicks "Generate with AI"
        ↓
Frontend calls this Edge Function with:
  - venue_knowledge (extracted menu/PDF data)
  - enquiry details (group size, budget, occasion, requirements)
        ↓
Function calls AI Worker (EC2/PM2) or Bedrock directly
        ↓
Returns generated proposal content
        ↓
Merchant reviews and edits before sending
```

***

### `mistral-ocr`

**Last updated:** 1 month ago\
**Triggered by:** Frontend / PDF Extract Worker

Processes PDF menus and brochures uploaded by merchants. Extracts structured data from PDFs to populate `venue_knowledge.extracted_data`.

**Flow:**

```
Merchant uploads menu PDF to venue-brochures storage
        ↓
PDF Extract Worker (EC2/PM2) or frontend calls this function
        ↓
Function performs OCR/extraction on the PDF
        ↓
Returns structured JSON data
        ↓
Saved to venue_knowledge.extracted_data
```

***

### `update-exchange-rates`

**Last updated:** 1 month ago\
**Triggered by:** Scheduled (cron) or manual

Fetches latest currency exchange rates and updates the `exchange_rates` table. Supports multi-currency pricing across USD, AED, GBP, INR, EUR.

**Flow:**

```
Scheduled trigger (or manual call)
        ↓
Function fetches latest rates from exchange rate API
        ↓
Updates exchange_rates table (base_currency: USD, rates: jsonb)
        ↓
Frontend CurrencyContext uses these rates for display conversion
```
