Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to provide their own routing for notifications. #4922

Closed
CaMer0n opened this issue Dec 13, 2022 · 0 comments
Closed

Allow plugins to provide their own routing for notifications. #4922

CaMer0n opened this issue Dec 13, 2022 · 0 comments
Labels
topic: documentation type: enhancement An improvement or new feature request
Milestone

Comments

@CaMer0n
Copy link
Member

CaMer0n commented Dec 13, 2022

Motivation

Currently e107 only provides options for emailing of notifications, but not SMS, Push notifications or similar.

Proposed Solution

Allow plugins to expand the core functionality to provide additional notification channels via new methods inside e_notify.php.

Example

class _blank_notify extends notify
{		
	function config()
	{
			
		$config = array();
	
		$config[] = array(
			'name'			=> "Notify about something",
			'function'		=> "customNotify",
			'category'		=> ''
		);	


		
		return $config;
	}


	function customNotify($data)
	{
		$subject = "My Notification";
		$message = print_a($data,true);
		$this->send('customNotify', $subject, $message);
	}


	// BELOW IS OPTIONAL - R IF YOU WISH YOUR PLUGIN TO BECOME A ROUTER OF NOTIFICATIONS. eg. sending sms or messages to other platforms.

	/**
	 * REMOVE THIS METHOD WHEN NOT IN USE.
	 * @return array
	 */
	function router()
	{
		$ret = [];

		$ret['other_type'] = array( // 'other_type' method will be called when this notification is triggered (see method below)
			'label'			=> "Blank Example", // label used in admin Notify area
			'field'		    => "handle", // rendered in the admin Notify area when this option is selected. see method below.
			'category'		=> ''
		);

		return $ret;
	}

	/**
	 * Custom method used to render a field in Admin Notify area.
	 * REMOVE THIS METHOD WHEN NOT IN USE.
	 * @param string $name Field name.
	 * @param mixed $curVal current value.
	 * @return string
	 */
	function handle($name, $curVal)
	{
		return e107::getForm()->text($name, $curVal, 80, ['size'=>'large','placeholder'=>'eg. account name']);
	}

	/**
	 * Custom Method to handle notification.
	 * REMOVE THIS METHOD WHEN NOT IN USE
	 * @param array $data
	 * @return array
	 */
	function other_type($data)
	{
		return $data; // Peform some other kind of notification and return true on success / false on error.
	}
}

Example Output in admin area:

image

Other usage example:

Saving a phone number to receive SMS notifications. (See Twilio plugin )

image

@CaMer0n CaMer0n added the type: enhancement An improvement or new feature request label Dec 13, 2022
@CaMer0n CaMer0n added this to the e107 2.3.3 milestone Dec 13, 2022
CaMer0n added a commit that referenced this issue Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: documentation type: enhancement An improvement or new feature request
Projects
None yet
Development

No branches or pull requests

1 participant