|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +ModulePhoneBook is a MikoPBX extension module that provides caller ID management and contact storage. It integrates with Asterisk PBX for real-time caller identification on inbound and outbound calls. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +### JavaScript Compilation |
| 12 | +```bash |
| 13 | +docker run --rm -v /Users/nb/PhpstormProjects/mikopbx:/workspace ghcr.io/mikopbx/babel-compiler:latest /workspace/Extensions/[module]/public/assets/js/src/[file] extension` |
| 14 | +``` |
| 15 | + |
| 16 | +### PHP Syntax Check |
| 17 | +```bash |
| 18 | +php -l Lib/PhoneBookConf.php |
| 19 | +``` |
| 20 | + |
| 21 | +### Code Quality (PHPStan) |
| 22 | +Run phpstan after creating new PHP code to validate quality. |
| 23 | + |
| 24 | +### Dependencies |
| 25 | +```bash |
| 26 | +composer install |
| 27 | +``` |
| 28 | + |
| 29 | +## Architecture |
| 30 | + |
| 31 | +### Directory Structure |
| 32 | +- `App/Controllers/` - Phalcon MVC controllers (ModulePhoneBookController) |
| 33 | +- `App/Forms/` - Phalcon form definitions |
| 34 | +- `Lib/` - Core business logic |
| 35 | + - `PhoneBookConf.php` - PBX integration, REST API callbacks, Asterisk dialplan generation |
| 36 | + - `PhoneBookAgi.php` - Asterisk AGI handler for real-time caller ID lookup |
| 37 | + - `PhoneBookImport.php` - Excel import processor using PhpSpreadsheet |
| 38 | + - `MikoPBXVersion.php` - Version compatibility helpers |
| 39 | +- `Models/` - Phalcon ORM models (PhoneBook, Settings) |
| 40 | +- `Setup/` - Module installation logic (PbxExtensionSetup) |
| 41 | +- `agi-bin/` - Asterisk AGI scripts |
| 42 | +- `Messages/` - i18n translation files (26 languages) |
| 43 | +- `public/assets/js/src/` - Source JavaScript files (ES6) |
| 44 | +- `public/assets/js/` - Compiled JavaScript files |
| 45 | + |
| 46 | +### Data Flow |
| 47 | +1. **Inbound calls**: Asterisk dialplan → `agi_phone_book.php` → `PhoneBookAgi::setCallerId('in')` → Sets CALLERID(name) |
| 48 | +2. **Outbound calls**: CONNECTED_LINE_SEND_SUB → `PhoneBookAgi::setCallerId('out')` → Sets CONNECTEDLINE(name) |
| 49 | +3. **Web UI**: DataTable with server-side processing via AJAX to `ModulePhoneBookController::getNewRecordsAction()` |
| 50 | +
|
| 51 | +### Phone Number Storage Format |
| 52 | +Numbers are normalized for consistent storage and fast lookups: |
| 53 | +- Strip all non-digit characters |
| 54 | +- Keep last 9 digits only |
| 55 | +- Prepend "1" |
| 56 | +- Example: `+7 (906) 555-43-43` → `1065554343` |
| 57 | +
|
| 58 | +### Database |
| 59 | +SQLite database at runtime: `/storage/usbdisk1/mikopbx/custom_modules/ModulePhoneBook/db/module.db` |
| 60 | +
|
| 61 | +Tables: |
| 62 | +- `m_PhoneBook` - contacts (id, number, number_rep, call_id, search_index) |
| 63 | +- `m_ModulePhoneBook` - settings (disableInputMask) |
| 64 | +
|
| 65 | +### Key Integration Points |
| 66 | +- `PhoneBookConf::moduleRestAPICallback()` - REST API entry point for Excel import |
| 67 | +- `PhoneBookConf::generateIncomingRoutBeforeDial()` - Injects AGI into inbound routes |
| 68 | +- `PhoneBookConf::generateOutRoutContext()` - Injects connected line handling for outbound |
| 69 | +- `PhoneBookConf::extensionGenContexts()` - Generates `[phone-book-out]` Asterisk context |
| 70 | +
|
| 71 | +### Frontend |
| 72 | +- Uses Semantic UI components and DataTables |
| 73 | +- Input masking for phone numbers (toggleable via settings) |
| 74 | +- State persistence in localStorage for page length and search |
| 75 | +- Files in `public/assets/js/src/` must be compiled with Babel to `public/assets/js/` |
| 76 | +
|
| 77 | +## Module Configuration |
| 78 | +
|
| 79 | +`module.json` defines module metadata including: |
| 80 | +- `moduleUniqueID`: "ModulePhoneBook" |
| 81 | +- `min_pbx_version`: "2024.1.114" |
| 82 | +
|
| 83 | +## CI/CD |
| 84 | +
|
| 85 | +GitHub Actions workflow (`.github/workflows/build.yml`) uses shared MikoPBX workflow for building and publishing releases. |
0 commit comments