Spaces:
Running
Running
axeronis commited on
Commit ·
4aca3b9
1
Parent(s): c6f1711
Feature: AI voice messages now playable in platform
Browse filesPreviously AI voice only sent to Telegram, not saved to DB.
Fix:
1. Upload AI voice audio to Supabase (chat-attachments bucket)
2. Update ai_message with media_url, media_type, media_name
3. Voice now appears with player in platform chat UI
Both Telegram and platform now have playable AI voice
- backend/app/api/webhook.py +29 -1
backend/app/api/webhook.py
CHANGED
|
@@ -1185,7 +1185,35 @@ async def process_ai_response_background(
|
|
| 1185 |
custom_voice_url=custom_voice_url
|
| 1186 |
)
|
| 1187 |
|
| 1188 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1189 |
send_success = await telegram_service.send_voice(
|
| 1190 |
token=tenant.telegram_bot_token,
|
| 1191 |
chat_id=chat_id,
|
|
|
|
| 1185 |
custom_voice_url=custom_voice_url
|
| 1186 |
)
|
| 1187 |
|
| 1188 |
+
# Upload audio to Supabase for platform playback
|
| 1189 |
+
try:
|
| 1190 |
+
from app.core.supabase import supabase_client
|
| 1191 |
+
import time
|
| 1192 |
+
|
| 1193 |
+
if supabase_client and audio_bytes:
|
| 1194 |
+
bucket = "chat-attachments"
|
| 1195 |
+
ts = int(time.time())
|
| 1196 |
+
path = f"{tenant_id}/{conversation_id}/{ts}_ai_voice.mp3"
|
| 1197 |
+
|
| 1198 |
+
supabase_client.storage.from_(bucket).upload(
|
| 1199 |
+
path=path,
|
| 1200 |
+
file=audio_bytes,
|
| 1201 |
+
file_options={"content-type": "audio/mpeg"}
|
| 1202 |
+
)
|
| 1203 |
+
voice_media_url = supabase_client.storage.from_(bucket).get_public_url(path)
|
| 1204 |
+
|
| 1205 |
+
# Update AI message with media_url
|
| 1206 |
+
ai_message.media_url = voice_media_url
|
| 1207 |
+
ai_message.media_type = "audio/mpeg"
|
| 1208 |
+
ai_message.media_name = "ai_voice.mp3"
|
| 1209 |
+
session.add(ai_message)
|
| 1210 |
+
await session.commit()
|
| 1211 |
+
|
| 1212 |
+
logger.info(f"✅ AI voice uploaded to Supabase: {voice_media_url[:60]}...")
|
| 1213 |
+
except Exception as upload_err:
|
| 1214 |
+
logger.warning(f"⚠️ AI voice upload to Supabase failed: {upload_err}")
|
| 1215 |
+
|
| 1216 |
+
# Send voice message to Telegram
|
| 1217 |
send_success = await telegram_service.send_voice(
|
| 1218 |
token=tenant.telegram_bot_token,
|
| 1219 |
chat_id=chat_id,
|