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 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'app/Integration') 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); } -- cgit v1.2.3 From afab68b130ccdd97a7575a682683d6df71006748 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 5 Jul 2015 13:14:00 -0400 Subject: Add schema migration for Slack channel --- app/Integration/SlackWebhook.php | 10 +++++----- app/Schema/Mysql.php | 8 +++++++- app/Schema/Postgres.php | 8 +++++++- app/Schema/Sqlite.php | 8 +++++++- docs/slack.markdown | 9 ++++----- 5 files changed, 30 insertions(+), 13 deletions(-) (limited to 'app/Integration') diff --git a/app/Integration/SlackWebhook.php b/app/Integration/SlackWebhook.php index a584c132..4f42dca3 100644 --- a/app/Integration/SlackWebhook.php +++ b/app/Integration/SlackWebhook.php @@ -38,7 +38,7 @@ class SlackWebhook extends \Core\Base $options = $this->projectIntegration->getParameters($project_id); return $options['slack_webhook_url']; } - + /** * Get optional Slack channel * @@ -48,10 +48,10 @@ class SlackWebhook extends \Core\Base */ public function getChannel($project_id) { - if (!empty($this->config->get('integration_slack_webhook_channel'))) { + 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']; } @@ -85,9 +85,9 @@ 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)) { + if (! empty($channel)) { $payload['channel'] = $channel; } diff --git a/app/Schema/Mysql.php b/app/Schema/Mysql.php index 0c932104..37ef637b 100644 --- a/app/Schema/Mysql.php +++ b/app/Schema/Mysql.php @@ -6,7 +6,13 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 77; +const VERSION = 78; + +function version_78($pdo) +{ + $pdo->exec("ALTER TABLE project_integrations ADD COLUMN slack_webhook_channel VARCHAR(255) DEFAULT ''"); + $pdo->exec("INSERT INTO settings VALUES ('integration_slack_webhook_channel', '')"); +} function version_77($pdo) { diff --git a/app/Schema/Postgres.php b/app/Schema/Postgres.php index a3309068..62f22baa 100644 --- a/app/Schema/Postgres.php +++ b/app/Schema/Postgres.php @@ -6,7 +6,13 @@ use PDO; use Core\Security; use Model\Link; -const VERSION = 57; +const VERSION = 58; + +function version_58($pdo) +{ + $pdo->exec("ALTER TABLE project_integrations ADD COLUMN slack_webhook_channel VARCHAR(255) DEFAULT ''"); + $pdo->exec("INSERT INTO settings VALUES ('integration_slack_webhook_channel', '')"); +} function version_57($pdo) { diff --git a/app/Schema/Sqlite.php b/app/Schema/Sqlite.php index c3bbbac9..10899b54 100644 --- a/app/Schema/Sqlite.php +++ b/app/Schema/Sqlite.php @@ -6,7 +6,13 @@ use Core\Security; use PDO; use Model\Link; -const VERSION = 73; +const VERSION = 74; + +function version_74($pdo) +{ + $pdo->exec("ALTER TABLE project_integrations ADD COLUMN slack_webhook_channel TEXT DEFAULT ''"); + $pdo->exec("INSERT INTO settings VALUES ('integration_slack_webhook_channel', '')"); +} function version_73($pdo) { diff --git a/docs/slack.markdown b/docs/slack.markdown index 437098ac..f90464e8 100644 --- a/docs/slack.markdown +++ b/docs/slack.markdown @@ -29,11 +29,10 @@ Now, Kanboard events will be sent to the Slack channel. ### Overriding Channel (Optional) -Optnally you can override the channel, private group or send direct messages by filling up **Channel/Group/User** textbox. Leaving it empty will post to the channel configured during webhook configuration. +Optionally you can override the channel, private group or send direct messages by filling up **Channel/Group/User** text box. Leaving it empty will post to the channel configured during webhook configuration. Examples: -- #mychannel1 - Send message to channel 'mychannel1' -- #myprivategroup1 - Send message to private group 'myprivategroup1' -- @anotheruser1 - Send message to user 'anotheruser1' - +- Send messages to another channel: **#mychannel1** +- Send messages to a private group: **#myprivategroup1** +- Send messages directly to someone: **@anotheruser1** -- cgit v1.2.3 From 538dab64b93f3690c223e148d1126e6ac9b862b8 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 6 Jul 2015 21:39:41 -0400 Subject: Fix PHP 5.3 issue --- app/Integration/SlackWebhook.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/Integration') diff --git a/app/Integration/SlackWebhook.php b/app/Integration/SlackWebhook.php index 4f42dca3..498cea09 100644 --- a/app/Integration/SlackWebhook.php +++ b/app/Integration/SlackWebhook.php @@ -48,8 +48,10 @@ class SlackWebhook extends \Core\Base */ public function getChannel($project_id) { - if (! empty($this->config->get('integration_slack_webhook_channel'))) { - return $this->config->get('integration_slack_webhook_channel'); + $channel = $this->config->get('integration_slack_webhook_channel'); + + if (! empty($channel)) { + return $channel; } $options = $this->projectIntegration->getParameters($project_id); -- cgit v1.2.3