Kazak automation backend
- HTML 71.1%
- JavaScript 28.9%
| dockerizer | ||
| references | ||
| requirements_from_the_customer | ||
| scripts | ||
| src | ||
| test-results | ||
| .dockerignore | ||
| .env.example | ||
| .gitignore | ||
| AGENTS.md | ||
| deploy.js | ||
| KOMMO_SETUP.md | ||
| OUT_OF_SCOPE.md | ||
| package-lock.json | ||
| package.json | ||
| previoud webhook URL.txt | ||
| README.md | ||
| SPEC.md | ||
| todo.md | ||
Kazak Automatizaciones Backend
Backend automation service for Kazak Consultores - Commercial Diagnosis workflow. Receives form submissions from Elementor, integrates with Kommo CRM and OpenAI, and manages leads through 3 pricing tiers (Free, $500, $1000).
Production URL:
https://kazak.in2.altocontrastemexico.com/.
The former Banawork hostname forwards to production for the Google Apps Script
webhook proxy. Deploy with npm run deploy.
Port is 3457, note we would need to change it in 2 places, the .env (if on easypanel it's changed on the .env interface, or if disabled on the file like usual) and the dockerizer/Dockerfile
Quick Start
# Install dependencies
npm install
# Copy environment template and fill in credentials
cp .env.example .env
# Start development server (with auto-reload)
npm run dev
# Start production server
npm start
Webhook URL
After starting the server, your webhook URL for Elementor is:
http://your-domain:3000/webhook/elementor
Or locally:
http://localhost:3000/webhook/elementor
Environment Variables
Create a .env file with:
# Server
PORT=3000
# PostgreSQL Database
DATABASE_URL=postgresql://user:password@host:port/database
# Kommo CRM (Long-lived access token)
KOMMO_SUBDOMAIN=your-subdomain
KOMMO_ACCESS_TOKEN=your-token
# OpenAI
OPENAI_API_KEY=sk-your-key
API Endpoints
Webhook
| Method | Endpoint | Description |
|---|---|---|
| POST | /webhook/elementor |
Receive Elementor form submissions |
| GET | /webhook/test |
Test webhook route |
Admin
| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/logs |
View application logs |
| GET | /admin/logs/errors |
View error logs only |
| GET | /admin/db/init |
Initialize database tables |
| GET | /admin/db/status |
Check database status |
| GET | /admin/webhook-logs |
View stored webhook logs |
| GET | /admin/leads |
View processed leads |
| GET | /admin/gpt-outputs |
View GPT outputs |
| GET | /admin/kommo/fields |
View Kommo lead/contact fields |
| GET | /admin/kommo/pipelines |
View Kommo pipelines and stages |
| GET | /admin/kommo/tags |
View Kommo tags |
| GET | /admin/kommo/test |
Test Kommo API connection |
Project Structure
├── src/
│ ├── index.js # Express app entry point
│ ├── config/
│ │ ├── database.js # PostgreSQL connection
│ │ └── db-init.js # Database schema
│ ├── routes/
│ │ ├── webhook.js # Webhook handlers
│ │ └── admin.js # Admin dashboard
│ ├── services/
│ │ ├── kommoService.js # Kommo CRM API client
│ │ ├── gptService.js # OpenAI integration
│ │ └── leadProcessor.js # Lead processing workflow
│ ├── prompts/
│ │ ├── PROMPT_GRATIS.md # Free tier prompt
│ │ ├── PROMPT_500.md # $500 tier prompt
│ │ └── PROMPT_1000.md # $1000 tier prompt
│ └── utils/
│ └── logger.js # Custom file logger
├── logs/ # Log files
├── .env.example # Environment template
└── package.json
Processing Flow
- Webhook Reception: Elementor form submits to
/webhook/elementor - Logging: Raw payload logged to database and files
- Option Detection: System detects Free/$500/$1000 based on form response
- Kommo Integration: Creates/updates contact and lead in CRM
- GPT Diagnosis: Generates diagnosis using appropriate prompt
- Task Creation: Creates follow-up tasks in Kommo if needed
First-Time Setup
- Start the server:
npm run dev - Visit
http://localhost:3000/to see available endpoints - Set up database: Visit
/admin/db/init - Check Kommo connection: Visit
/admin/kommo/account - Send a test webhook to
/webhook/elementor - View webhook logs:
/admin/webhook-logs
Notes
- Logs are stored in
logs/directory - Master prompts in
src/prompts/are placeholders - replace with final versions - See
OUT_OF_SCOPE.mdfor features that need additional implementation - The wordpress form cannot connect to our VPS so it sends the webhook to https://script.google.com/macros/s/AKfycbzZTV753s5EeSMuipbPed5taUHv8b2Xb5_qwP3pMac9sW8O56hiI2siXlqOOcCL5Mqc/exec and that script forwards it to our
/webhook/elementorendpoint