@xuda.io/ai_module 1.1.4672 → 1.1.4674
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +628 -132
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -3439,7 +3439,7 @@ export const update_thumbnail = async function (type, doc, app_id, uid, job_id,
|
|
|
3439
3439
|
break;
|
|
3440
3440
|
}
|
|
3441
3441
|
|
|
3442
|
-
case '
|
|
3442
|
+
case 'conversation_title': {
|
|
3443
3443
|
prompt = `create image: ${doc.title}`;
|
|
3444
3444
|
let images_arr;
|
|
3445
3445
|
const cache = await get_chat_picture_cache(uid, 'chat_thumbnail', doc.title);
|
|
@@ -7061,141 +7061,143 @@ const get_image_blob_from_downloaded_image = async function (url) {
|
|
|
7061
7061
|
return images[0];
|
|
7062
7062
|
};
|
|
7063
7063
|
|
|
7064
|
-
export const get_business_info = async function (uid, name, email, account_profile_info) {
|
|
7065
|
-
|
|
7066
|
-
|
|
7067
|
-
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7071
|
-
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7144
|
-
|
|
7145
|
-
|
|
7146
|
-
|
|
7147
|
-
|
|
7148
|
-
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7064
|
+
// export const get_business_info = async function (uid, name, email, account_profile_info) {
|
|
7065
|
+
// // Extract lists from your JSON categories array
|
|
7066
|
+
// const categories = [
|
|
7067
|
+
// {
|
|
7068
|
+
// id: 'ind_technology',
|
|
7069
|
+
// name: 'Technology',
|
|
7070
|
+
// sub: ['Software Development', 'AI & Machine Learning', 'Cybersecurity', 'Cloud Computing', 'IT Services', 'SaaS & Platforms', 'Hardware & Electronics'],
|
|
7071
|
+
// },
|
|
7072
|
+
// {
|
|
7073
|
+
// id: 'ind_marketing',
|
|
7074
|
+
// name: 'Marketing & Advertising',
|
|
7075
|
+
// sub: ['Digital Marketing', 'PPC & SEO', 'Content Creation', 'Branding', 'Social Media Management', 'Email Marketing', 'Market Research'],
|
|
7076
|
+
// },
|
|
7077
|
+
// {
|
|
7078
|
+
// id: 'ind_sales',
|
|
7079
|
+
// name: 'Sales',
|
|
7080
|
+
// sub: ['B2B Sales', 'B2C Sales', 'Real Estate Sales', 'Account Management', 'Lead Generation', 'Inside Sales', 'Field Sales'],
|
|
7081
|
+
// },
|
|
7082
|
+
// {
|
|
7083
|
+
// id: 'ind_finance',
|
|
7084
|
+
// name: 'Finance & Accounting',
|
|
7085
|
+
// sub: ['Banking', 'Investment', 'Financial Planning', 'Accounting', 'Bookkeeping', 'Insurance', 'FinTech'],
|
|
7086
|
+
// },
|
|
7087
|
+
// {
|
|
7088
|
+
// id: 'ind_healthcare',
|
|
7089
|
+
// name: 'Healthcare',
|
|
7090
|
+
// sub: ['Medical Clinics', 'Hospitals', 'Pharma', 'Mental Health', 'Healthcare IT', 'Home Care', 'Medical Research'],
|
|
7091
|
+
// },
|
|
7092
|
+
// {
|
|
7093
|
+
// id: 'ind_realestate',
|
|
7094
|
+
// name: 'Real Estate',
|
|
7095
|
+
// sub: ['Residential Real Estate', 'Commercial Real Estate', 'Property Management', 'Investment & BRRRR', 'Construction', 'Architecture', 'Interior Design'],
|
|
7096
|
+
// },
|
|
7097
|
+
// {
|
|
7098
|
+
// id: 'ind_ecommerce',
|
|
7099
|
+
// name: 'E-commerce',
|
|
7100
|
+
// sub: ['Online Store', 'Dropshipping', 'Amazon FBA', 'Marketplace Selling', 'Retail', 'Inventory Management', 'Fulfillment & Logistics'],
|
|
7101
|
+
// },
|
|
7102
|
+
// {
|
|
7103
|
+
// id: 'ind_education',
|
|
7104
|
+
// name: 'Education',
|
|
7105
|
+
// sub: ['Schools', 'Universities', 'Private Tutoring', 'Online Courses', 'EdTech', 'Training & Development'],
|
|
7106
|
+
// },
|
|
7107
|
+
// {
|
|
7108
|
+
// id: 'ind_hospitality',
|
|
7109
|
+
// name: 'Hospitality & Travel',
|
|
7110
|
+
// sub: ['Hotels', 'Restaurants', 'Cafes & Bars', 'Travel Agencies', 'Tourism', 'Events & Catering', 'Transportation'],
|
|
7111
|
+
// },
|
|
7112
|
+
// {
|
|
7113
|
+
// id: 'ind_professional',
|
|
7114
|
+
// name: 'Professional Services',
|
|
7115
|
+
// sub: ['Legal', 'Consulting', 'HR & Recruiting', 'Accounting Firms', 'Business Services', 'Management Consulting'],
|
|
7116
|
+
// },
|
|
7117
|
+
// {
|
|
7118
|
+
// id: 'ind_manufacturing',
|
|
7119
|
+
// name: 'Manufacturing',
|
|
7120
|
+
// sub: ['Automotive', 'Industrial', 'Textile', 'Electronics', 'Food Production', 'Machinery', 'Chemicals'],
|
|
7121
|
+
// },
|
|
7122
|
+
// {
|
|
7123
|
+
// id: 'ind_nonprofit',
|
|
7124
|
+
// name: 'Nonprofit & Government',
|
|
7125
|
+
// sub: ['NGOs', 'Municipality', 'Government Services', 'Public Health', 'Community Organizations', 'Education Programs'],
|
|
7126
|
+
// },
|
|
7127
|
+
// {
|
|
7128
|
+
// id: 'ind_media',
|
|
7129
|
+
// name: 'Media & Entertainment',
|
|
7130
|
+
// sub: ['Film & Video', 'Music', 'Publishing', 'Gaming', 'News & Journalism', 'Influencers', 'Production Studios'],
|
|
7131
|
+
// },
|
|
7132
|
+
// {
|
|
7133
|
+
// id: 'ind_logistics',
|
|
7134
|
+
// name: 'Logistics & Transportation',
|
|
7135
|
+
// sub: ['Shipping', 'Trucking', 'Last-Mile Delivery', 'Warehousing', 'Freight Forwarding', 'Route Optimization'],
|
|
7136
|
+
// },
|
|
7137
|
+
// {
|
|
7138
|
+
// id: 'ind_energy',
|
|
7139
|
+
// name: 'Energy & Utilities',
|
|
7140
|
+
// sub: ['Solar', 'Oil & Gas', 'Electricity Providers', 'Water Utilities', 'Environmental Services', 'Renewable Energy'],
|
|
7141
|
+
// },
|
|
7142
|
+
// {
|
|
7143
|
+
// id: 'ind_construction',
|
|
7144
|
+
// name: 'Construction & Trades',
|
|
7145
|
+
// sub: ['General Contracting', 'Roofing', 'Plumbing', 'HVAC', 'Electrical', 'Renovation', 'Engineering'],
|
|
7146
|
+
// },
|
|
7147
|
+
// {
|
|
7148
|
+
// id: 'ind_food',
|
|
7149
|
+
// name: 'Food & Beverage',
|
|
7150
|
+
// sub: ['Restaurants', 'Catering', 'Food Manufacturing', 'Bakeries', 'Bars & Nightlife', 'Food Delivery'],
|
|
7151
|
+
// },
|
|
7152
|
+
// {
|
|
7153
|
+
// id: 'ind_retail',
|
|
7154
|
+
// name: 'Retail',
|
|
7155
|
+
// sub: ['Physical Stores', 'Boutiques', 'Supermarkets', 'Consumer Goods', 'Fashion Retail', 'Home Goods'],
|
|
7156
|
+
// },
|
|
7157
|
+
// ];
|
|
7158
|
+
// const categoryNames = categories.map((c) => c.name);
|
|
7159
|
+
// const allSubCategories = categories.flatMap((c) => c.sub);
|
|
7160
|
+
|
|
7161
|
+
// const business_info_ret = await submit_chat_gpt_prompt({
|
|
7162
|
+
// uid,
|
|
7163
|
+
// prompt: `Research the company: "${name}" (${email}).
|
|
7164
|
+
// 1. get the company name.
|
|
7165
|
+
// 2. get the domain name from the email.
|
|
7166
|
+
// 2. Provide a professional one-sentence biography of the company.
|
|
7167
|
+
// 3. Categorize them using the provided industry lists.
|
|
7168
|
+
// 4. Identify their primary country as a 2-letter ISO code (e.g., 'US').`,
|
|
7169
|
+
// model: 'gpt-5-nano',
|
|
7170
|
+
// response_format: z.object({
|
|
7171
|
+
// business_name: z.string().describe('the company name'),
|
|
7172
|
+
// business_domain: z.string().describe('the email domain name'),
|
|
7173
|
+
// business_bio: z.string().describe('A concise, professional one-sentence summary of what the business does'),
|
|
7174
|
+
// business_size: z.enum(['unknown', 'small', 'medium', 'large', 'enterprise']),
|
|
7175
|
+
// business_category: z.enum(categoryNames),
|
|
7176
|
+
// business_sub_category: z.enum(allSubCategories),
|
|
7177
|
+
// business_country: z.string().length(2).describe("2-letter ISO country code (e.g., 'US')"),
|
|
7178
|
+
// }),
|
|
7179
|
+
// metadata: { func: 'get_business_info' },
|
|
7180
|
+
// account_profile_info,
|
|
7181
|
+
// tools: [{ type: 'web_search_preview' }],
|
|
7182
|
+
// });
|
|
7160
7183
|
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
1. get the company name.
|
|
7165
|
-
2. Provide a professional one-sentence biography of the company.
|
|
7166
|
-
3. Categorize them using the provided industry lists.
|
|
7167
|
-
4. Identify their primary country as a 2-letter ISO code (e.g., 'US').`,
|
|
7168
|
-
model: 'gpt-5-nano',
|
|
7169
|
-
response_format: z.object({
|
|
7170
|
-
business_name: z.string().describe('the company name'),
|
|
7171
|
-
business_bio: z.string().describe('A concise, professional one-sentence summary of what the business does'),
|
|
7172
|
-
business_size: z.enum(['unknown', 'small', 'medium', 'large', 'enterprise']),
|
|
7173
|
-
business_category: z.enum(categoryNames),
|
|
7174
|
-
business_sub_category: z.enum(allSubCategories),
|
|
7175
|
-
business_country: z.string().length(2).describe("2-letter ISO country code (e.g., 'US')"),
|
|
7176
|
-
}),
|
|
7177
|
-
metadata: { func: 'get_business_info' },
|
|
7178
|
-
account_profile_info,
|
|
7179
|
-
tools: [{ type: 'web_search_preview' }],
|
|
7180
|
-
});
|
|
7181
|
-
|
|
7182
|
-
try {
|
|
7183
|
-
if (business_info_ret.code > -1) {
|
|
7184
|
-
const data = typeof business_info_ret.data === 'string' ? JSON.parse(business_info_ret.data) : business_info_ret.data;
|
|
7184
|
+
// try {
|
|
7185
|
+
// if (business_info_ret.code > -1) {
|
|
7186
|
+
// const data = typeof business_info_ret.data === 'string' ? JSON.parse(business_info_ret.data) : business_info_ret.data;
|
|
7185
7187
|
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
+
// // Standardize country to uppercase
|
|
7189
|
+
// if (data.business_country) data.business_country = data.business_country.toUpperCase();
|
|
7188
7190
|
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7191
|
+
// // Logic to attach the ID for your database
|
|
7192
|
+
// const matched = categories.find((c) => c.name === data.business_category);
|
|
7193
|
+
// data.business_category_id = matched ? matched.id : null;
|
|
7192
7194
|
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
};
|
|
7195
|
+
// return data;
|
|
7196
|
+
// }
|
|
7197
|
+
// } catch (error) {
|
|
7198
|
+
// console.error('Error in get_business_info:', error);
|
|
7199
|
+
// }
|
|
7200
|
+
// };
|
|
7199
7201
|
|
|
7200
7202
|
const get_chat_picture_cache = async function (uid, docType, key) {
|
|
7201
7203
|
if (!key || typeof key !== 'string') return null;
|
|
@@ -8598,3 +8600,497 @@ Category:`;
|
|
|
8598
8600
|
};
|
|
8599
8601
|
}
|
|
8600
8602
|
};
|
|
8603
|
+
|
|
8604
|
+
export const get_business_info = async function (uid, name, email, account_profile_info) {
|
|
8605
|
+
// ========== HELPER FUNCTIONS ==========
|
|
8606
|
+
|
|
8607
|
+
function validatePhoneNumber(phone) {
|
|
8608
|
+
if (!phone || phone.toLowerCase() === 'not available' || phone.trim() === '') {
|
|
8609
|
+
return 'Not available';
|
|
8610
|
+
}
|
|
8611
|
+
|
|
8612
|
+
const cleaned = phone.replace(/[^\d\+\(\)\-\s]/g, '');
|
|
8613
|
+
const digitCount = (cleaned.match(/\d/g) || []).length;
|
|
8614
|
+
|
|
8615
|
+
// Require at least 7 digits for a valid phone number
|
|
8616
|
+
if (digitCount < 7) {
|
|
8617
|
+
return 'Not available';
|
|
8618
|
+
}
|
|
8619
|
+
|
|
8620
|
+
return cleaned.trim();
|
|
8621
|
+
}
|
|
8622
|
+
|
|
8623
|
+
function validateWebsite(website) {
|
|
8624
|
+
if (!website || website.toLowerCase() === 'not available' || website.trim() === '') {
|
|
8625
|
+
return 'Not available';
|
|
8626
|
+
}
|
|
8627
|
+
|
|
8628
|
+
const trimmed = website.trim();
|
|
8629
|
+
|
|
8630
|
+
// Ensure URL has proper protocol
|
|
8631
|
+
if (!trimmed.startsWith('http://') && !trimmed.startsWith('https://')) {
|
|
8632
|
+
// Check if it looks like a domain
|
|
8633
|
+
if (trimmed.includes('.') && !trimmed.includes(' ')) {
|
|
8634
|
+
return `https://${trimmed.replace(/^www\./, '')}`;
|
|
8635
|
+
}
|
|
8636
|
+
return 'Not available';
|
|
8637
|
+
}
|
|
8638
|
+
|
|
8639
|
+
return trimmed;
|
|
8640
|
+
}
|
|
8641
|
+
|
|
8642
|
+
function cleanStreetAddress(street) {
|
|
8643
|
+
if (!street || street.toLowerCase() === 'not available' || street.trim() === '') {
|
|
8644
|
+
return 'Not available';
|
|
8645
|
+
}
|
|
8646
|
+
|
|
8647
|
+
return street
|
|
8648
|
+
.replace(/\s+/g, ' ')
|
|
8649
|
+
.replace(/,\s*$/g, '') // Remove trailing commas
|
|
8650
|
+
.trim();
|
|
8651
|
+
}
|
|
8652
|
+
|
|
8653
|
+
function cleanText(text) {
|
|
8654
|
+
if (!text || text.toLowerCase() === 'not available' || text.trim() === '') {
|
|
8655
|
+
return 'Not available';
|
|
8656
|
+
}
|
|
8657
|
+
|
|
8658
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
8659
|
+
}
|
|
8660
|
+
|
|
8661
|
+
function cleanZipCode(zip, country) {
|
|
8662
|
+
if (!zip || zip.toLowerCase() === 'not available' || zip.trim() === '') {
|
|
8663
|
+
return 'Not available';
|
|
8664
|
+
}
|
|
8665
|
+
|
|
8666
|
+
const cleaned = zip.trim();
|
|
8667
|
+
|
|
8668
|
+
// Country-specific formatting
|
|
8669
|
+
switch (country) {
|
|
8670
|
+
case 'US':
|
|
8671
|
+
// US ZIP: 5 digits or 5-4 format
|
|
8672
|
+
return cleaned.replace(/\D/g, '').replace(/^(\d{5})(\d{4})$/, '$1-$2');
|
|
8673
|
+
case 'CA':
|
|
8674
|
+
// Canada: A1A 1A1 format
|
|
8675
|
+
return cleaned.toUpperCase().replace(/\s+/g, '');
|
|
8676
|
+
case 'UK':
|
|
8677
|
+
// UK: various formats, preserve as is but uppercase
|
|
8678
|
+
return cleaned.toUpperCase();
|
|
8679
|
+
case 'AU':
|
|
8680
|
+
// Australia: 4 digits
|
|
8681
|
+
return cleaned.replace(/\D/g, '');
|
|
8682
|
+
default:
|
|
8683
|
+
return cleaned;
|
|
8684
|
+
}
|
|
8685
|
+
}
|
|
8686
|
+
|
|
8687
|
+
function cleanStateProvince(state, country) {
|
|
8688
|
+
if (!state || state.toLowerCase() === 'not available' || state.trim() === '') {
|
|
8689
|
+
return 'Not available';
|
|
8690
|
+
}
|
|
8691
|
+
|
|
8692
|
+
const cleaned = state.trim();
|
|
8693
|
+
|
|
8694
|
+
// Standardize US state abbreviations
|
|
8695
|
+
if (country === 'US') {
|
|
8696
|
+
const stateMap = {
|
|
8697
|
+
alabama: 'AL',
|
|
8698
|
+
alaska: 'AK',
|
|
8699
|
+
arizona: 'AZ',
|
|
8700
|
+
arkansas: 'AR',
|
|
8701
|
+
california: 'CA',
|
|
8702
|
+
colorado: 'CO',
|
|
8703
|
+
connecticut: 'CT',
|
|
8704
|
+
delaware: 'DE',
|
|
8705
|
+
florida: 'FL',
|
|
8706
|
+
georgia: 'GA',
|
|
8707
|
+
hawaii: 'HI',
|
|
8708
|
+
idaho: 'ID',
|
|
8709
|
+
illinois: 'IL',
|
|
8710
|
+
indiana: 'IN',
|
|
8711
|
+
iowa: 'IA',
|
|
8712
|
+
kansas: 'KS',
|
|
8713
|
+
kentucky: 'KY',
|
|
8714
|
+
louisiana: 'LA',
|
|
8715
|
+
maine: 'ME',
|
|
8716
|
+
maryland: 'MD',
|
|
8717
|
+
massachusetts: 'MA',
|
|
8718
|
+
michigan: 'MI',
|
|
8719
|
+
minnesota: 'MN',
|
|
8720
|
+
mississippi: 'MS',
|
|
8721
|
+
missouri: 'MO',
|
|
8722
|
+
montana: 'MT',
|
|
8723
|
+
nebraska: 'NE',
|
|
8724
|
+
nevada: 'NV',
|
|
8725
|
+
'new hampshire': 'NH',
|
|
8726
|
+
'new jersey': 'NJ',
|
|
8727
|
+
'new mexico': 'NM',
|
|
8728
|
+
'new york': 'NY',
|
|
8729
|
+
'north carolina': 'NC',
|
|
8730
|
+
'north dakota': 'ND',
|
|
8731
|
+
ohio: 'OH',
|
|
8732
|
+
oklahoma: 'OK',
|
|
8733
|
+
oregon: 'OR',
|
|
8734
|
+
pennsylvania: 'PA',
|
|
8735
|
+
'rhode island': 'RI',
|
|
8736
|
+
'south carolina': 'SC',
|
|
8737
|
+
'south dakota': 'SD',
|
|
8738
|
+
tennessee: 'TN',
|
|
8739
|
+
texas: 'TX',
|
|
8740
|
+
utah: 'UT',
|
|
8741
|
+
vermont: 'VT',
|
|
8742
|
+
virginia: 'VA',
|
|
8743
|
+
washington: 'WA',
|
|
8744
|
+
'west virginia': 'WV',
|
|
8745
|
+
wisconsin: 'WI',
|
|
8746
|
+
wyoming: 'WY',
|
|
8747
|
+
'district of columbia': 'DC',
|
|
8748
|
+
};
|
|
8749
|
+
|
|
8750
|
+
const lowerState = cleaned.toLowerCase();
|
|
8751
|
+
if (stateMap[lowerState]) {
|
|
8752
|
+
return stateMap[lowerState];
|
|
8753
|
+
}
|
|
8754
|
+
|
|
8755
|
+
// If already 2-letter code, uppercase it
|
|
8756
|
+
if (/^[A-Z]{2}$/i.test(cleaned)) {
|
|
8757
|
+
return cleaned.toUpperCase();
|
|
8758
|
+
}
|
|
8759
|
+
}
|
|
8760
|
+
|
|
8761
|
+
return cleaned;
|
|
8762
|
+
}
|
|
8763
|
+
|
|
8764
|
+
function cleanCountry(country) {
|
|
8765
|
+
if (!country || country.toLowerCase() === 'not available' || country.trim() === '') {
|
|
8766
|
+
return 'Not available';
|
|
8767
|
+
}
|
|
8768
|
+
|
|
8769
|
+
// Convert 2-letter codes to full country names for display
|
|
8770
|
+
const countryMap = {
|
|
8771
|
+
US: 'United States',
|
|
8772
|
+
CA: 'Canada',
|
|
8773
|
+
UK: 'United Kingdom',
|
|
8774
|
+
GB: 'United Kingdom',
|
|
8775
|
+
AU: 'Australia',
|
|
8776
|
+
DE: 'Germany',
|
|
8777
|
+
FR: 'France',
|
|
8778
|
+
JP: 'Japan',
|
|
8779
|
+
CN: 'China',
|
|
8780
|
+
IN: 'India',
|
|
8781
|
+
BR: 'Brazil',
|
|
8782
|
+
MX: 'Mexico',
|
|
8783
|
+
};
|
|
8784
|
+
|
|
8785
|
+
const upperCountry = country.toUpperCase();
|
|
8786
|
+
return countryMap[upperCountry] || upperCountry;
|
|
8787
|
+
}
|
|
8788
|
+
|
|
8789
|
+
function formatFullAddress(data) {
|
|
8790
|
+
const parts = [];
|
|
8791
|
+
|
|
8792
|
+
if (data.business_address_street && data.business_address_street !== 'Not available') {
|
|
8793
|
+
parts.push(data.business_address_street);
|
|
8794
|
+
}
|
|
8795
|
+
|
|
8796
|
+
const cityStateZip = [];
|
|
8797
|
+
if (data.business_address_city && data.business_address_city !== 'Not available') {
|
|
8798
|
+
cityStateZip.push(data.business_address_city);
|
|
8799
|
+
}
|
|
8800
|
+
|
|
8801
|
+
if (data.business_address_state && data.business_address_state !== 'Not available') {
|
|
8802
|
+
cityStateZip.push(data.business_address_state);
|
|
8803
|
+
}
|
|
8804
|
+
|
|
8805
|
+
if (data.business_address_zip && data.business_address_zip !== 'Not available') {
|
|
8806
|
+
cityStateZip.push(data.business_address_zip);
|
|
8807
|
+
}
|
|
8808
|
+
|
|
8809
|
+
if (cityStateZip.length > 0) {
|
|
8810
|
+
parts.push(cityStateZip.join(', '));
|
|
8811
|
+
}
|
|
8812
|
+
|
|
8813
|
+
if (data.business_address_country && data.business_address_country !== 'Not available') {
|
|
8814
|
+
parts.push(data.business_address_country);
|
|
8815
|
+
}
|
|
8816
|
+
|
|
8817
|
+
return parts.length > 0 ? parts.join(', ') : 'Not available';
|
|
8818
|
+
}
|
|
8819
|
+
|
|
8820
|
+
function getRegionFromState(state, country) {
|
|
8821
|
+
if (country !== 'US' || state === 'Not available') return null;
|
|
8822
|
+
|
|
8823
|
+
const regions = {
|
|
8824
|
+
Northeast: ['CT', 'ME', 'MA', 'NH', 'RI', 'VT', 'NJ', 'NY', 'PA'],
|
|
8825
|
+
Midwest: ['IL', 'IN', 'MI', 'OH', 'WI', 'IA', 'KS', 'MN', 'MO', 'NE', 'ND', 'SD'],
|
|
8826
|
+
South: ['DE', 'FL', 'GA', 'MD', 'NC', 'SC', 'VA', 'DC', 'WV', 'AL', 'KY', 'MS', 'TN', 'AR', 'LA', 'OK', 'TX'],
|
|
8827
|
+
West: ['AZ', 'CO', 'ID', 'MT', 'NV', 'NM', 'UT', 'WY', 'AK', 'CA', 'HI', 'OR', 'WA'],
|
|
8828
|
+
};
|
|
8829
|
+
|
|
8830
|
+
for (const [region, states] of Object.entries(regions)) {
|
|
8831
|
+
if (states.includes(state)) {
|
|
8832
|
+
return region;
|
|
8833
|
+
}
|
|
8834
|
+
}
|
|
8835
|
+
|
|
8836
|
+
return null;
|
|
8837
|
+
}
|
|
8838
|
+
|
|
8839
|
+
function getDefaultBusinessInfo(name, email, error = null) {
|
|
8840
|
+
const domain = email.includes('@') ? email.split('@')[1] : '';
|
|
8841
|
+
|
|
8842
|
+
return {
|
|
8843
|
+
business_name: name,
|
|
8844
|
+
business_domain: domain,
|
|
8845
|
+
business_bio: 'Information not available',
|
|
8846
|
+
business_size: 'unknown',
|
|
8847
|
+
business_category: 'Professional Services',
|
|
8848
|
+
business_sub_category: 'Business Services',
|
|
8849
|
+
business_country: 'US',
|
|
8850
|
+
business_phone: 'Not available',
|
|
8851
|
+
business_website: 'Not available',
|
|
8852
|
+
|
|
8853
|
+
// Address components
|
|
8854
|
+
business_address_street: 'Not available',
|
|
8855
|
+
business_address_city: 'Not available',
|
|
8856
|
+
business_address_state: 'Not available',
|
|
8857
|
+
business_address_zip: 'Not available',
|
|
8858
|
+
business_address_country: 'Not available',
|
|
8859
|
+
business_address_full: 'Not available',
|
|
8860
|
+
|
|
8861
|
+
// Structured objects
|
|
8862
|
+
business_category_id: null,
|
|
8863
|
+
business_address: {
|
|
8864
|
+
street: 'Not available',
|
|
8865
|
+
city: 'Not available',
|
|
8866
|
+
state: 'Not available',
|
|
8867
|
+
zip: 'Not available',
|
|
8868
|
+
country: 'Not available',
|
|
8869
|
+
full: 'Not available',
|
|
8870
|
+
coordinates: null,
|
|
8871
|
+
timezone: null,
|
|
8872
|
+
},
|
|
8873
|
+
business_location: {
|
|
8874
|
+
region: null,
|
|
8875
|
+
metro_area: null,
|
|
8876
|
+
is_headquarters: null,
|
|
8877
|
+
},
|
|
8878
|
+
error: error || 'API call failed',
|
|
8879
|
+
};
|
|
8880
|
+
}
|
|
8881
|
+
|
|
8882
|
+
// Extract lists from your JSON categories array
|
|
8883
|
+
const categories = [
|
|
8884
|
+
{
|
|
8885
|
+
id: 'ind_technology',
|
|
8886
|
+
name: 'Technology',
|
|
8887
|
+
sub: ['Software Development', 'AI & Machine Learning', 'Cybersecurity', 'Cloud Computing', 'IT Services', 'SaaS & Platforms', 'Hardware & Electronics'],
|
|
8888
|
+
},
|
|
8889
|
+
{
|
|
8890
|
+
id: 'ind_marketing',
|
|
8891
|
+
name: 'Marketing & Advertising',
|
|
8892
|
+
sub: ['Digital Marketing', 'PPC & SEO', 'Content Creation', 'Branding', 'Social Media Management', 'Email Marketing', 'Market Research'],
|
|
8893
|
+
},
|
|
8894
|
+
{
|
|
8895
|
+
id: 'ind_sales',
|
|
8896
|
+
name: 'Sales',
|
|
8897
|
+
sub: ['B2B Sales', 'B2C Sales', 'Real Estate Sales', 'Account Management', 'Lead Generation', 'Inside Sales', 'Field Sales'],
|
|
8898
|
+
},
|
|
8899
|
+
{
|
|
8900
|
+
id: 'ind_finance',
|
|
8901
|
+
name: 'Finance & Accounting',
|
|
8902
|
+
sub: ['Banking', 'Investment', 'Financial Planning', 'Accounting', 'Bookkeeping', 'Insurance', 'FinTech'],
|
|
8903
|
+
},
|
|
8904
|
+
{
|
|
8905
|
+
id: 'ind_healthcare',
|
|
8906
|
+
name: 'Healthcare',
|
|
8907
|
+
sub: ['Medical Clinics', 'Hospitals', 'Pharma', 'Mental Health', 'Healthcare IT', 'Home Care', 'Medical Research'],
|
|
8908
|
+
},
|
|
8909
|
+
{
|
|
8910
|
+
id: 'ind_realestate',
|
|
8911
|
+
name: 'Real Estate',
|
|
8912
|
+
sub: ['Residential Real Estate', 'Commercial Real Estate', 'Property Management', 'Investment & BRRRR', 'Construction', 'Architecture', 'Interior Design'],
|
|
8913
|
+
},
|
|
8914
|
+
{
|
|
8915
|
+
id: 'ind_ecommerce',
|
|
8916
|
+
name: 'E-commerce',
|
|
8917
|
+
sub: ['Online Store', 'Dropshipping', 'Amazon FBA', 'Marketplace Selling', 'Retail', 'Inventory Management', 'Fulfillment & Logistics'],
|
|
8918
|
+
},
|
|
8919
|
+
{
|
|
8920
|
+
id: 'ind_education',
|
|
8921
|
+
name: 'Education',
|
|
8922
|
+
sub: ['Schools', 'Universities', 'Private Tutoring', 'Online Courses', 'EdTech', 'Training & Development'],
|
|
8923
|
+
},
|
|
8924
|
+
{
|
|
8925
|
+
id: 'ind_hospitality',
|
|
8926
|
+
name: 'Hospitality & Travel',
|
|
8927
|
+
sub: ['Hotels', 'Restaurants', 'Cafes & Bars', 'Travel Agencies', 'Tourism', 'Events & Catering', 'Transportation'],
|
|
8928
|
+
},
|
|
8929
|
+
{
|
|
8930
|
+
id: 'ind_professional',
|
|
8931
|
+
name: 'Professional Services',
|
|
8932
|
+
sub: ['Legal', 'Consulting', 'HR & Recruiting', 'Accounting Firms', 'Business Services', 'Management Consulting'],
|
|
8933
|
+
},
|
|
8934
|
+
{
|
|
8935
|
+
id: 'ind_manufacturing',
|
|
8936
|
+
name: 'Manufacturing',
|
|
8937
|
+
sub: ['Automotive', 'Industrial', 'Textile', 'Electronics', 'Food Production', 'Machinery', 'Chemicals'],
|
|
8938
|
+
},
|
|
8939
|
+
{
|
|
8940
|
+
id: 'ind_nonprofit',
|
|
8941
|
+
name: 'Nonprofit & Government',
|
|
8942
|
+
sub: ['NGOs', 'Municipality', 'Government Services', 'Public Health', 'Community Organizations', 'Education Programs'],
|
|
8943
|
+
},
|
|
8944
|
+
{
|
|
8945
|
+
id: 'ind_media',
|
|
8946
|
+
name: 'Media & Entertainment',
|
|
8947
|
+
sub: ['Film & Video', 'Music', 'Publishing', 'Gaming', 'News & Journalism', 'Influencers', 'Production Studios'],
|
|
8948
|
+
},
|
|
8949
|
+
{
|
|
8950
|
+
id: 'ind_logistics',
|
|
8951
|
+
name: 'Logistics & Transportation',
|
|
8952
|
+
sub: ['Shipping', 'Trucking', 'Last-Mile Delivery', 'Warehousing', 'Freight Forwarding', 'Route Optimization'],
|
|
8953
|
+
},
|
|
8954
|
+
{
|
|
8955
|
+
id: 'ind_energy',
|
|
8956
|
+
name: 'Energy & Utilities',
|
|
8957
|
+
sub: ['Solar', 'Oil & Gas', 'Electricity Providers', 'Water Utilities', 'Environmental Services', 'Renewable Energy'],
|
|
8958
|
+
},
|
|
8959
|
+
{
|
|
8960
|
+
id: 'ind_construction',
|
|
8961
|
+
name: 'Construction & Trades',
|
|
8962
|
+
sub: ['General Contracting', 'Roofing', 'Plumbing', 'HVAC', 'Electrical', 'Renovation', 'Engineering'],
|
|
8963
|
+
},
|
|
8964
|
+
{
|
|
8965
|
+
id: 'ind_food',
|
|
8966
|
+
name: 'Food & Beverage',
|
|
8967
|
+
sub: ['Restaurants', 'Catering', 'Food Manufacturing', 'Bakeries', 'Bars & Nightlife', 'Food Delivery'],
|
|
8968
|
+
},
|
|
8969
|
+
{
|
|
8970
|
+
id: 'ind_retail',
|
|
8971
|
+
name: 'Retail',
|
|
8972
|
+
sub: ['Physical Stores', 'Boutiques', 'Supermarkets', 'Consumer Goods', 'Fashion Retail', 'Home Goods'],
|
|
8973
|
+
},
|
|
8974
|
+
];
|
|
8975
|
+
const categoryNames = categories.map((c) => c.name);
|
|
8976
|
+
const allSubCategories = categories.flatMap((c) => c.sub);
|
|
8977
|
+
|
|
8978
|
+
const business_info_ret = await submit_chat_gpt_prompt({
|
|
8979
|
+
uid,
|
|
8980
|
+
prompt: `Research the company: "${name}" (${email}).
|
|
8981
|
+
|
|
8982
|
+
REQUIRED INFORMATION:
|
|
8983
|
+
1. Company name (official name)
|
|
8984
|
+
2. Email domain name
|
|
8985
|
+
3. Professional one-sentence biography
|
|
8986
|
+
4. Industry category and sub-category
|
|
8987
|
+
5. Primary country (2-letter ISO code)
|
|
8988
|
+
6. Telephone number
|
|
8989
|
+
7. Website URL
|
|
8990
|
+
8. COMPLETE ADDRESS DETAILS:
|
|
8991
|
+
- Full street address (street number, street name, suite/apt if applicable)
|
|
8992
|
+
- City
|
|
8993
|
+
- State/Province (use abbreviation where standard)
|
|
8994
|
+
- Zip/Postal code
|
|
8995
|
+
- Country
|
|
8996
|
+
|
|
8997
|
+
ADDRESS FORMATTING EXAMPLES:
|
|
8998
|
+
- Full street: "1600 Amphitheatre Parkway"
|
|
8999
|
+
- City: "Mountain View"
|
|
9000
|
+
- State: "CA"
|
|
9001
|
+
- Zip: "94043"
|
|
9002
|
+
- Country: "US"
|
|
9003
|
+
- Full address: "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA"
|
|
9004
|
+
|
|
9005
|
+
INSTRUCTIONS:
|
|
9006
|
+
- Use web search to find accurate information
|
|
9007
|
+
- If not found online, infer from typical patterns
|
|
9008
|
+
- For unknown info, use "Not available"
|
|
9009
|
+
- For US states, use 2-letter abbreviations (CA, NY, TX, etc.)
|
|
9010
|
+
- For other countries, use standard regional names
|
|
9011
|
+
|
|
9012
|
+
Be as precise and accurate as possible.`,
|
|
9013
|
+
model: 'gpt-4o-mini',
|
|
9014
|
+
response_format: z.object({
|
|
9015
|
+
business_name: z.string().describe('Official company name'),
|
|
9016
|
+
business_domain: z.string().describe('Domain name from email'),
|
|
9017
|
+
business_bio: z.string().describe('One-sentence professional summary'),
|
|
9018
|
+
business_size: z.enum(['unknown', 'small', 'medium', 'large', 'enterprise']),
|
|
9019
|
+
business_category: z.enum(categoryNames),
|
|
9020
|
+
business_sub_category: z.enum(allSubCategories),
|
|
9021
|
+
business_country: z.string().length(2).describe('2-letter ISO country code'),
|
|
9022
|
+
business_phone: z.string().describe("Telephone number or 'Not available'"),
|
|
9023
|
+
business_website: z.string().describe("Website URL or 'Not available'"),
|
|
9024
|
+
|
|
9025
|
+
// Complete address components
|
|
9026
|
+
business_address_street: z.string().describe('Full street address (number, street, suite)'),
|
|
9027
|
+
business_address_city: z.string().describe('City name'),
|
|
9028
|
+
business_address_state: z.string().describe('State/Province (abbreviation if standard)'),
|
|
9029
|
+
business_address_zip: z.string().describe('Zip/Postal code'),
|
|
9030
|
+
business_address_country: z.string().describe('Country name'),
|
|
9031
|
+
business_address_full: z.string().describe('Complete formatted address'),
|
|
9032
|
+
}),
|
|
9033
|
+
metadata: {
|
|
9034
|
+
func: 'get_business_info',
|
|
9035
|
+
company_name: name,
|
|
9036
|
+
company_email: email,
|
|
9037
|
+
},
|
|
9038
|
+
account_profile_info,
|
|
9039
|
+
tools: [{ type: 'web_search_preview' }],
|
|
9040
|
+
});
|
|
9041
|
+
|
|
9042
|
+
try {
|
|
9043
|
+
if (business_info_ret.code > -1) {
|
|
9044
|
+
const data = typeof business_info_ret.data === 'string' ? JSON.parse(business_info_ret.data) : business_info_ret.data;
|
|
9045
|
+
|
|
9046
|
+
// Standardize country codes to uppercase
|
|
9047
|
+
if (data.business_country) data.business_country = data.business_country.toUpperCase();
|
|
9048
|
+
if (data.business_address_country) {
|
|
9049
|
+
data.business_address_country = data.business_address_country.toUpperCase();
|
|
9050
|
+
}
|
|
9051
|
+
|
|
9052
|
+
// Logic to attach the ID for your database
|
|
9053
|
+
const matched = categories.find((c) => c.name === data.business_category);
|
|
9054
|
+
data.business_category_id = matched ? matched.id : null;
|
|
9055
|
+
|
|
9056
|
+
// Validate and clean all contact information
|
|
9057
|
+
data.business_phone = validatePhoneNumber(data.business_phone);
|
|
9058
|
+
data.business_website = validateWebsite(data.business_website);
|
|
9059
|
+
|
|
9060
|
+
// Clean and standardize all address components
|
|
9061
|
+
data.business_address_street = cleanStreetAddress(data.business_address_street);
|
|
9062
|
+
data.business_address_city = cleanText(data.business_address_city);
|
|
9063
|
+
data.business_address_zip = cleanZipCode(data.business_address_zip, data.business_country);
|
|
9064
|
+
data.business_address_state = cleanStateProvince(data.business_address_state, data.business_country);
|
|
9065
|
+
data.business_address_country = cleanCountry(data.business_address_country || data.business_country);
|
|
9066
|
+
data.business_address_full = formatFullAddress(data);
|
|
9067
|
+
|
|
9068
|
+
// Create a comprehensive structured address object
|
|
9069
|
+
data.business_address = {
|
|
9070
|
+
street: data.business_address_street,
|
|
9071
|
+
city: data.business_address_city,
|
|
9072
|
+
state: data.business_address_state,
|
|
9073
|
+
zip: data.business_address_zip,
|
|
9074
|
+
country: data.business_address_country,
|
|
9075
|
+
full: data.business_address_full,
|
|
9076
|
+
coordinates: null, // Can be populated later with geocoding
|
|
9077
|
+
timezone: null, // Can be populated later
|
|
9078
|
+
};
|
|
9079
|
+
|
|
9080
|
+
// Generate additional useful fields
|
|
9081
|
+
data.business_location = {
|
|
9082
|
+
region: getRegionFromState(data.business_address_state, data.business_country),
|
|
9083
|
+
metro_area: null, // Can be populated later
|
|
9084
|
+
is_headquarters: null, // Can be determined from address pattern
|
|
9085
|
+
};
|
|
9086
|
+
|
|
9087
|
+
return data;
|
|
9088
|
+
} else {
|
|
9089
|
+
console.error('Business info API call failed:', business_info_ret);
|
|
9090
|
+
return getDefaultBusinessInfo(name, email);
|
|
9091
|
+
}
|
|
9092
|
+
} catch (error) {
|
|
9093
|
+
console.error('Error in get_business_info:', error);
|
|
9094
|
+
return getDefaultBusinessInfo(name, email, error.message);
|
|
9095
|
+
}
|
|
9096
|
+
};
|