Skip to content

Conversation

@AltamashShaikh
Copy link
Contributor

Description

Adds ability to send alerts to MicrosoftTeams Channel, #PG-4671

Requires: matomo-org/plugin-MicrosoftTeams#1

Issue No

#PG-4671

Steps to Replicate the Issue

  1. Download MicrosoftTeams plugin
  2. Activate the plugin
  3. Create new alert via MSTeams
  4. For webhook URL refer to keeper (Microsoft Teams - Test details under Plugins team section)
  5. Set condition like unique_visitors < 10
  6. Execute this command - ./console scheduled-tasks:run --force "Piwik\Plugins\CustomAlerts\Tasks.runAlertsDaily_{idsite}"
  7. You will view the alerts in the channel (Plugins team already added)

Checklist

  • [✔] Tested locally or on demo2/demo3?
  • [✔] New test case added/updated?
  • [✔] Are all newly added texts included via translation?
  • [✔] Are text sanitized properly? (Eg use of v-text v/s v-html for vue)
  • [✔] Version bumped?

Copy link

@james-hill-matomo james-hill-matomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, haven't managed to test it yet. Can we tag in Jeff for that?

* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, don't fix. Use strict.

Comment on lines +42 to +45
return array(
$this->migration->db->addColumn('alert', 'ms_teams_webhook_url', 'VARCHAR(500) NULL', 'slack_channel_id'),
$this->migration->db->addColumn('alert_triggered', 'ms_teams_webhook_url', 'VARCHAR(500) NULL', 'slack_channel_id'),
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe code can be migrated before db is updated, for up to an hour. Codex impact assessment below.

I'm not sure what our policy for this stuff is currently - I suspect previously we wouldn't have thought about it, and wouldn't have seen any of the errors.

Maybe a good middle ground is to is to fix Model.php only, so that alerts continue working until the schema is updated. A fix would be to check for existence of the column first.

  - Updates/5.2.0.php:42-45 is what adds ms_teams_webhook_url to both alert and alert_triggered. If that migration isn’t run, those columns simply don’t exist.
  - Model.php:264-289 and Model.php:349-371 always include ms_teams_webhook_url in the insert/update payload. Without the column, every call to the addAlert/editAlert API fails with an
    “Unknown column” SQL error, so no alert can be saved (not just Teams alerts).
  - When an alert fires, Model.php:392-417 copies the same field into the alert_triggered insert. With the old schema this insert also errors, so the scheduler can’t persist triggered
    alerts and all downstream notifications (email/SMS/Slack) abort for that run.
  - Housekeeping code such as CustomAlerts.php:166-183 reads $alert['ms_teams_webhook_url'] while updating alerts. If the column is missing, those arrays never have that key, leading to
    PHP notices and preventing clean saves even when editing unrelated fields.
  - Because the UI and API contract now expose a ms_teams_webhook_url property (see vue/src/EditAlert/EditAlert.vue:114-118 and API.php:136-254), users will see the Teams options but
    any submission will error until the schema is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is okay to pass, as we have done similar thing in past and have received very few complaints

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only add//update will be broken, till the time we run the update, existing alerts will keep working.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right - triggerAlert could potentially insert the wrong column, but it's reading from the db in the first place, so never will.

@AltamashShaikh
Copy link
Contributor Author

I am merging this in-order to fix test cases.

@AltamashShaikh AltamashShaikh merged commit ef813f1 into 5.x-dev Nov 21, 2025
7 checks passed
@AltamashShaikh AltamashShaikh deleted the PG-4671-msteams-alert branch November 21, 2025 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants