| |
| |
|
|
| export interface LeadEnrichmentData { |
| email: string; |
| firstName?: string; |
| lastName?: string; |
| fullName?: string; |
| jobTitle?: string; |
| company?: string; |
| companyDomain?: string; |
| companySize?: string; |
| industry?: string; |
| location?: string; |
| linkedinUrl?: string; |
| twitterHandle?: string; |
| phoneNumber?: string; |
| enrichedAt: Date; |
| confidence: 'high' | 'medium' | 'low'; |
| } |
|
|
| export interface CompanyData { |
| domain: string; |
| name: string; |
| description?: string; |
| industry?: string; |
| size?: string; |
| founded?: number; |
| location?: string; |
| website?: string; |
| techStack?: string[]; |
| revenue?: string; |
| funding?: string; |
| recentNews?: Array<{ |
| title: string; |
| date: Date; |
| source: string; |
| url: string; |
| }>; |
| } |
|
|
| export class LeadEnrichmentService { |
| |
| |
| |
| |
| async enrichLead(email: string): Promise<LeadEnrichmentData> { |
| try { |
| |
| const domain = email.split('@')[1]; |
| |
| |
| const enrichedData: LeadEnrichmentData = { |
| email, |
| enrichedAt: new Date(), |
| confidence: 'medium', |
| companyDomain: domain, |
| }; |
| |
| return enrichedData; |
| } catch (error) { |
| console.error('Error enriching lead:', error); |
| return { |
| email, |
| enrichedAt: new Date(), |
| confidence: 'low', |
| }; |
| } |
| } |
|
|
| |
| |
| |
| async enrichCompany(domain: string): Promise<CompanyData> { |
| try { |
| |
| const companyData: CompanyData = { |
| domain, |
| name: domain.split('.')[0], |
| }; |
| |
| return companyData; |
| } catch (error) { |
| console.error('Error enriching company:', error); |
| throw error; |
| } |
| } |
|
|
| |
| |
| |
| async verifyEmail(email: string): Promise<{ |
| valid: boolean; |
| reason?: string; |
| deliverable: boolean; |
| }> { |
| |
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; |
| if (!emailRegex.test(email)) { |
| return { valid: false, deliverable: false, reason: 'Invalid format' }; |
| } |
| |
| |
| |
| return { |
| valid: true, |
| deliverable: true, |
| }; |
| } |
|
|
| |
| |
| |
| scoreLead(data: LeadEnrichmentData): number { |
| let score = 0; |
| |
| |
| if (data.firstName) score += 10; |
| if (data.lastName) score += 10; |
| if (data.jobTitle) score += 15; |
| if (data.company) score += 15; |
| if (data.linkedinUrl) score += 20; |
| if (data.phoneNumber) score += 10; |
| if (data.companyDomain) score += 10; |
| if (data.industry) score += 5; |
| if (data.location) score += 5; |
| |
| return score; |
| } |
|
|
| |
| |
| |
| generatePersonalizationVars( |
| lead: LeadEnrichmentData, |
| company?: CompanyData |
| ): Record<string, string> { |
| return { |
| firstName: lead.firstName || 'there', |
| lastName: lead.lastName || '', |
| fullName: lead.fullName || lead.firstName || 'there', |
| jobTitle: lead.jobTitle || 'team member', |
| company: lead.company || company?.name || 'your company', |
| industry: lead.industry || company?.industry || 'your industry', |
| location: lead.location || company?.location || '', |
| companySize: company?.size || lead.companySize || '', |
| }; |
| } |
| } |
|
|
| export const leadEnrichment = new LeadEnrichmentService(); |
|
|