From bc6b443c3db4f260bdc1460009c8110b54b3c257 Mon Sep 17 00:00:00 2001 From: Ash Bike Date: Sun, 5 Jul 2015 02:16:18 +0530 Subject: Slack channel can be overridden to post to another channel/private group or send direct messages. Need to make these database changes: INSERT INTO settings VALUES ('integration_slack_webhook_channel', ''); ALTER TABLE project_integrations ADD COLUMN slack_webhook_channel text; --- app/Integration/SlackWebhook.php | 22 ++++++++++++++++++++++ app/Template/config/integrations.php | 2 ++ app/Template/project/integrations.php | 2 ++ 3 files changed, 26 insertions(+) (limited to 'app') diff --git a/app/Integration/SlackWebhook.php b/app/Integration/SlackWebhook.php index 975ea21f..a584c132 100644 --- a/app/Integration/SlackWebhook.php +++ b/app/Integration/SlackWebhook.php @@ -38,6 +38,23 @@ class SlackWebhook extends \Core\Base $options = $this->projectIntegration->getParameters($project_id); return $options['slack_webhook_url']; } + + /** + * Get optional Slack channel + * + * @access public + * @param integer $project_id + * @return string + */ + public function getChannel($project_id) + { + if (!empty($this->config->get('integration_slack_webhook_channel'))) { + return $this->config->get('integration_slack_webhook_channel'); + } + + $options = $this->projectIntegration->getParameters($project_id); + return $options['slack_webhook_channel']; + } /** * Send message to the incoming Slack webhook @@ -68,6 +85,11 @@ class SlackWebhook extends \Core\Base $payload['text'] .= $this->helper->url->href('task', 'show', array('task_id' => $task_id, 'project_id' => $project_id)); $payload['text'] .= '|'.t('view the task on Kanboard').'>'; } + + $channel = $this->getChannel($project_id); + if (!empty($channel)) { + $payload['channel'] = $channel; + } $this->httpClient->postJson($this->getWebhookUrl($project_id), $payload); } diff --git a/app/Template/config/integrations.php b/app/Template/config/integrations.php index a1299806..9c80b499 100644 --- a/app/Template/config/integrations.php +++ b/app/Template/config/integrations.php @@ -77,6 +77,8 @@ form->label(t('Webhook URL'), 'integration_slack_webhook_url') ?> form->text('integration_slack_webhook_url', $values, $errors) ?> + form->label(t('Channel/Group/User (Optional)'), 'integration_slack_webhook_channel') ?> + form->text('integration_slack_webhook_channel', $values, $errors) ?>

diff --git a/app/Template/project/integrations.php b/app/Template/project/integrations.php index 698e438c..445e7bfb 100644 --- a/app/Template/project/integrations.php +++ b/app/Template/project/integrations.php @@ -85,6 +85,8 @@ form->label(t('Webhook URL'), 'slack_webhook_url') ?> form->text('slack_webhook_url', $values, $errors) ?> + form->label(t('Channel/Group/User (Optional)'), 'slack_webhook_channel') ?> + form->text('slack_webhook_channel', $values, $errors) ?>

-- cgit v1.2.3