untitled-6431// Val Town App - Lead Generation + Cold Email Builder

export async function leadGenApp( industry = "FinTech", solutionType = "CRM software", region = "Nigeria", jobTitle = "CTO", leadCount = 5 ) { // πŸ” NOTE: Replace this with your actual Bing Search API key const API_KEY = "YOUR_BING_API_KEY"; const SEARCH_URL = "https://api.bing.microsoft.com/v7.0/search";

// πŸ“Œ If you don’t have a Bing key, use mock search results instead const useMock = !API_KEY || API_KEY === "YOUR_BING_API_KEY";

const query = ${industry} companies in ${region} using ${solutionType}; let searchResults = [];

if (useMock) { searchResults = Array.from({ length: leadCount }).map((_, i) => ({ name: Mock Company ${i + 1}, url: https://example.com/company${i + 1}, snippet: A mock snippet about company ${i + 1} doing ${solutionType} })); } else { const response = await fetch(${SEARCH_URL}?q=${encodeURIComponent(query)}&count=${leadCount}, { headers: { "Ocp-Apim-Subscription-Key": API_KEY } });

if (!response.ok) {
  throw new Error("Failed to fetch from Bing Search API");
}

const data = await response.json();
searchResults = data.webPages?.value || [];

}

// πŸ“§ Build leads with email pitch const leads = searchResults.map((item, i) => { const company = item.name; const website = item.url; const snippet = item.snippet;

const email = `Hi ${jobTitle},\n\nI came across ${company} while researching top companies in the ${industry} space.\nWe provide a ${solutionType} that can help you streamline operations and boost efficiency.\nWould you be open to a quick conversation?\n\nBest regards,\n[Your Name]`;

return {
  ID: i + 1,
  Company: company,
  Website: website,
  Snippet: snippet,
  ColdEmail: email.replace(/\n/g, ' ')
};

});

// 🧾 Create CSV const headers = "ID,Company,Website,Snippet,ColdEmail"; const rows = leads.map(l => "${l.ID}","${l.Company}","${l.Website}","${l.Snippet}","${l.ColdEmail}" ); const csv = [headers, ...rows].join("\n");

const blob = new Blob([csv], { type: "text/csv" });

return new File([blob], "leads.csv", { type: "text/csv" }); }