skailan-crm
Version:
Servicio de CRM y gestión de ventas para Skailan
33 lines • 1.46 kB
JavaScript
import axios from 'axios';
export class StartConversationWithLead {
leadRepository;
constructor(leadRepository) {
this.leadRepository = leadRepository;
}
async execute(request) {
const { organizationId, leadId, channelId } = request;
const lead = await this.leadRepository.findById(leadId, organizationId);
if (!lead) {
throw new Error('Lead not found.');
}
// Assuming the Conversations Service is running at a known URL
const CONVERSATIONS_SERVICE_URL = process.env.CONVERSATIONS_SERVICE_URL || 'http://localhost:3007'; // Now for 'conversations' service
try {
const response = await axios.post(`${CONVERSATIONS_SERVICE_URL}/conversations`, {
channelId,
contactExternalId: lead.email || lead.phone, // Pass external ID to conversations service
contactName: lead.name,
contactEmail: lead.email,
contactPhone: lead.phone,
}, {
headers: { 'x-tenant-id': organizationId },
});
return response.data;
}
catch (error) {
console.error('Error starting conversation with lead:', error.response?.data || error.message);
throw new Error(`Failed to start conversation: ${error.response?.data?.error || error.message}`);
}
}
}
//# sourceMappingURL=StartConversationWithLead.js.map