Page MenuHomePhabricator

Echo email notifications not bundling properly
Open, Needs TriagePublicFeature

Description

Users are sent notifications when images they have uploaded are ready for review within the Special:SuggestedTags page. Since users often upload files in batches, we want to ensure notifications are bundled so that folks don't get spammed with alerts.

Right now web-based notifications are bundling correctly, but email-based notifications are still getting sent out as individual emails (one per file), despite the fact that email has been set to true in the Echo configuration. Is there something missing from the presentation model perhaps?

I have been able to reproduce this issue locally using $wgSMTP on my local dev environment.

Steps to Reproduce:

  1. Sign up for email notifications for "Suggested Tags" in user settings
  2. Upload a series of images

Actual Results:
User gets one email for every image.

Expected Results:
User should get a "bundled" email for a batch of images (I'm not sure what this should actually look like).

Relevant Code

Here's the current echo configuration and presentation model we are using:

  1. MachineVision's extension.json defines two echo-related hooks: BeforeCreateEchoEvent and EchoGetBundleRules.
  2. Those hooks are implemented in the Hooks.php file. Here's the code for each hook method:
/**
 * @param array &$notifications
 * @param array &$notificationCategories
 * @param array &$icons
 */
public static function onBeforeCreateEchoEvent(
	&$notifications,
	&$notificationCategories,
	&$icons
) {
	// 1. Define notification categories: $notificationCategories[ '...' ]
	$notificationCategories[ 'machinevision' ] = [
		'priority' => 3,
		'tooltip' => 'echo-pref-tooltip-machinevision-suggestions-ready',
	];

	// 2. Define the event: $notifications[ '...' ]
	$notifications[ 'machinevision-suggestions-ready'] = [
		'category' => 'machinevision',
		'group' => 'positive',
		'section' => 'alert',
		'presentation-model' => Notifications\SuggestionsReadyPresentationModel::class,
		'user-locators' => [ 'EchoUserLocator::locateEventAgent' ],
		'canNotifyAgent' => true,
		'bundle' => [
			'web' => true,
			'email' => true,
			'expandable' => false
		]
	];

	$icons['suggestions-ready']['path'] = 'MachineVision/resources/icons/suggestions-ready-icon.svg';
}
/**
 * @param EchoEvent $event
 * @param string &$bundleString
 * @return bool
 */
public static function onEchoGetBundleRules( EchoEvent $event, &$bundleString ) {
	if ( $event->getType() === 'machinevision-suggestions-ready' ) {
		$bundleString = 'machinevision';
	}

	return true;
}
  1. A simple presentation model is defined for our notifications in SuggestionsReadyPresentationModel.php. Here's the code for the model:
<?php

namespace MediaWiki\Extension\MachineVision\Notifications;

use EchoEventPresentationModel;
use Message;
use MWException;

class SuggestionsReadyPresentationModel extends EchoEventPresentationModel {
	/**
	 * @return string
	 */
	public function getIconType() {
		return 'suggestions-ready';
	}

	/**
	 * @return Message
	 */
	public function getHeaderMessage() {
		$user = $this->getViewingUserForGender();
		$title = $this->event->getTitle()->getText();

		if ( $this->isBundled() ) {
			return $this->msg(
				'echo-machinevision-suggestions-ready-notification-header',
				$user
			);
		} else {
			return $this->msg(
				'echo-machinevision-suggestions-ready-notification-header-compact',
				$user,
				$title
			);
		}
	}

	/**
	 * @return Message
	 */
	public function getCompactHeaderMessage() {
		$user = $this->getViewingUserForGender();
		$title = $this->event->getTitle()->getText();

		return $this->msg(
			'echo-machinevision-suggestions-ready-notification-header-compact',
			$user,
			$title
		);
	}

	/**
	 * @return bool|Message
	 */
	public function getBodyMessage() {
		$user = $this->getViewingUserForGender();

		return $this->msg(
			'echo-machinevision-suggestions-ready-notification-body',
			$user
		);
	}

	/**
	 * @return array|false
	 * @throws MWException
	 */
	public function getPrimaryLink() {
		$url = \SpecialPage::getTitleFor( 'SuggestedTags', false, 'user' );

		return [
			'url' => $url->getLinkURL(),
			'label' => $this->msg( 'machinevision-machineaidedtagging' )
		];
	}
}

If anyone who is more familiar with Echo can take a look and let me know if anything is missing here, it would be greatly appreciated.

Event Timeline

Sample of current multiple email notifications:

CAT-mails.jpg (1×640 px, 86 KB)

egardner added a subscriber: Catrope.

@Ramsey-WMF I'm able to reproduce this locally, but I don't understand why email notifications are not bundling; I've followed the instructions in the Echo docs but I must be missing something. I'm pinging the Notifications project and @Catrope in the hope that they can shed some light.

In the short term, we may disable the email notifications entirely – it's likely that very few users have opted-in to this in the first place.

Change 558635 had a related patch set uploaded (by Eric Gardner; owner: Eric Gardner):
[operations/mediawiki-config@master] Disable MachineVision email notifications on Commons

https://gerrit.wikimedia.org/r/558635

Change 558635 merged by jenkins-bot:
[operations/mediawiki-config@master] Disable MachineVision email notifications

https://gerrit.wikimedia.org/r/558635

Mentioned in SAL (#wikimedia-operations) [2019-12-17T19:41:43Z] <mholloway-shell@deploy1001> Synchronized wmf-config/CommonSettings.php: Disable MachineVision email notifications (T240878) (duration: 01m 07s)

Just to eliminate the obvious, this has been tested with email delivery preference set to daily or weekly digest, right? Emails sent right away won't be bundled.

Don't worry, nothing is obvious as far as I'm concerned. This is my first attempt using Echo (most of my work is on the JS side).

Does email notification bundling only happen when users have set their preferences to daily or weekly digests? I has assumed that digests and notification bundles were not related.

On the web, you can bundle all notifications within a certain category – I figured there was a way to do something similar for email (a digest of all notifications within a specific category that happened over the course of a few minutes, rather than one email each time) regardless of whether the user has signed up for everything in digest form.

Is there any discussion of this in the Echo docs? I followed the Creating a New Notification Type guide, but didn't see much about email notifications there. The Notifications Developer Guide is listed as outdated so I didn't study this one as closely.

Does email notification bundling only happen when users have set their preferences to daily or weekly digests? I has assumed that digests and notification bundles were not related.

They are related in the sense that when you want notifications to be sent as they happen, they are processed immediately and individually. There is just no opportunity for the bundling code to run.

Feel free to create a feature request (or turn this task into one). I don't think this is necessarily a big task, and there are other use cases where a 5-10 minutes email delay would help (moderation, don't send already read).

Hi @SBisson, I agree that this would be a useful feature. I'm happy to turn this ticket into a formal request (not sure if there are any tags that I should add for that).

In the MachineVision extension, we think it will be common for users to upload images in batches (meaning they will be processed within moments of one another when they reach the head of the queue), and we'd prefer to notify users in a batched way as well. We can do that for Web notifications but not for email.

Feature Request
When email bundling is set up for a given notification type, Echo should add a delay of ~5-10 minutes before sending an email notification for the event in question. During this time, any other events of the same type should be collected into a single email bundle, similar to the way that bundled web notifications work. This feature would continue to respect daily/weekly digest preferences, so only emails that would otherwise be sent right away should be effected.

Please let me know if there is any other information that I should provide. If this is something that could be added to Echo in the near future, that would be great.

@egardner Thanks for documenting your need here. It's now up to the Growth-Team to figure if/when they can work on it.

SBisson changed the subtype of this task from "Bug Report" to "Feature Request".Jan 7 2020, 7:05 PM