Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
2.5 kB
3
Indexable
Never
let inputConfig = input.config();
let companyName = inputConfig["Company Name"];
console.log(`The value of "Company Name" is ${inputConfig["Company Name"]}`);

async function searchCompany(companyName) {
    const url = "https://api.apollo.io/v1/accounts/search";
    const data = {
        "api_key": "zXdZZKnvwdh37gas2F7hXQ",
        "q_organization_name": companyName,
    };
    const headers = {
        'Cache-Control': 'no-cache',
        'Content-Type': 'application/json'
    };
    
    const response = await fetch(url, {
        method: "POST",
        headers: headers,
        body: JSON.stringify(data)
    });
    const responseJson = await response.json();
    
    if(responseJson.accounts && responseJson.accounts.length > 0) {
        const websiteUrl = responseJson.accounts[0].website_url;
        const linkedinUrl = responseJson.accounts[0].linkedin_url;
        const organizationCountry = responseJson.accounts[0].organization_country;
        const foundedYear = responseJson.accounts[0].founded_year;
        
        return {
            "website_url": websiteUrl,
            "linkedin_url": linkedinUrl,
            "organization_country": organizationCountry,
            "founded_year": foundedYear,
        }
    } else {
        return {"error": "Company not found"};
    }
}

async function query(payload, API_URL) {
    const response = await fetch(API_URL, {
        method: "POST",
        body: JSON.stringify(payload),
        headers: { 'Content-Type': 'application/json' },
    });
    return response.json();
}

searchCompany(companyName).then(apolloInfo => {
    if (apolloInfo.error) {
        console.log(apolloInfo.error);
        return;
    }

    const API_URL = "http://103.69.193.226:3005/api/v1/prediction/d0b87630-383b-4402-a9e9-a9de13c6152e";
    const payload = {
        "question": `Search the internet for 'About Us' section of a company named ${companyName}, read through then summarize the company information, including what is their service or product.`
    };

    query(payload, API_URL).then(summaryInfo => {
        // Set the output
        output.set('website_url', apolloInfo.website_url);
        output.set('linkedin_url', apolloInfo.linkedin_url);
        output.set('organization_country', apolloInfo.organization_country);
        output.set('founded_year', apolloInfo.founded_year);
        output.set('summary_info', summaryInfo);
    });
});