113 lines
5.5 KiB
JavaScript
113 lines
5.5 KiB
JavaScript
const Anthropic = require('@anthropic-ai/sdk');
|
|
|
|
// Support both standard API keys and OAuth tokens
|
|
const apiKey = process.env.ANTHROPIC_API_KEY || '';
|
|
const clientOpts = {};
|
|
if (apiKey.startsWith('sk-ant-oat')) {
|
|
// OAuth token — use as auth token instead of API key
|
|
clientOpts.authToken = apiKey;
|
|
clientOpts.apiKey = null;
|
|
} else {
|
|
clientOpts.apiKey = apiKey;
|
|
}
|
|
const client = new Anthropic(clientOpts);
|
|
|
|
async function generateContent(formData) {
|
|
const { businessName, businessAddress, businessEmail, businessPhone, businessDescription } = formData;
|
|
|
|
const prompt = `You are an expert A2P 10DLC compliance consultant and web copywriter. Generate ALL content for a professional business website AND a complete A2P SMS compliance packet.
|
|
|
|
Business Details:
|
|
- Legal Business Name: ${businessName}
|
|
- Business Address: ${businessAddress}
|
|
- Support Email: ${businessEmail}
|
|
- Business Phone: ${businessPhone}
|
|
- Business Description: ${businessDescription}
|
|
|
|
Generate the following as a single JSON object. Be specific, professional, and thorough. All content should be tailored to this specific business and industry.
|
|
|
|
IMPORTANT: Return ONLY valid JSON. No markdown code fences, no explanations outside the JSON.
|
|
|
|
{
|
|
"website": {
|
|
"heroTitle": "A compelling headline for the business (5-10 words)",
|
|
"heroSubtitle": "A supporting subtitle (15-25 words)",
|
|
"ctaText": "CTA button text (2-4 words)",
|
|
"expandedDescription": "A 3-4 sentence professional business description",
|
|
"painpoints": [
|
|
{
|
|
"icon": "one of: shield, clock, chart, heart, star, zap, target, users, check, phone",
|
|
"title": "Pain point title (3-6 words)",
|
|
"description": "Pain point description (1-2 sentences)"
|
|
}
|
|
],
|
|
"howItWorks": [
|
|
{
|
|
"step": 1,
|
|
"title": "Step title (2-5 words)",
|
|
"description": "Step description (1-2 sentences)"
|
|
}
|
|
],
|
|
"faqItems": [
|
|
{
|
|
"question": "A relevant FAQ question",
|
|
"answer": "A thorough, helpful answer (2-4 sentences)"
|
|
}
|
|
],
|
|
"privacyPolicy": "COMPLETE privacy policy text in HTML format. MUST include: company name, data collection practices, how info is used, cookie policy, third-party sharing policy, and CRITICALLY: 'No mobile information will be shared with third parties/affiliates for marketing/promotional purposes. All the above categories exclude text messaging originator opt-in data and consent; this information will not be shared with any third parties.' Include contact info. Make it thorough and professional.",
|
|
"termsOfService": "COMPLETE terms of service text in HTML format. MUST include: SMS/text messaging terms section covering message frequency, data rates, opt-out (STOP), help (HELP), supported carriers, and that consent is not a condition of purchase. Include standard legal terms. Make it thorough."
|
|
},
|
|
"a2pPacket": {
|
|
"campaignDescription": "A detailed description of who sends messages (brand name), who receives them (opted-in customers via website), and why (purpose). 3-5 sentences. Reference the website URL.",
|
|
"sampleMessages": [
|
|
"First sample message with brand name and [bracketed] template fields. Include opt-out.",
|
|
"Second sample message - different type (reminder/promo/info). Include brand name.",
|
|
"Third sample message - yet another type. Include HELP instructions."
|
|
],
|
|
"optInFlowDescription": "Detailed description of how users opt in: they visit the website, fill out the contact form, check a non-pre-selected SMS consent checkbox. Describe the disclosure language on the form. Mention Privacy Policy and Terms links.",
|
|
"optInConfirmation": "Under 160 chars. Brand name, frequency, rates, HELP, STOP instructions.",
|
|
"optOutConfirmation": "Brand name + confirmation that no more messages will be sent.",
|
|
"helpMessage": "Brand name + support contact info + opt-out instructions.",
|
|
"optInKeywords": "START, SUBSCRIBE, YES",
|
|
"optOutKeywords": "STOP, UNSUBSCRIBE, END, QUIT, CANCEL",
|
|
"helpKeywords": "HELP, INFO",
|
|
"consentText": "The exact checkbox consent text for the opt-in form. Must include: brand name, message frequency varies, msg & data rates may apply, reply HELP for help, reply STOP to unsubscribe. Do NOT include links in the consent text itself."
|
|
},
|
|
"colorScheme": {
|
|
"primary": "A professional hex color that fits the business industry (e.g., #2563EB for tech, #059669 for health, #DC2626 for food)",
|
|
"primaryDark": "A darker shade of the primary",
|
|
"primaryLight": "A lighter/muted shade for backgrounds",
|
|
"accent": "A complementary accent color"
|
|
}
|
|
}
|
|
|
|
Generate 3-4 painpoints, exactly 3 howItWorks steps, and 4-6 faqItems. Make sure sample messages are realistic and include the actual business name. The privacy policy and terms of service should be COMPLETE, thorough legal documents ready for use. Return ONLY the JSON.`;
|
|
|
|
const response = await client.messages.create({
|
|
model: 'claude-sonnet-4-20250514',
|
|
max_tokens: 8000,
|
|
messages: [
|
|
{ role: 'user', content: prompt }
|
|
]
|
|
});
|
|
|
|
const text = response.content[0].text;
|
|
|
|
// Parse the JSON - handle potential markdown code fences
|
|
let jsonStr = text;
|
|
const jsonMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
if (jsonMatch) {
|
|
jsonStr = jsonMatch[1];
|
|
}
|
|
|
|
try {
|
|
const parsed = JSON.parse(jsonStr.trim());
|
|
return parsed;
|
|
} catch (e) {
|
|
console.error('Failed to parse AI response:', text.substring(0, 500));
|
|
throw new Error('AI generated invalid JSON. Please try again.');
|
|
}
|
|
}
|
|
|
|
module.exports = { generateContent };
|