import { Application } from 'express'; import { deleteConversation, getConversation, listConversations, buildConversation, } from '../store/conversation'; export function registerConversationRoutes(app: Application, openWaUrl: string | undefined) { app.get('/conversations', (req, res) => { console.log('[routes] GET /conversations'); res.json({ conversations: listConversations() }); }); app.get('/conversations/:id', async (req, res) => { console.log(`[routes] GET /conversations/${req.params.id}`); if (!openWaUrl) return res.status(500).json({ error: 'Service URLs not configured' }); try { const conv = await getConversation(req.params.id, openWaUrl); res.json(conv); } catch (err: any) { console.error('Failed to get conversation:', err.message); res.status(500).json({ error: err.message }); } }); app.post('/conversations/:id/update', async (req, res) => { console.log(`[routes] POST /conversations/${req.params.id}/update`); if (!openWaUrl) return res.status(500).json({ error: 'Service URLs not configured' }); try { const conv = await buildConversation(req.params.id, openWaUrl); res.json(conv); } catch (err: any) { console.error('Failed to update conversation:', err.message); res.status(500).json({ error: err.message }); } }); app.delete('/conversations/:id', (req, res) => { console.log(`[routes] DELETE /conversations/${req.params.id}`); const deleted = deleteConversation(req.params.id); res.json({ success: deleted }); }); }