Browse Source

fix(vapi-webhook): rename query param to store_id, fix created_at default

- Rename webshop_id query param to store_id
- Database: added DEFAULT now() to created_at column
Fszontagh 4 months ago
parent
commit
9b24e8efe8
1 changed files with 13 additions and 13 deletions
  1. 13 13
      supabase/functions/vapi-webhook/index.ts

+ 13 - 13
supabase/functions/vapi-webhook/index.ts

@@ -42,48 +42,48 @@ serve(async (req) => {
       })
     }
 
-    // Extract and validate webshop_id from query parameters
+    // Extract and validate store_id from query parameters
     const url = new URL(req.url)
-    const webshopId = url.searchParams.get('webshop_id')
+    const storeId = url.searchParams.get('store_id')
 
-    if (!webshopId) {
+    if (!storeId) {
       return new Response(
-        JSON.stringify({ error: 'Missing required query parameter: webshop_id' }),
+        JSON.stringify({ error: 'Missing required query parameter: store_id' }),
         { status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
       )
     }
 
     // Validate UUID format
     const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
-    if (!uuidRegex.test(webshopId)) {
+    if (!uuidRegex.test(storeId)) {
       return new Response(
-        JSON.stringify({ error: 'Invalid webshop_id format. Must be a valid UUID.' }),
+        JSON.stringify({ error: 'Invalid store_id format. Must be a valid UUID.' }),
         { status: 400, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
       )
     }
 
-    // Verify webshop exists and is active
+    // Verify store exists and is active
     const { data: store, error: storeError } = await supabase
       .from('stores')
       .select('id, store_name, is_active')
-      .eq('id', webshopId)
+      .eq('id', storeId)
       .single()
 
     if (storeError || !store) {
       return new Response(
-        JSON.stringify({ error: 'Webshop not found', webshop_id: webshopId }),
+        JSON.stringify({ error: 'Store not found', store_id: storeId }),
         { status: 404, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
       )
     }
 
     if (!store.is_active) {
       return new Response(
-        JSON.stringify({ error: 'Webshop is inactive', webshop_id: webshopId }),
+        JSON.stringify({ error: 'Store is inactive', store_id: storeId }),
         { status: 403, headers: { ...corsHeaders, 'Content-Type': 'application/json' } }
       )
     }
 
-    console.log(`Processing VAPI webhook for webshop: ${store.store_name} (${webshopId})`)
+    console.log(`Processing VAPI webhook for store: ${store.store_name} (${storeId})`)
 
     // Parse the webhook payload
     const payload = await req.json()
@@ -101,11 +101,11 @@ serve(async (req) => {
     // Prepare simplified call log data
     const callLogData = {
       id: crypto.randomUUID(),
-      store_id: webshopId,
+      store_id: storeId,
       payload: payload,
     }
 
-    console.log('Inserting call log for store:', webshopId)
+    console.log('Inserting call log for store:', storeId)
 
     // Insert call log into database
     const { data, error } = await supabase