Notifly in MODX
In MODX Revolution everything is extended through plugins that “subscribe” to system events. Let’s hook important points to Notifly: resource creation, form submission (FormIt), registration, errors.
Helper snippet
Section titled “Helper snippet”Create a snippet notiflySend in the MODX manager:
<?php/* notiflySend(&$modx, string $title, string $message, int $priority = 5) */$url = $modx->getOption('notifly.url');$token = $modx->getOption('notifly.token');if (!$url || !$token) return '';
$body = json_encode([ 'title' => mb_substr($title, 0, 200), 'message' => mb_substr($message, 0, 1500), 'priority' => $priority,], JSON_UNESCAPED_UNICODE);
$ch = curl_init("$url/message?token=$token");curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => $body, CURLOPT_TIMEOUT => 5,]);curl_exec($ch);curl_close($ch);return '';In the “System → System Settings” section create two settings with keys notifly.url and notifly.token.
Plugin: new resource / edit
Section titled “Plugin: new resource / edit”Create a plugin NotiflyResource and bind it to the OnDocFormSave event:
<?php$action = $mode === modSystemEvent::MODE_NEW ? 'создан' : 'обновлён';$title = "📄 Ресурс $action: " . $resource->get('pagetitle');$msg = "ID: " . $resource->get('id') . "\n" . "URL: " . $modx->makeUrl($resource->get('id'), '', '', 'full') . "\n" . "Автор: " . $modx->user->get('username');
$modx->runSnippet('notiflySend', [ 'title' => $title, 'message' => $msg, 'priority' => 4,]);(in a real implementation it’s better to call notiflySend as a regular PHP function, but runSnippet is the simplest way).
FormIt: new submission notification
Section titled “FormIt: new submission notification”In the call to the FormIt snippet there is a &hooks parameter — add your hook notiflyForm:
[[!FormIt? &hooks=`email,notiflyForm,redirect` &emailTpl=`mailFormTpl` ...]]Snippet notiflyForm:
<?php$values = $hook->getValues();unset($values['spam-test']);
$lines = [];foreach ($values as $k => $v) { if (is_string($v)) $lines[] = "$k: $v";}
$modx->runSnippet('notiflySend', [ 'title' => "✉️ Заявка с сайта", 'message' => implode("\n", $lines), 'priority' => 7,]);return true;User registration
Section titled “User registration”Plugin NotiflyUser, event OnUserFormSave:
<?phpif ($mode !== modSystemEvent::MODE_NEW) return;
$modx->runSnippet('notiflySend', [ 'title' => "👤 Новый пользователь: " . $user->get('username'), 'message' => "Email: " . $user->Profile->get('email') . "\n" . "ID: " . $user->get('id'), 'priority' => 5,]);Site errors
Section titled “Site errors”Event OnPageNotFound:
<?php$modx->runSnippet('notiflySend', [ 'title' => "🚧 404: " . $_SERVER['REQUEST_URI'], 'message' => "Referer: " . ($_SERVER['HTTP_REFERER'] ?? '-') . "\n" . "UA: " . ($_SERVER['HTTP_USER_AGENT'] ?? '-'), 'priority' => 3,]);(throttling is mandatory — search bots will quickly fill the channel).
Throttling via cacheManager
Section titled “Throttling via cacheManager”$cache = $modx->cacheManager->getCacheProvider();$key = 'notifly_t_' . md5($title);if ($cache->get($key)) return true;$cache->set($key, 1, 60);Benefits
Section titled “Benefits”- MODX sites are often deployed on low-end VPS. Push at the moment of submission = a fast response to the client.
- Moderator oversight. Every resource change is an event.
- Quick SEO feedback. A stream of 404s → problematic links become visible.
What to improve next
Section titled “What to improve next”- Custom TV (Template Variable) with a
notifytag — send only if the author explicitly checked the box. - One common plugin using
match()on$modx->event->name— fewer duplicates.