Просмотр исходного кода

fix(shoprenter): improve auto-registration with defaults and cleanup

- Change WebUI greeting fallback to Hungarian to match VAPI
- Create default business hours record with is_enabled=true on store creation
- Add default ai_config to alt_data when creating store
- Enhance pending_shoprenter_installs deletion with logging

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

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh 4 месяцев назад
Родитель
Сommit
4ba5ca67f2

+ 1 - 1
shopcall.ai-main/src/components/AIConfigContent.tsx

@@ -219,7 +219,7 @@ export function AIConfigContent() {
     const config = store.alt_data?.ai_config || {};
     const config = store.alt_data?.ai_config || {};
     setAiConfig({
     setAiConfig({
       voice_type: config.voice_type || "",
       voice_type: config.voice_type || "",
-      greeting_message: config.greeting_message || `Hello! Thank you for calling ${store.store_name || 'our store'}. How can I help you?`
+      greeting_message: config.greeting_message || `Üdvözlöm! A ${store.store_name || 'webáruház'} ügyfélszolgálata vagyok. Miben segíthetek?`
     });
     });
   };
   };
 
 

+ 32 - 3
supabase/functions/auto-register-shoprenter/index.ts

@@ -309,7 +309,11 @@ serve(wrapHandler('auto-register-shoprenter', async (req) => {
             client_id: shoprenterClientId,
             client_id: shoprenterClientId,
             client_secret: shoprenterClientSecret,
             client_secret: shoprenterClientSecret,
             connectedAt: new Date().toISOString(),
             connectedAt: new Date().toISOString(),
-            autoRegistered: true
+            autoRegistered: true,
+            ai_config: {
+              voice_type: '',
+              greeting_message: `Üdvözlöm! A ${pendingInstall.shopname} ügyfélszolgálata vagyok. Miben segíthetek?`
+            }
           }
           }
         })
         })
         .select()
         .select()
@@ -341,6 +345,27 @@ serve(wrapHandler('auto-register-shoprenter', async (req) => {
       if (syncConfigError) {
       if (syncConfigError) {
         console.error('[AutoRegister] Error creating sync config:', syncConfigError)
         console.error('[AutoRegister] Error creating sync config:', syncConfigError)
       }
       }
+
+      // Create default business hours
+      const { error: businessHoursError } = await supabase
+        .from('store_business_hours')
+        .insert({
+          store_id: storeId,
+          is_enabled: true,
+          daily_hours: {
+            monday: { is_open: true, open: '09:00', close: '18:00' },
+            tuesday: { is_open: true, open: '09:00', close: '18:00' },
+            wednesday: { is_open: true, open: '09:00', close: '18:00' },
+            thursday: { is_open: true, open: '09:00', close: '18:00' },
+            friday: { is_open: true, open: '09:00', close: '18:00' },
+            saturday: { is_open: false, open: '10:00', close: '16:00' },
+            sunday: { is_open: false, open: '10:00', close: '14:00' }
+          }
+        })
+
+      if (businessHoursError) {
+        console.error('[AutoRegister] Error creating business hours:', businessHoursError)
+      }
     }
     }
 
 
     // Update phone number assignment if provided
     // Update phone number assignment if provided
@@ -361,15 +386,19 @@ serve(wrapHandler('auto-register-shoprenter', async (req) => {
     }
     }
 
 
     // Clean up pending installation
     // Clean up pending installation
-    const { error: deleteError } = await supabase
+    console.log(`[AutoRegister] Attempting to delete pending installation id=${pendingInstall.id}, installation_id=${installation_id}`)
+    const { data: deletedData, error: deleteError } = await supabase
       .from('pending_shoprenter_installs')
       .from('pending_shoprenter_installs')
       .delete()
       .delete()
       .eq('id', pendingInstall.id)
       .eq('id', pendingInstall.id)
+      .select()
 
 
     if (deleteError) {
     if (deleteError) {
       console.error(`[AutoRegister] Failed to delete pending installation ${pendingInstall.id}:`, deleteError)
       console.error(`[AutoRegister] Failed to delete pending installation ${pendingInstall.id}:`, deleteError)
+    } else if (!deletedData || deletedData.length === 0) {
+      console.warn(`[AutoRegister] Delete returned no rows for pending installation ${pendingInstall.id}`)
     } else {
     } else {
-      console.log(`[AutoRegister] Deleted pending installation ${pendingInstall.id}`)
+      console.log(`[AutoRegister] Successfully deleted pending installation ${pendingInstall.id}:`, deletedData)
     }
     }
 
 
     // Clean up any related oauth_states
     // Clean up any related oauth_states