renombrado nucleoClient y nucleoActions por whatsappCliente y whatsappActions
All checks were successful
Deploy conversation layer / deploy (push) Successful in 2m4s
All checks were successful
Deploy conversation layer / deploy (push) Successful in 2m4s
This commit is contained in:
44
whatsapp-router/src/routes/conversationActions.ts
Normal file
44
whatsapp-router/src/routes/conversationActions.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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 });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user