/** * @param DispatcherContract $events */ public function boot(DispatcherContract $events) { if (false === config('slack.endpoint', false)) { return; } $this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'slack'); /** * To get the actual changes we need to record the * changes before the Cachet event is fired. */ Incident::updating(function (Incident $incident) { $dirty = []; foreach ($incident->getDirty() as $key => $v) { $dirty[$key] = $incident->getOriginal($key); } self::registerChanges('incident', $dirty); }); Component::updating(function (Component $component) { $dirty = []; foreach ($component->getDirty() as $key => $v) { $dirty[$key] = $component->getOriginal($key); } self::registerChanges('component', $dirty); }); /** * Send Slack notification on new incidents. */ $events->listen('CachetHQ\\Cachet\\Bus\\Events\\Incident\\IncidentWasReportedEvent', function (IncidentWasReportedEvent $event) { $handler = new IncidentWasReportedHandler($event->incident->status, $event->incident->name, $event->incident->message, $event->incident['component_id']); return $handler->send(); }); /** * Send Slack notification on incident updates. */ $events->listen('CachetHQ\\Cachet\\Bus\\Events\\Incident\\IncidentWasUpdatedEvent', function (IncidentWasUpdatedEvent $event) { $handler = new IncidentWasUpdatedHandler($event->incident->id, $event->incident->status, $event->incident->name, $event->incident->message, $event->incident['component_id'], self::getChanges('incident')); return $handler->send(); }); /** * Send Slack notification on component updates. * Note these are not send when a component is updated as part of an incident update. */ $events->listen('CachetHQ\\Cachet\\Bus\\Events\\Component\\ComponentWasUpdatedEvent', function (ComponentWasUpdatedEvent $event) { $handler = new ComponentWasUpdatedHandler($event->component->status, $event->component->name); return $handler->send(); }); }