diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-04-18 18:44:45 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-04-18 18:44:45 -0400 |
commit | 370b5a0fd7c1dba60e3b973506ba087adba42be0 (patch) | |
tree | 8da109b4fc90062d6eebb69d4ae2efca4da1bac3 /app/Integration/SlackWebhook.php | |
parent | f53bb88d10836e5c31efb958683d8bf3829eecbf (diff) |
Add Slack and Hipchat integrations for each projects
Diffstat (limited to 'app/Integration/SlackWebhook.php')
-rw-r--r-- | app/Integration/SlackWebhook.php | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/app/Integration/SlackWebhook.php b/app/Integration/SlackWebhook.php index 1c2ea781..b64096fb 100644 --- a/app/Integration/SlackWebhook.php +++ b/app/Integration/SlackWebhook.php @@ -11,6 +11,35 @@ namespace Integration; class SlackWebhook extends Base { /** + * Return true if Slack is enabled for this project or globally + * + * @access public + * @param integer $project_id + * @return boolean + */ + public function isActivated($project_id) + { + return $this->config->get('integration_slack_webhook') == 1 || $this->projectIntegration->hasValue($project_id, 'slack', 1); + } + + /** + * Get wehbook url + * + * @access public + * @param integer $project_id + * @return string + */ + public function getWebhookUrl($project_id) + { + if ($this->config->get('integration_slack_webhook') == 1) { + return $this->config->get('integration_slack_webhook_url'); + } + + $options = $this->projectIntegration->getParameters($project_id); + return $options['slack_webhook_url']; + } + + /** * Send message to the incoming Slack webhook * * @access public @@ -21,23 +50,26 @@ class SlackWebhook extends Base */ public function notify($project_id, $task_id, $event_name, array $event) { - $project = $this->project->getbyId($project_id); + if ($this->isActivated($project_id)) { - $event['event_name'] = $event_name; - $event['author'] = $this->user->getFullname($this->session['user']); + $project = $this->project->getbyId($project_id); - $payload = array( - 'text' => '*['.$project['name'].']* '.str_replace('"', '"', $this->projectActivity->getTitle($event)), - 'username' => 'Kanboard', - 'icon_url' => 'http://kanboard.net/assets/img/favicon.png', - ); + $event['event_name'] = $event_name; + $event['author'] = $this->user->getFullname($this->session['user']); - if ($this->config->get('application_url')) { - $payload['text'] .= ' - <'.$this->config->get('application_url'); - $payload['text'] .= $this->helper->u('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id)); - $payload['text'] .= '|'.t('view the task on Kanboard').'>'; - } + $payload = array( + 'text' => '*['.$project['name'].']* '.str_replace('"', '"', $this->projectActivity->getTitle($event)).(isset($event['task']['title']) ? ' ('.$event['task']['title'].')' : ''), + 'username' => 'Kanboard', + 'icon_url' => 'http://kanboard.net/assets/img/favicon.png', + ); - $this->httpClient->post($this->config->get('integration_slack_webhook_url'), $payload); + if ($this->config->get('application_url')) { + $payload['text'] .= ' - <'.$this->config->get('application_url'); + $payload['text'] .= $this->helper->u('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id)); + $payload['text'] .= '|'.t('view the task on Kanboard').'>'; + } + + $this->httpClient->post($this->getWebhookUrl($project_id), $payload); + } } } |