• Run the automation whenever a new reply is added.
• The AI-generated analysis will be saved in the “AI Insights” field.
• You can extend this script to classify industries, job titles, and messaging effectiveness.
let table = base.getTable("Email Replies"); // Change this to your actual table name or table id
let query = await table.selectRecordsAsync();
let apiKey = "your_openai_api_key"; // Get your OpenAI API key from platform.openai.com
for (let record of query.records) {
let replyText = record.getCellValue("Reply Message");
if (!replyText) continue; // Skip empty replies
let prompt = `Analyze this email reply. Categorize as Interested, Neutral, or Not Interested. Extract key objections and suggest improvements:
Email Reply: "${replyText}"`;
let response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
body: JSON.stringify({
model: "gpt-4", // Use gpt-4 or gpt-3.5-turbo
messages: { role: "system", content: "You are an email marketing analyst." },
{ role: "user", content: prompt }],
temperature: 0.3
})
});
let data = await response.json();
let aiAnalysis = data.choicesa0]?.message?.content || "No analysis available";
// Update Airtable with the AI-generated insights
await table.updateRecordAsync(record.id, {
"AI Insights": aiAnalysis
});
}
output.set("AI Analysis Completed & Saved in Airtable");
@Sannit Vartak thanks for this. I have tested out this script, but it does not run results. I have set up to update every Monday. Can this be the root cause why I am not seeing the result. Just as a pointer - the tests I run of the script do not produce errors, but they do not output a result either. Eventually the test results in: ”Script exceeded execution time limit of 120 seconds”. What am I doing wrong:
let table = base.getTable("Email Replies");
let query = await table.selectRecordsAsync();
let apiKey = "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";
for (let record of query.records) {
let replyText = record.getCellValue("Status");
let copyStep = record.getCellValue("Copy Step");
let copyVersion = record.getCellValue("Copy Version");
let headcount = record.getCellValue("Head Count");
let industry = record.getCellValue("Industry");
let jobTitle = record.getCellValue("Prospects Job Title");
let campaignName = record.getCellValue("Campaign Name");
if (!replyText) continue;
let prompt = `Analyze email campaign performance based on responses received. Identify top-performing and underperforming elements:
- Copy Step: ${copyStep}
- Copy Version: ${copyVersion}
- Head Count: ${headcount}
- Industry: ${industry}
- Prospects Job Title: ${jobTitle}
- Campaign Name: ${campaignName}
- Status: "${replyText}"
Key insights required:
1. Determine if this reply is Interested, Maybe Later, Neutral, or Not Interested.
2. Identify which copy versions, steps, industries, and job titles drive the highest positive engagement.
3. Highlight what elements contribute to negative responses.
4. Recommend optimizations to improve future campaign success.`;
let response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
body: JSON.stringify({
model: "gpt-4",
messages: p
{ role: "system", content: "You are an advanced email marketing analyst." },
{ role: "user", content: prompt }
],
temperature: 0.3
})
});
let data = await response.json();
let aiAnalysis = data.choices0]?.message?.content || "No analysis available";
await table.updateRecordAsync(record.id, {
"AI Insights": aiAnalysis
});
}
output.set("Email Campaign Analysis Completed & Saved in Airtable");