diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc9bba..0e52c69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Changelog +5.0.2 - 2025-10-27 +- Update Slack alert message to mention Matomo instance along with idSite + 5.0.1 - 2025-10-10 - Fix markReportAsSent method was missing diff --git a/Slack.php b/Slack.php index 0965a4c..ae5c40a 100644 --- a/Slack.php +++ b/Slack.php @@ -15,6 +15,7 @@ use Piwik\Piwik; use Piwik\Plugin; use Piwik\Plugins\ScheduledReports\ScheduledReports; +use Piwik\SettingsPiwik; use Piwik\View; use Piwik\Container\StaticContainer; use Piwik\ReportRenderer; @@ -466,7 +467,14 @@ private function groupAlertsByChannelId(array $alerts): array */ public function getAlertMessage(array $alert, string $metric, string $reportName): string { - return Piwik::translate('Slack_SlackAlertContent', [$alert['name'], $alert['siteName'], $metric, $reportName, $this->transformAlertCondition($alert)]); + $settingURL = SettingsPiwik::getPiwikUrl(); + if (stripos($settingURL, 'index.php') === false) { + $settingURL .= 'index.php'; + } + $settingURL .= '?idSite=' . $alert['idsite']; + $siteName = $alert['siteName']; + $siteWithLink = "<$settingURL|$siteName>"; + return Piwik::translate('Slack_SlackAlertContent', [$alert['name'], $siteWithLink, $metric, $reportName, $this->transformAlertCondition($alert)]); } /** diff --git a/plugin.json b/plugin.json index 5a41ce4..87bf7cc 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "name": "Slack", "description": "Send Matomo reports and alerts to Slack channels, keeping your team informed and ready to act in real time.", - "version": "5.0.1", + "version": "5.0.2", "theme": false, "require": { "matomo": ">=5.0.0,<6.0.0-b1" diff --git a/tests/Integration/SlackTest.php b/tests/Integration/SlackTest.php index c949d43..3be2e56 100644 --- a/tests/Integration/SlackTest.php +++ b/tests/Integration/SlackTest.php @@ -105,12 +105,12 @@ public function testGetAlertMessage($alert, $expectedMessage) public function getAlertData() { return [ - [['name' => 'Alert1', 'siteName' => 'test.com', 'metric_condition' => 'less_than', 'metric_matched' => '5', 'value_new' => '1', 'value_old' => '2'], 'Alert1 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary is 1 which is less than 5.'], - [['name' => 'Alert2', 'siteName' => 'test.com', 'metric_condition' => 'greater_than', 'metric_matched' => '8', 'value_new' => '10', 'value_old' => '2'], 'Alert2 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary is 10 which is greater than 8.'], - [['name' => 'Alert3', 'siteName' => 'test.com', 'metric_condition' => 'decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15'], 'Alert3 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary decreased more than 5 from 15 to 8.'], - [['name' => 'Alert4', 'siteName' => 'test.com', 'metric_condition' => 'increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20'], 'Alert4 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary increased more than 5 from 20 to 30.'], - [['name' => 'Alert5', 'siteName' => 'test.com', 'metric_condition' => 'percentage_decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15'], 'Alert5 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary decreased more than 5% from 15 to 8.'], - [['name' => 'Alert6', 'siteName' => 'test.com', 'metric_condition' => 'percentage_increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20'], 'Alert6 has been triggered for website test.com as the metric Unique Visitors in report Visits Summary increased more than 5% from 20 to 30.'], + [['name' => 'Alert1', 'siteName' => 'test.com', 'metric_condition' => 'less_than', 'metric_matched' => '5', 'value_new' => '1', 'value_old' => '2', 'idsite' => 1], 'Alert1 has been triggered for website as the metric Unique Visitors in report Visits Summary is 1 which is less than 5.'], + [['name' => 'Alert2', 'siteName' => 'test.com', 'metric_condition' => 'greater_than', 'metric_matched' => '8', 'value_new' => '10', 'value_old' => '2', 'idsite' => 1], 'Alert2 has been triggered for website as the metric Unique Visitors in report Visits Summary is 10 which is greater than 8.'], + [['name' => 'Alert3', 'siteName' => 'test.com', 'metric_condition' => 'decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15', 'idsite' => 1], 'Alert3 has been triggered for website as the metric Unique Visitors in report Visits Summary decreased more than 5 from 15 to 8.'], + [['name' => 'Alert4', 'siteName' => 'test.com', 'metric_condition' => 'increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20', 'idsite' => 1], 'Alert4 has been triggered for website as the metric Unique Visitors in report Visits Summary increased more than 5 from 20 to 30.'], + [['name' => 'Alert5', 'siteName' => 'test.com', 'metric_condition' => 'percentage_decrease_more_than', 'metric_matched' => '5', 'value_new' => '8', 'value_old' => '15', 'idsite' => 1], 'Alert5 has been triggered for website as the metric Unique Visitors in report Visits Summary decreased more than 5% from 15 to 8.'], + [['name' => 'Alert6', 'siteName' => 'test.com', 'metric_condition' => 'percentage_increase_more_than', 'metric_matched' => '5', 'value_new' => '30', 'value_old' => '20', 'idsite' => 1], 'Alert6 has been triggered for website as the metric Unique Visitors in report Visits Summary increased more than 5% from 20 to 30.'], ]; }