-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle-apps-script.js
More file actions
157 lines (139 loc) · 4.92 KB
/
google-apps-script.js
File metadata and controls
157 lines (139 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
function doPost(e) {
try {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const data = JSON.parse(e.postData.contents);
// Check if it's a newsletter signup or insurance form
if (data.type === 'newsletter') {
handleNewsletterSignup(sheet, data);
} else if (data.type === 'insurance_quote') {
handleInsuranceQuote(sheet, data);
}
return ContentService.createTextOutput(JSON.stringify({
status: 'success',
message: 'Data received successfully'
})).setMimeType(ContentService.MimeType.JSON);
} catch (error) {
return ContentService.createTextOutput(JSON.stringify({
status: 'error',
message: error.toString()
})).setMimeType(ContentService.MimeType.JSON);
}
}
function handleNewsletterSignup(sheet, data) {
// Append newsletter signup to sheet
sheet.appendRow([
new Date(),
'', // Full Name (empty for newsletter)
data.email,
'', // Phone
'', // City/Country
'', // Annual CTC
'', // Experience
'', // Industry
'', // College Tier
'', // Monthly Expenditure
'', // Dependents
'', // Spouse Earning
'', // Spouse Salary
'', // Premium
'', // Coverage
'', // Security Score
'Newsletter' // Type
]);
// Send email notification
MailApp.sendEmail({
to: 'rohitashgoyal509@gmail.com',
subject: '📧 New Newsletter Subscription - Vindex Protocol',
body: `New newsletter subscription received!\n\nEmail: ${data.email}\nTimestamp: ${new Date()}\n\nBest regards,\nVindex Protocol System`
});
}
function handleInsuranceQuote(sheet, data) {
// Append insurance quote to sheet
sheet.appendRow([
new Date(),
data.fullName || '',
data.email || '',
data.phone || '',
data.location || '', // City or Country
data.annualCTC || '',
data.experience || '',
data.industry || '',
data.collegeTier || '',
data.monthlyExpenditure || '',
data.dependents || '',
data.spouseEarning || '',
data.spouseSalary || '0',
data.calculatedPremium || '',
data.calculatedCoverage || '',
data.securityScore || '',
'Insurance Quote' // Type
]);
// Send detailed email notification
const emailBody = `
New Insurance Quote Request Received!
═══════════════════════════════════════
PERSONAL INFORMATION
═══════════════════════════════════════
Full Name: ${data.fullName}
Email: ${data.email}
Phone: ${data.phone}
Location: ${data.location}
═══════════════════════════════════════
PROFESSIONAL PROFILE
═══════════════════════════════════════
Annual CTC: ₹${data.annualCTC}
Experience: ${data.experience} years
Industry: ${data.industry}
College Tier: ${data.collegeTier}
═══════════════════════════════════════
FINANCIAL PROFILE
═══════════════════════════════════════
Monthly Expenditure: ₹${data.monthlyExpenditure}
Number of Dependents: ${data.dependents}
Spouse Earning: ${data.spouseEarning}
Spouse Salary: ₹${data.spouseSalary}
═══════════════════════════════════════
CALCULATED RESULTS
═══════════════════════════════════════
Monthly Premium: ₹${data.calculatedPremium}
Coverage Amount: ₹${data.calculatedCoverage}
Family Security Score: ${data.securityScore}/100
═══════════════════════════════════════
Timestamp: ${new Date()}
Action Required: Follow up with the lead within 24 hours.
Best regards,
Vindex Protocol System
`;
MailApp.sendEmail({
to: 'rohitashgoyal509@gmail.com',
subject: `🎯 New Insurance Quote - ${data.fullName} (₹${data.calculatedPremium}/mo)`,
body: emailBody
});
}
// Test function - you can run this to test the script
function testScript() {
const testData = {
postData: {
contents: JSON.stringify({
type: 'insurance_quote',
fullName: 'Test User',
email: 'test@example.com',
phone: '+91 9876543210',
location: 'Bangalore',
annualCTC: '1200000',
experience: '5',
industry: 'Technology',
collegeTier: 'Tier 1',
monthlyExpenditure: '50000',
dependents: '3',
spouseEarning: 'yes',
spouseSalary: '800000',
calculatedPremium: '3333',
calculatedCoverage: '600000',
securityScore: '85'
})
}
};
const result = doPost(testData);
Logger.log(result.getContent());
}