UNPKG

@ria-sys/mcp

Version:

MCP Server para integração com WhatsApp

70 lines (69 loc) 2.33 kB
export class MessageService { constructor() { this.apiUrl = 'https://assistants.riasistemas.com.br/v1/notification'; } async sendMessage(toList, message, sessionName) { try { const response = await fetch(this.apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ to: toList, message, session_name: sessionName }) }); if (response.ok) { return { success: true, message: '✅ Mensagem enviada com sucesso.' }; } else { const errorBody = await response.text().catch(() => ''); return { success: false, message: `❌ Erro da API: ${response.status} - ${response.statusText}${errorBody ? ` - ${errorBody.replace(/\s+/g, ' ')}` : ''}` }; } } catch (error) { return { success: false, message: `❌ Erro inesperado: ${error instanceof Error ? error.message : 'Erro desconhecido'}` }; } } formatPhone(phone, removeNinthDigit = false) { try { if (!phone) { return { success: false, message: '⚠️ Telefone não pode estar vazio.' }; } let cleaned = phone.replace(/\D/g, ''); if (!cleaned.startsWith('55')) { cleaned = '55' + cleaned; } if (cleaned.length === 10) { cleaned = cleaned.slice(0, 4) + '9' + cleaned.slice(4); } if (removeNinthDigit && cleaned.length === 11) { cleaned = cleaned.slice(0, 4) + cleaned.slice(5); } return { success: true, phone: cleaned }; } catch (error) { return { success: false, message: `❌ Erro ao formatar: ${error instanceof Error ? error.message : 'Erro desconhecido'}` }; } } }