Генерация и доработка модулей MikoPBX. Создание новых модулей по описанию на естественном языке, добавление функциональности в существующие модули, оптимизация и унификация кода модулей. Использовать когда пользователь хочет создать новый модуль, добавить фичу в модуль, оптимизировать модуль или узнать как устроена система модулей.
Создание, доработка и оптимизация модулей для MikoPBX 2025.1.1+.
PHP: 8.3
min_pbx_version: 2025.1.1
Framework: Phalcon 5.8
NO legacy compatibility (no MikoPBXVersion.php)
Parse user's natural language description and determine:
ModuleXxxYyy following MikoPBX conventionsExtensions/ — for production modulesExtensions/EXAMPLES/{Category}/ — for example/learning modules| Recipe | Trigger words / signals |
|---|---|
| base (always) | — |
| ui | "настройки", "страница", "форма", "интерфейс", "settings", "page", "UI" |
| rest-api | "API", "REST", "эндпоинт", "endpoint", "CRUD" |
| dialplan | "звонки", "маршрут", "IVR", "входящие", "исходящие", "calls", "routing" |
| agi | "AGI", "скрипт", "lookup", "CallerID", "перед набором" |
| workers | "фоновый", "воркер", "очередь", "события", "background", "worker", "queue", "events" |
| firewall | "порт", "фаервол", "fail2ban", "безопасность", "firewall", "port" |
| acl | "доступ", "права", "роли", "ACL", "permissions", "roles" |
| system | "cron", "nginx", "периодический", "запуск", "scheduled" |
Ask many questions! It's better to clarify intent than to guess wrong. Examples:
Generate files using reference templates in templates/ directory. For each recipe, create the corresponding files.
File generation order:
module.json — module metadataSetup/PbxExtensionSetup.php — installerModels/*.php — database modelsLib/{Name}Conf.php — configuration class with hooksLib/{Name}Main.php — business logic (if needed)App/Controllers/ — web controllers (if ui recipe)App/Forms/ — Phalcon forms (if ui recipe)App/Views/ — Volt templates (if ui recipe)App/Providers/ — Asset and Menu providers (if ui recipe)public/assets/js/src/ — ES6+ JavaScript (if ui recipe)public/assets/css/ — CSS styles (if ui recipe)Lib/RestAPI/ — REST API controllers and actions (if rest-api recipe)bin/ — Worker scripts (if workers recipe)agi-bin/ — AGI scripts (if agi recipe)Messages/ — Translation files (call /translations skill)Code references: When generating code, study existing EXAMPLES for patterns:
Extensions/EXAMPLES/REST-API/ModuleExampleRestAPIv3/Extensions/EXAMPLES/WebInterface/ModuleExampleForm/Extensions/EXAMPLES/AMI/ModuleExampleAmi/Extensions/EXAMPLES/REST-API/ModuleExampleRestAPIv{1,2}/Read the actual source code from these examples before generating — they are the canonical reference.
After generating all files, run:
# 1. PHP syntax check on all generated PHP files
find {module_dir} -name "*.php" -exec php -l {} \;
# 2. Babel transpilation for JS files (if ui recipe)
# Use /babel-compiler skill
# 3. module.json validation
php -r "json_decode(file_get_contents('{module_dir}/module.json'), true) ?: exit(1);"
Report results and suggest fixes for any issues found.
Module: ModuleBlackList
Location: Extensions/ModuleBlackList/
Recipes: base, ui, rest-api, dialplan, agi
Files created:
Setup/PbxExtensionSetup.php
Lib/BlackListConf.php
Lib/BlackListMain.php
Models/BlackListNumbers.php
App/Controllers/ModuleBlackListController.php
App/Forms/ModuleBlackListForm.php
App/Views/ModuleBlackList/index.volt
App/Providers/AssetProvider.php
App/Providers/MenuProvider.php
public/assets/js/src/module-black-list.js
public/assets/css/module-black-list.css
Lib/RestAPI/Numbers/Controller.php
Lib/RestAPI/Numbers/Processor.php
Lib/RestAPI/Numbers/DataStructure.php
Lib/RestAPI/Numbers/Actions/GetListAction.php
...
agi-bin/check-blacklist.php
Messages/ru.php (+ 28 languages via /translations)
module.json
Checks:
PHP syntax: PASS (18/18 files)
Babel: PASS
module.json: VALID
Next steps:
1. Review generated code
2. Install module in MikoPBX
3. Test functionality
4. Customize business logic
Based on user request, determine:
Apply changes following the same patterns as Mode 1. When modifying Conf.php, add new hook methods without breaking existing ones.
Run anti-pattern checker and suggest improvements.
Analyze module code against best practices:
// Typed properties (for non-model classes: Conf, Main, Worker, etc.)
public string $name = '';
public readonly string $moduleUniqueId;
// Constructor promotion
public function __construct(
private readonly string $moduleUniqueId,
) {}
// Match expressions
$result = match($action) {
'check' => $this->check(),
'reload' => $this->reload(),
default => throw new \InvalidArgumentException("Unknown action: $action"),
};
// Named arguments
PBX::dialplanReload(timeout: 30);
// Enums where appropriate
enum CallDirection: string {
case Incoming = 'incoming';
case Outgoing = 'outgoing';
}
Model column properties follow Phalcon/SQLite conventions — do NOT apply PHP 8.3 typed properties rules here:
// Primary key — ALWAYS untyped
public $id;
// String columns — nullable with string default
public ?string $name = '';
// Integer columns stored as string in SQLite
public ?string $enabled = '0';
// Integer foreign keys — nullable int
public ?int $userid = null;
This pattern matches core models in src/Common/Models/. See Extensions.php, Sip.php, CallQueues.php for reference.
// CORRECT
use Phalcon\Di\Di;
// WRONG - will cause errors
use Phalcon\Di;
| Entity | Pattern | Example |
|---|---|---|
| Module ID | Module{Feature} | ModuleBlackList |
| Namespace | Modules\{ModuleID}\... | Modules\ModuleBlackList\Lib |
| Config class | {Feature}Conf | BlackListConf |
| Main class | {Feature}Main | BlackListMain |
| Model | {Entity} | BlackListNumbers |
| DB table | m_{Entity} | m_BlackListNumbers |
| Controller | Module{Feature}Controller | ModuleBlackListController |
| Worker | Worker{Feature}{Type} | WorkerBlackListAMI |
| JS file | module-{kebab-case} | module-black-list.js |
| CSS file | module-{kebab-case} | module-black-list.css |
| Translation prefix | module_{feature}_ | module_black_list_ |
| Sidebar group | modules or integrations | — |
All PHP files must start with:
<?php
declare(strict_types=1);
No closing ?> tag.
See recipes.md for detailed recipe specifications.
See hook-reference.md for complete list of 60+ hooks with signatures and examples.
See anti-patterns.md for common mistakes to detect and fix.
See templates/ directory for code generation templates.
After generating PHP code, invoke the /translations skill to create Messages files for all 29 languages.
Workflow:
Messages/ru.php)/translations skill to translate to remaining 28 languages/Users/nb/PhpstormProjects/mikopbx/Extensions//Users/nb/PhpstormProjects/mikopbx/Extensions/EXAMPLES//Users/nb/PhpstormProjects/mikopbx/Core/src/Modules//Users/nb/PhpstormProjects/mikopbx/Core/src/Core/Asterisk/Configs/This skill activates when you say: