const SHEET_ID = "https://docs.google.com/spreadsheets/d/1aoluIKqswTdw8golQL92AfESSK7xS5ct68StrIgLyyo/edit?gid=489690397#gid=489690397"; const DRIVE_FOLDER_ID = "18o8RC4AnIhNd2_XwQADndINiNxR3pud2"; function doPost(e) { try { const data = JSON.parse(e.postData.contents); const ss = SpreadsheetApp.openById(SHEET_ID); // 1. SEND OTP VIA BULKSMSPLANS + EMAIL if (data.action === "send_bank_form_otp") { const otp = Math.floor(100000 + Math.random() * 900000).toString(); const otpSheet = ss.getSheetByName("OTP_Logs"); otpSheet.appendRow([new Date(), data.email, data.mobile, otp, "Pending"]); // BulkSMSPlans DLT API Call (Exact template spacing preserved) const smsMessage = "Your Verification OTP is " + otp + ". For latest job updates kindly visit- https://www.friendsjob.in. Thank you. Team Friendsjob (Bestconcern Services)"; const smsPayload = { "api_id": "APIr4Xpug7R6123", "api_password": "9910425835", "sms_type": "Transactional", "sms_encoding": "text", "sender": "BCSPLF", "number": data.mobile, "message": smsMessage, "template_id": "1777178661951106091" }; UrlFetchApp.fetch("https://bulksmsplans.com/api/send_sms", { "method": "post", "contentType": "application/json", "payload": JSON.stringify(smsPayload), "muteHttpExceptions": true }); // Optional: Email par bhi OTP bhejne ke liye if (data.email) { MailApp.sendEmail({ to: data.email, subject: "Verification OTP - Bestconcern Services", body: smsMessage }); } return ContentService.createTextOutput(JSON.stringify({ success: true })) .setMimeType(ContentService.MimeType.JSON); } // 2. VERIFY OTP & SAVE DATA + PASSBOOK if (data.action === "verify_and_submit") { const otpSheet = ss.getSheetByName("OTP_Logs"); const rows = otpSheet.getDataRange().getValues(); let isValid = false; for (let i = rows.length - 1; i >= 1; i--) { if (String(rows[i][2]) === String(data.mobile) && String(rows[i][3]) === String(data.otp) && rows[i][4] === "Pending") { otpSheet.getRange(i + 1, 5).setValue("Verified"); isValid = true; break; } } if (!isValid) { return ContentService.createTextOutput(JSON.stringify({ success: false, message: "Invalid OTP. Please enter correct 6-digit OTP." })) .setMimeType(ContentService.MimeType.JSON); } // Passbook file Google Drive mein save karein let fileUrl = ""; if (data.fileData && data.fileName) { const blob = Utilities.newBlob(Utilities.base64Decode(data.fileData), data.fileMimeType, data.empCode + "_" + data.fileName); const folder = DriveApp.getFolderById(DRIVE_FOLDER_ID); const file = folder.createFile(blob); fileUrl = file.getUrl(); } // Submissions sheet mein row add karein const subSheet = ss.getSheetByName("Submissions"); subSheet.appendRow([ new Date(), data.empCode, data.fullName, data.jobTitle, data.workLocation, data.email, data.mobile, data.accHolder, "'" + data.accNumber, data.ifsc, data.remark, "Verified", fileUrl ]); return ContentService.createTextOutput(JSON.stringify({ success: true })) .setMimeType(ContentService.MimeType.JSON); } } catch (err) { return ContentService.createTextOutput(JSON.stringify({ success: false, message: err.toString() })) .setMimeType(ContentService.MimeType.JSON); } }