Example #1
0
 public function post($body, $type, $id)
 {
     if (!$this->config('enabled')) {
         return false;
     }
     // Find out when the last time an announce was sent for this entity
     $result = $this->Slack->findAllByEntityAndEntityId($type, $id)->first();
     if ($result) {
         $last_update = $result->modified;
     } else {
         $result = $this->Slack->newEntity();
         $result->entity = $type;
         $result->entity_id = $id;
         $last_update = new Time('1 year ago');
     }
     // Prevent sending out an update too soon
     if ($last_update->wasWithinLast($this->config('debounce'))) {
         return false;
     }
     $http = new Client();
     $data = (object) ['text' => $body];
     $response = $http->post($this->config('webhook_url'), ['payload' => json_encode($data, JSON_PRETTY_PRINT)]);
     $result->messages++;
     $this->Slack->save($result);
 }