The command exited with code 0. Output: 4119: session.eidNumber = data.data.eidNumber; 4120: session.retrievedName = data.data.name; 4121: await saveSearchRecord(userId, 'DOWNLOAD_PDF', session.retrievedName, session.mobile, session.eidNumber, null, null, null); 4122: ctx.reply(`šŸŽ‰ *Aadhaar Details Located!*\n\nšŸ‘¤ *Name* : \`${session.retrievedName}\`\nšŸ“‘ *EID* : \`${session.eidNumber}\`\n\n*Would you like to securely download the password-free Aadhaar PDF?*`, { 4123: parse_mode: 'Markdown', 4124: ...Markup.inlineKeyboard([ 4125: [{ text: toSansBold('Secure Download PDF'), callback_data: 'CONTINUE_PDF', style: 'success' }] 4126: ]) 4127: }); 4128: } 4129: } else { 4130: if (session.otpLoaderId) { 4131: ctx.telegram.deleteMessage(userId, session.otpLoaderId).catch(() => { }); 4132: } 4133: ctx.reply(`āŒ *Verification failed. Please check the OTP and try again.*`, { parse_mode: 'Markdown' }); 4134: session.step = 'FINISHED'; 4135: } 4136: } catch (error) { 4137: console.error(error); 4138: ctx.reply('āŒ *A temporary error occurred while submitting OTP.*', { parse_mode: 'Markdown' }); 4139: } 4140: return; 4141: } 4142: 4143: if (session.step === 'WAITING_FOR_PDF_OTP') { 4144: session.otpValue = text; 4145: const pLdr = await ctx.reply('ā³ Downloading PDF... Please wait.', { parse_mode: 'HTML' }); 4146: session.pdfLoaderId = pLdr.message_id; 4147: 4148: try { 4149: const finalReqBody = { 4150: eid: session.eidNumber, 4151: otp: session.otpValue, 4152: otpTxnId: session.otpTxnId, 4153: name: session.retrievedName, 4154: dob: session.dob 4155: }; 4156: 4157: const finalResponse = await callApi('/eid-to-adhar/verifyotp', { 4158: method: 'POST', 4159: body: JSON.stringify(finalReqBody) 4160: }); 4161: 4162: const rawText = await finalResponse.text(); 4163: try { 4164: const data = JSON.parse(rawText); 4165: let rawPdfBuffer = null; 4166: 4167: if (data.status === "success" && data.pdfBase64) { 4168: rawPdfBuffer = Buffer.from(data.pdfBase64, 'base64'); 4169: } 4170: 4171: if (rawPdfBuffer) { 4172: let foundPassword = data.pdfPassword || data.pdfPasswordUsed || null; 4173: let extractedText = ""; 4174: 4175: try { 4176: const pdfjsLib = await import('file://' + require('path').resolve('node_modules/pdfjs-dist/legacy/build/pdf.mjs').replace(/\\/g, '/')); 4177: const doc = await pdfjsLib.getDocument({ 4178: data: new Uint8Array(rawPdfBuffer) 4179: }).promise; 4180: 4181: const page = await doc.getPage(1); 4182: const textContent = await page.getTextContent(); 4183: extractedText = textContent.items.map(i => i.str).join(' '); 4184: } catch (e) { 4185: console.error("Failed to extract text:", e); 4186: } 4187: 4188: // Cleanly delete the downloading loader right before sending the final PDF document! 4189: if (session.pdfLoaderId) { 4190: ctx.telegram.deleteMessage(ctx.chat.id, session.pdfLoaderId).catch(() => { }); 4191: session.pdfLoaderId = null; 4192: } 4193: 4194: let finalPdfBuffer = rawPdfBuffer; 4195: 4196: const access = await checkUserAccess(userId); 4197: let leftCredits = access.credits; 4198: const cost = session.serviceType === 'EID_TO_PDF' ? 100 : 120; 4199: if (!access.isUnlimited) { 4200: leftCredits = await deductUserCredit(userId, cost); 4201: } else { 4202: setCooldown(userId, session.serviceType); 4203: } 4204: 4205: let msg = `šŸ’³ ─── AADHAAR RETRIEVED ─── šŸ’³\n\n`; 4206: msg += `šŸ‘¤ Name : ${session.retrievedName.toUpperCase()}\n`; 4207: 4208: const dobStr = session.dob || 'N/A'; 4209: msg += `šŸŽ‚ DOB : ${dobStr}\n`; 4210: 4211: let finalAadhaar = 'N/A'; 4212: const aadhaarMatch = extractedText.match(/\b\d{4}\s?\d{4}\s?\d{4}\b/g); 4213: if (aadhaarMatch) { 4214: finalAadhaar = aadhaarMatch[0]; 4215: } 4216: msg += `šŸ†” Aadhaar No : ${finalAadhaar}\n`; 4217: 4218: const passVal = foundPassword ? foundPassword : 'Protected (Locked)'; 4219: msg += `šŸ”‘ Password : ${passVal}\n\n`; 4220: 4221: msg += `
šŸŖ™ Deducted: ${access.isUnlimited ? '0 (Unlimited Plan)' : cost + ' Credits'}\nšŸŖ™ Remaining Balance: ${access.isUnlimited ? 'Unlimited' : leftCredits + ' Credits'}
\n\n`; 4222: msg += `⚔ Powered by MayaX Aadhar ⚔\nšŸ¤– @MayaXAdharbot`; 4223: 4224: await ctx.replyWithDocument({ source: finalPdfBuffer, filename: `${session.retrievedName}_Aadhaar.pdf` }, { caption: msg, parse_mode: 'HTML' }); 4225: await saveSearchRecord(userId, session.serviceType, session.retrievedName, session.mobile, session.eidNumber, finalAadhaar, foundPassword, finalPdfBuffer); 4226: } else { 4227: if (session.pdfLoaderId) { 4228: ctx.telegram.deleteMessage(ctx.chat.id, session.pdfLoaderId).catch(() => { }); 4229: session.pdfLoaderId = null; 4230: } 4231: ctx.reply(`āŒ Could not retrieve PDF data. Please try again later.`, { parse_mode: 'HTML' }); 4232: } 4233: } catch (e) { 4234: console.error("Error:", e); 4235: if (session.pdfLoaderId) { 4236: ctx.telegram.deleteMessage(ctx.chat.id, session.pdfLoaderId).catch(() => { }); 4237: session.pdfLoaderId = null; 4238: } 4239: // If it's not JSON, it might be the raw PDF bytes 4240: if (rawText.startsWith('%PDF')) { 4241: const pdfBuffer = Buffer.from(rawText, 'binary'); 4242: const access = await checkUserAccess(userId); 4243: let leftCredits = access.credits; 4244: const cost = session.serviceType === 'EID_TO_PDF' ? 100 : 120; 4245: if (!access.isUnlimited) { 4246: leftCredits = await deductUserCredit(userId, cost); 4247: } else { 4248: setCooldown(userId, session.serviceType); 4249: } 4250: await ctx.replyWithDocument({ source: pdfBuffer, filename: `${session.retrievedName}_Aadhaar.pdf` }); The above content does NOT show the entire file contents. If you need to view any lines of the file which were not shown to complete your task, call this tool again to view those lines.