Agency CRM Full System Documentation

Agency CRM lead generation, email outreach, reply tracking, meeting automation, AI email coordination, landing page, login, and profile settings ka complete system hai.

Node.js + Express Login Protected CRM Encrypted Profile Settings Apollo + LeadGorilla OpenAI Email AI Mobile Responsive

Table of Contents

1. Overview

Backend server.js Express par run hota hai, frontend index.html, css/style.css, aur js/app.js se browser mein chalta hai. Data JSON files mein store hota hai.

System public landing page show karta hai. Dashboard access sirf login ke baad milta hai. Default login pehli dafa admin / admin123 hai, jise Profile Settings se change karna chahiye.

Latest system mobile responsive hai: dashboard, pipeline, tables, settings, modals aur landing page mobile par adjust hote hain.

2. Features

Landing Page + Login

Public landing page modules show karta hai. Dashboard login ke baghair hidden rehta hai.

Profile Settings

Portal name, slogan, logo, super admin ID/password aur API settings manage hoti hain.

Encrypted API Settings

Apollo, LeadGorilla, OpenAI, Gmail, SMTP, IMAP values encrypted portal_secrets.json mein save hoti hain.

Apollo Fetch

Job title, country, company size aur keywords ke base par Apollo API se leads fetch hoti hain.

LinkedIn Intent Leads

Marketing agency, SEO, website, ads related post intent se leads create karne ka module available hai.

LeadGorilla

Business/local lead search ke liye LeadGorilla API integration ready hai.

CSV Import / Export

Leads CSV se import aur export ho sakti hain.

Manual Lead Add

Name, email, phone, website, company, source, service aur requirements/comments ke sath lead add hoti hai.

Pipeline

Stages: New Lead, Contacted, Replied, Meeting, Proposal, Won. Forward/backward stage movement available hai.

Meeting Calendar

Meeting stage mein schedule/reschedule button se manual date/time set kar sakte hain.

OpenAI Coordination

AI client reply samajh kar email draft, intent aur next action suggest/send kar sakta hai.

Fallback Safe

OpenAI fail ho to old template/keyword system automatically chalta rehta hai.

3. Lead Workflow

  1. Lead Apollo, LinkedIn, LeadGorilla, CSV import ya manual form se system mein aati hai.
  2. Duplicate email/API id check hota hai.
  3. Lead New Lead stage mein save hoti hai.
  4. Profile setting First Email Auto Send on ho to first email background mein send hoti hai.
  5. Profile mein OpenAI Automation on ho to email personalized draft hoti hai; off/fail ho to normal saved template email send hoti hai.
  6. Email send hone par lead Contacted stage mein move hoti hai.
  7. Client reply kare to IMAP reply processor reply timeline mein save karta hai.
  8. OpenAI reply intent samajhta hai; fallback keyword logic bhi active rehta hai.
  9. Meeting intent ho to lead Meeting stage mein jati hai. Requested time free ho to unique meeting link generate hota hai.
  10. Requested meeting time already booked ho to client ko multiple available time options email hoti hain. Client option select/done/confirmed reply kare to meeting link generate hota hai.
  11. Pricing/proposal reply ho to lead Proposal stage mein jati hai.
  12. Proposal sent hone ke baad client go ahead/onboarding/approved type reply kare to lead Won stage mein move hoti hai.
  13. Non-meeting replies par AI draft timeline mein save hoti hai; optional auto-send setting bhi available hai.

4. Profile Settings

Profile Settings dashboard ke sidebar mein available hai. Is section mein portal branding, login credentials aur encrypted integrations manage hoti hain.

SectionFieldsNotes
Portal ProfilePortal Name, Slogan, Logo Text, Logo URLLanding page, sidebar aur browser title update hota hai.
Super Admin LoginAdmin ID, current password, new passwordPassword change ke liye current password required hai.
Lead APIsApollo, LeadGorilla, PhantomBusterSecret values masked hoti hain; blank chorne se old value keep rehti hai.
AI AutomationOpenAI On/Off, OpenAI API Key, OpenAI Model, AI Auto Send RepliesOpenAI key encrypted save hoti hai. Off mode mein normal templates chalte rehte hain.
EmailGmail, custom SMTP, TLS settings, From/Reply-ToGmail ya company SMTP dono supported hain.
RepliesIMAP host, port, user, passClient replies read karne ke liye.
AutomationFirst Email Auto Send, cron, daily limit, delayFirst email on/off yahin se control hoti hai.
MeetingsMeeting base URLUnique meeting links ke liye.
Encrypted files portal_secrets.json aur portal_secret.key ko server par safe rakhna hai. portal_secret.key delete ho gaya to old encrypted values decrypt nahi hongi.

5. OpenAI Automation

OpenAI integration emails ko client context aur reply ke mutabiq coordinate karta hai.

SettingRecommendedPurpose
OPENAI_API_KEYYour keyOpenAI API access.
OPENAI_MODELgpt-5.4-miniEmail drafting and reply classification.
AI_EMAIL_AUTOMATIONtrue or Profile toggle OnOn par first/follow-up emails AI personalize karega. Off par normal saved templates use honge.
AI_AUTO_SEND_REPLIESfalseFalse par AI draft banata hai; true par non-meeting replies auto-send kar sakta hai.

