Custom Notification type

Hi,

I have build a custom notification type using INotificationType Plugin Type and it seems to work fine.

I was able to enable email , live alert option in the settings/notifications tab.

I  was unable to figure out which API i need to use to retrieve these setting whether Email / lIve alert are Enabled / Disabled for a particular user .

Parents
No Data
Reply
  •  i had implemented this as below , using he controller i was generating the notifications when a custom comment is created ,

    public class IdeaChatNotificationType : INotificationType , ISingletonPlugin
    	{
    		private INotificationController _notificationController;
    		public string NotificationTypeName => "Ideas Chat";
    
    		public string NotificationTypeDescription => "Idea Internal Chat";
    
    		public string NotificationTypeCategory => "Idea Internal Chat";
    
    		public Guid NotificationTypeId => new Guid("b25aa3c5-a3f9-4c23-a295-a6425b87b030");
    
    		public bool IsCacheable => true;
    
    		public bool VaryCacheByUser => true;
    
    		public string Name => "Ideas Internal Chat Notifications";
    
    		public string Description => "Raises Notification for Ideas Internal Chat Members";
    
    		public bool CanDeleteNotification(Guid notificationId, int userId)
    		{
    			return true;
    		}
    
    		public string GetMessage(Guid notificationId, [Documentation("Target", OptionsType = typeof(NotificationTarget))] string target)
    		{
    			var notification = Apis.Get<INotifications>().Get(notificationId);
    			if (notification == null) { return null; }
    
    			return "A new [Internal Idea Chat] Comment added ";
    		}
    
    		public string GetTargetUrl(Guid notificationId) 
    		{
    			var notification = Apis.Get<INotifications>().Get(notificationId);
    			return notification != null && notification.Content != null ? notification.Content.Url : null;
    		}
    
    		public void Initialize()
    		{
    
    		}
    
    		public void SetController(INotificationController controller)
    		{
    			_notificationController = controller;
    		}
    
    		public void CreateNotification(Guid contentId, Guid contentTypeId,string url, int contentAuthor, int subscriberId)
    		{
    			_notificationController.CreateUpdate(new NotificationCreateUpdateOptions
    			{
    				ContentId = contentId,
    				ContentTypeId = contentTypeId,
    				ContentUrl = url,
    				LastUpdate = DateTime.UtcNow,
    				UserId = subscriberId,
    				ActorIdToAdd = contentAuthor
    			});
    		}
    	}

    i was triggering the schedular job to generate notifications and send emails ,

    public void Execute(JobData jobData)
    		{
    			try
    			{
    				int userId = int.Parse(jobData.Data["userId"]);
    				var data = jobData.Data["body"];
    				Guid id = Guid.Parse(jobData.Data["id"]);
    				string role = pluginConfiguration.GetCustom("role").Replace("Role=", "").Trim();
    				int roleid = int.Parse(role);
    
    				var roleobj = Apis.Get<IRoles>().Get(roleid);
    				if (roleobj == null) return;
    
    				var user = Apis.Get<IUsers>().Get(new UsersGetOptions { Id = userId });
    				var _ideaapi = Apis.Get<IIdeas>(); 
    				var idea = _ideaapi.Get(id);
    				if (user == null) return;
    				if (idea == null) return;
    				string subject = string.Format("Idea chat : {0} - {1} ", idea.Challenge.Group.Name, idea.Name);
    				string body = "<div><p style=\"font-size: 12pt; margin-top: 0;\">New chat comment on  @@title by @@displayname</p><p>@@body</p><div style=\"clear: both;\"></div><p><span style=\"color: #0087c3; text-decoration: none;\"><a href=\"@@url\" >View online</a></span></div>";
    				body = body.Replace("@@title", idea.Name).Replace("@@displayname", user.DisplayName).Replace("@@body", data).Replace("@@url", idea.Url);
    				
    				string[] rolename = new string[] { roleobj.Name };
    				var notificationplugin = PluginManager.GetSingleton<IdeaChatNotificationType>();
    				
    				var done = false;
    				var pageIndex = 0;
    				while (!done)
    				{
    					var growners = Apis.Get<IGroupUserMembers>().List(idea.Challenge.Group.Id.Value, new GroupUserMembersListOptions { IncludeRoleMembers = true, PageSize = 100, PageIndex = pageIndex });
    					var _roleapi = Apis.Get<IRoleUsers>();
    					var _emaiapi = Apis.Get<ISendEmail>();
    					var _users = Apis.Get<IUsers>();
    					var _notifications = Apis.Get<INotifications>();
    					bool send = false;
    					Guid nottypeid = new Guid("b25aa3c5-a3f9-4c23-a295-a6425b87b030");
    					Guid distypeid = new Guid("0d3948d6-aabc-4a58-b30a-1e46eda9abe8");
    
    					foreach (var owner in growners)
    					{
    						if (_roleapi.IsUserInRoles(owner.User.Username, rolename))
    						{
    							_users.RunAsUser(owner.User.Username, () => {
    
    								var preferences = _notifications.ListPreferences();
    								var dd = preferences.Preferences.FirstOrDefault(x => (x.NotificationTypeId == nottypeid && x.DistributionTypeId == null));
    								if (dd != null && dd.IsEnabled)
    								{
    									var per = preferences.Preferences.First(x => (x.NotificationTypeId == nottypeid && x.DistributionTypeId == distypeid));
    									send = per.IsEnabled;
    								}
    
    								
    
    
    							});
    
    							
    							if (send) _emaiapi.Send(new SendEmailOptions { Subject = subject, Body = body, ToEmail = owner.User.PrivateEmail });
    							notificationplugin.CreateNotification(idea.ContentId, _ideaapi.ContentTypeId , idea.Url, userId, owner.User.Id.Value);
    							send = false;
    						}
    					}
    
    					if (growners.TotalCount <= 100 * (pageIndex + 1)) done = true;
    					pageIndex++;
    
    				}
    
    				
    			}
    			catch(Exception e)
    			{
    				throw e;
    			}
    			
    		}

    Notifications and Emails are delivered as expected but, 

    We are receiving two emails the one we created  and the other system generated

    system-generated is below 

    so is there a way to restrict the system genrated email since we already generated one . Please correct me if i was in a wrong path

    Thanks

Children