Ver Fonte

fix(vapi): add VAPI setup to auto-register-shoprenter for ShopRenter OAuth

The VAPI assistant creation was missing from the ShopRenter OAuth flow.
Added setupVapiForStore call to auto-register-shoprenter function which
handles new ShopRenter store creation during the OAuth process.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh há 4 meses atrás
pai
commit
880f34b99a
1 ficheiros alterados com 20 adições e 0 exclusões
  1. 20 0
      supabase/functions/auto-register-shoprenter/index.ts

+ 20 - 0
supabase/functions/auto-register-shoprenter/index.ts

@@ -3,6 +3,7 @@ import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
 import { wrapHandler } from '../_shared/error-handler.ts'
 import { getCorsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts'
 import { createScraperClient } from '../_shared/scraper-client.ts'
+import { setupVapiForStore } from '../_shared/vapi-setup.ts'
 
 /**
  * Auto-register a user account during ShopRenter OAuth flow.
@@ -394,6 +395,25 @@ serve(wrapHandler('auto-register-shoprenter', async (req) => {
       .then(() => console.log(`[AutoRegister] Initial sync completed for store ${storeId}`))
       .catch(err => console.error(`[AutoRegister] Initial sync failed:`, err))
 
+    // Setup VAPI assistant in background (async, non-blocking)
+    if (finalPhoneNumberId) {
+      supabase
+        .from('phone_numbers')
+        .select('phone_number')
+        .eq('id', finalPhoneNumberId)
+        .single()
+        .then(({ data: phoneData }: { data: { phone_number: string } | null }) => {
+          if (phoneData?.phone_number) {
+            // Remove spaces for E.164 format
+            const phoneNumber = phoneData.phone_number.replace(/\s/g, '')
+            setupVapiForStore(supabase, storeId, pendingInstall.shopname, phoneNumber)
+              .then(result => console.log(`[AutoRegister] VAPI setup ${result.success ? 'complete' : 'failed'}: ${result.error || ''}`))
+              .catch(err => console.error(`[AutoRegister] VAPI setup error:`, err))
+          }
+        })
+        .catch((err: Error) => console.error(`[AutoRegister] Failed to fetch phone for VAPI:`, err))
+    }
+
     return new Response(
       JSON.stringify({
         success: true,