Spaces:
Running

axeronis commited on
Commit
e651f28
·
1 Parent(s): 31b64b4

fix: resolve NaN warning in frontend, fix psychotype parsing, and add telegram markdown fallback

Browse files
backend/app/api/webhook.py CHANGED
@@ -293,16 +293,33 @@ async def send_telegram_message(
293
 
294
  try:
295
  async with httpx.AsyncClient() as client:
296
- response = await client.post(url, json=payload, timeout=10.0)
297
-
298
  logger.info(
299
- "📡 Telegram API response",
300
- status_code=response.status_code,
301
- response_text=response.text[:200]
 
302
  )
 
303
 
 
 
 
 
 
 
 
 
 
 
304
  response.raise_for_status()
 
 
 
 
 
305
  return True
 
306
  except Exception as e:
307
  logger.error(
308
  "❌ Failed to send Telegram message",
 
293
 
294
  try:
295
  async with httpx.AsyncClient() as client:
296
+ # Attempt 1: Try with Markdown
 
297
  logger.info(
298
+ "📡 Telegram API request (Markdown)",
299
+ url=url[:60] + "...",
300
+ chat_id=chat_id,
301
+ text_length=len(text)
302
  )
303
+ response = await client.post(url, json=payload, timeout=10.0)
304
 
305
+ if response.status_code == 400 and "can't parse entities" in response.text:
306
+ logger.warning(
307
+ "⚠️ Telegram Markdown parse error, retrying as plain text",
308
+ chat_id=chat_id,
309
+ error=response.text
310
+ )
311
+ # Attempt 2: Retry as Plain Text
312
+ payload["parse_mode"] = None
313
+ response = await client.post(url, json=payload, timeout=10.0)
314
+
315
  response.raise_for_status()
316
+
317
+ logger.info(
318
+ "✅ Telegram message sent",
319
+ status_code=response.status_code
320
+ )
321
  return True
322
+
323
  except Exception as e:
324
  logger.error(
325
  "❌ Failed to send Telegram message",
backend/app/services/ai_core.py CHANGED
@@ -162,6 +162,8 @@ Goal: {current_stage.ai_goal if current_stage else 'Assist user'}
162
  # 1. Detect psychotype (NO threshold - analyze even "Hi")
163
  if len(user_messages) > 0: # At least 1 message
164
  psychotype_str = await self.llm.analyze_psychotype(user_messages)
 
 
165
  lead.psychotype = Psychotype(psychotype_str)
166
 
167
  # 2. Calculate heat score
 
162
  # 1. Detect psychotype (NO threshold - analyze even "Hi")
163
  if len(user_messages) > 0: # At least 1 message
164
  psychotype_str = await self.llm.analyze_psychotype(user_messages)
165
+ # Clean markdown if present (e.g. **steady**)
166
+ psychotype_str = psychotype_str.replace("*", "").strip().lower()
167
  lead.psychotype = Psychotype(psychotype_str)
168
 
169
  # 2. Calculate heat score
frontend/components/settings/ProductSettings.tsx CHANGED
@@ -306,8 +306,11 @@ export default function ProductSettings() {
306
  required
307
  type="number"
308
  min="0"
309
- value={formData.price}
310
- onChange={e => setFormData({ ...formData, price: parseFloat(e.target.value) })}
 
 
 
311
  className="w-full pl-8 pr-4 py-2 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-pink-500/20 focus:border-pink-500 outline-none text-sm"
312
  />
313
  </div>
 
306
  required
307
  type="number"
308
  min="0"
309
+ value={formData.price || ''}
310
+ onChange={e => {
311
+ const val = parseFloat(e.target.value)
312
+ setFormData({ ...formData, price: isNaN(val) ? 0 : val })
313
+ }}
314
  className="w-full pl-8 pr-4 py-2 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-pink-500/20 focus:border-pink-500 outline-none text-sm"
315
  />
316
  </div>