|
@@ -3,6 +3,7 @@ import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
|
|
|
import { wrapHandler } from '../_shared/error-handler.ts'
|
|
import { wrapHandler } from '../_shared/error-handler.ts'
|
|
|
import { getCorsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts'
|
|
import { getCorsHeaders, handleCorsPreflightRequest } from '../_shared/cors.ts'
|
|
|
import { createScraperClient } from '../_shared/scraper-client.ts'
|
|
import { createScraperClient } from '../_shared/scraper-client.ts'
|
|
|
|
|
+import { setupVapiForStore } from '../_shared/vapi-setup.ts'
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Auto-register a user account during ShopRenter OAuth flow.
|
|
* 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}`))
|
|
.then(() => console.log(`[AutoRegister] Initial sync completed for store ${storeId}`))
|
|
|
.catch(err => console.error(`[AutoRegister] Initial sync failed:`, err))
|
|
.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(
|
|
return new Response(
|
|
|
JSON.stringify({
|
|
JSON.stringify({
|
|
|
success: true,
|
|
success: true,
|