'use strict'; const generateId = require('../../utils/generateId.util'); const { sessionService } = require('../../core'); function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } exports.sendText111 = async ctx => { const { type } = ctx.params; const body = ctx.request.body; ctx.assert(null, 400, `debug: content: {${type}} {${body.content}}`); ctx.assert(null, 400, 'The message info is malformed!'); return body; }; exports.sendText = async ctx => { const { from, to, content } = ctx.request.body; if (!from || !content) { ctx.assert(from, 400, 'From and message are required'); return; } const wsToSend = sessionService.getSession(from); if (!wsToSend) { ctx.assert(wsToSend, 400, 'Session not found'); // 404 return; } // return wsToSend; try { await wsToSend.sendTextMessage(to, content); return { wsToSend, ret: 'Message sent successfully' }; } catch (error) { console.error('Error sending message:', error); ctx.assert(null, 500, 'Failed to send message'); } };