Spaces:
Sleeping
Sleeping
Fix: remove parse_mode Markdown, add English fallback for empty response, remove duplicate message saving
Browse files- telegram_handlers.py +3 -5
telegram_handlers.py
CHANGED
|
@@ -35,12 +35,11 @@ async def telegram_webhook(data: WebhookData):
|
|
| 35 |
|
| 36 |
if db_manager:
|
| 37 |
db_manager.create_or_update_user(telegram_id, username, first_name, data.message.chat.last_name)
|
| 38 |
-
|
| 39 |
|
| 40 |
ai_answer = await get_ai_response(user_text, telegram_id)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
db_manager.save_message(telegram_id, ai_answer, "assistant")
|
| 44 |
|
| 45 |
if TELEGRAM_URL:
|
| 46 |
try:
|
|
@@ -49,8 +48,7 @@ async def telegram_webhook(data: WebhookData):
|
|
| 49 |
async with httpx.AsyncClient(timeout=40.0, verify=False, follow_redirects=True) as client:
|
| 50 |
payload = {
|
| 51 |
"chat_id": telegram_id,
|
| 52 |
-
"text": ai_answer,
|
| 53 |
-
"parse_mode": "Markdown"
|
| 54 |
}
|
| 55 |
|
| 56 |
try:
|
|
|
|
| 35 |
|
| 36 |
if db_manager:
|
| 37 |
db_manager.create_or_update_user(telegram_id, username, first_name, data.message.chat.last_name)
|
| 38 |
+
|
| 39 |
|
| 40 |
ai_answer = await get_ai_response(user_text, telegram_id)
|
| 41 |
|
| 42 |
+
|
|
|
|
| 43 |
|
| 44 |
if TELEGRAM_URL:
|
| 45 |
try:
|
|
|
|
| 48 |
async with httpx.AsyncClient(timeout=40.0, verify=False, follow_redirects=True) as client:
|
| 49 |
payload = {
|
| 50 |
"chat_id": telegram_id,
|
| 51 |
+
"text": ai_answer or "Sorry, I couldn't generate a response. Please try again."
|
|
|
|
| 52 |
}
|
| 53 |
|
| 54 |
try:
|