AI Flow

Safe mode ke liye AI_AUTO_SEND_REPLIES=false rakhein. Is mode mein AI sirf draft banayega, email aap button se send karenge.

6. Email System

Gmail SMTP blocked/proxy ho to company SMTP use karein: EMAIL_PROVIDER=smtp, SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS.
Certificate mismatch aaye to hosting SMTP settings check karein. Temporary bypass SMTP_TLS_REJECT_UNAUTHORIZED=false hai, lekin production mein valid certificate better hai.

7. Reply + Meeting Automation

Reply processor IMAP inbox se replies read karta hai, lead email se match karta hai, aur timeline mein body/subject/from/date save karta hai.

Reply IntentSystem Action
Meeting, call, schedule, availableStage Meeting, requested time parse, conflict check. Free slot par meeting link + confirmation email.
Same time already bookedClient ko multiple available slots email. Link tabhi send hota hai jab client option select/done/confirmed reply kare.
RescheduleStage Meeting, pending/manual schedule option.
Pricing/proposalStage Proposal, proposal dropdown se PDF send.
Proposal approved/go ahead/onboardingStage Won, sent proposal PDF timeline/card se view ho sakti hai.
Question/interestedStage Replied, AI draft can be created.
Unsubscribe/not interestedLead unsubscribed, follow-up stops.

Meeting stage mein pipeline card par confirmed meeting time/link show hota hai. Pending multiple time options ke liye timeline mein reschedule proposal record save hota hai.

8. API Routes

RouteMethodPurpose
/api/public-settingsGETLanding/login branding.
/api/auth/loginPOSTSuper admin login.
/api/auth/logoutPOSTLogout session.
/api/settingsGET/PUTPortal profile and login settings.
/api/settings/secretsGET/PUTEncrypted API/SMTP/OpenAI settings.
/api/statusGETServer, Apollo, SMTP, schedulers, reply poller status.
/api/leadsGET/POSTList/add leads.
/api/leads/:idPUT/DELETEUpdate/delete one lead.
/api/leads/import-csvPOSTCSV leads import.
/api/leads/:id/send-emailPOSTSelected lead ko next email send.
/api/leads/:id/ai-draftPOSTLatest client reply ke mutabiq AI draft create.
/api/leads/:id/send-ai-draftPOSTSaved AI draft send.
/api/leads/:id/schedule-meetingPOSTManual meeting schedule/reschedule.
/api/apollo/fetchPOSTApollo leads fetch.
/api/linkedin/scrapePOSTLinkedIn intent leads.
/api/leadgorilla/searchPOSTLeadGorilla search.
/api/sources/runPOSTAll lead sources run.
/api/replies/runPOSTReplies manually sync.
/api/templatesGET/PUTEmail templates load/save.

9. Deployment

npm install
node server.js

Production mein PM2 recommended hai:

npm install -g pm2
pm2 start server.js --name agency-crm
pm2 save

10. Troubleshooting

IssueReasonSolution
Cannot POST /api/auth/loginOld server process running.Latest files upload karein aur node server.js/PM2 restart karein.
OpenAI email nahi ban rahiOpenAI toggle off, key/model/quota/network issue.Profile > AI Automation mein toggle/key check karein. Off/fail ho to normal template email automatically send hoti rahegi.
First email nahi jatiFirst Email Auto Send off, email missing, SMTP issue.Profile Automation mein setting on karein, SMTP verify karein.
Apollo errorAPI key missing/invalid.Profile Lead APIs mein Apollo key save karein.
Email certificate mismatchHosting SMTP proxy/cert mismatch.Company SMTP host use karein ya hosting support se outbound Gmail SMTP allow karwayen.
Replies update nahi hotiIMAP missing/wrong, reply from different email.Profile Replies settings check karein aur Sync Replies run karein.
Meeting conflict ignoredOld process or missing booked meeting times.Server restart karein, existing leads mein meetingAtIso records check karein.
Conflict par direct link chali gaiOld code running.Latest replyProcessor.js upload karke Node/PM2 restart karein. New flow pehle alternate time approval email bhejta hai.

11. Important Files

index.html

Landing, login, dashboard layout and tab containers.

css/style.css

Responsive styling for landing, dashboard, tables, pipeline and modals.

js/app.js

Frontend API calls, rendering, settings UI, AI draft buttons, modals.

server.js

Express API, auth, settings, routes, source/email/reply startup.

openaiService.js

OpenAI Responses API wrapper, email draft and reply intent logic.

emailService.js

Gmail/custom SMTP transporter and send email logic.

emailScheduler.js

Scheduled follow-up batch emails with AI fallback.

replyProcessor.js

IMAP reply sync, AI reply analysis, meeting automation.

leads_data.json

Lead database.

templates_custom.json

Editable email templates.

portal_settings.json

Portal branding and login settings.

portal_secrets.json + portal_secret.key

Encrypted API/SMTP/OpenAI settings and encryption key.

12. Notes