private PushNotification CreatePushNotification(CalendarEventApprovalsChangedWithAdditionalData message) { var templateExpressionContext = new Dictionary <string, string> { ["eventType"] = message.Event.Type, ["approver"] = message.Approver.Name }; templateExpressionContext = new DictionaryMerge().Perform( templateExpressionContext, message.Event.AdditionalData.ToDictionary(x => x.Key, x => x.Value)); var content = new PushNotificationContent { Title = this.pushNotificationConfig.Title, Body = new TemplateExpressionParser().Parse(this.pushNotificationConfig.Body, templateExpressionContext), CustomData = new { message.Event.EventId, message.Event.EmployeeId, ApproverId = message.Approver.EmployeeId, Type = CalendarEventPushNotificationTypes.EventUserGrantedApproval } }; return(new PushNotification(content, message.OwnerPushTokens.ToList())); }
protected override void OnReceive(object message) { switch (message) { case CalendarEventAssignedToApprover msg: this.GetAdditionalData(msg) .ContinueWith(task => { var(ownerEmployeeResult, approverPreferencesResult, approverEmployeeResult) = task.Result; return(new CalendarEventAssignedWithAdditionalData( msg.Event, ownerEmployeeResult.Employees.First().Metadata, approverPreferencesResult.UserPreferences, approverEmployeeResult.Employees.First().Metadata)); }) .PipeTo(this.Self); break; case CalendarEventAssignedWithAdditionalData msg when msg.ApproverUserPreferences.EmailNotifications: this.logger.Debug("Sending email notification about event {0} of {1} assigned to {2}", msg.Event.EventId, msg.Owner.EmployeeId, msg.Approver.EmployeeId); var datesStr = msg.Event.Dates.StartDate == msg.Event.Dates.EndDate ? msg.Event.Dates.StartDate.ToString("dd/MM/yyyy") : $"{msg.Event.Dates.StartDate:dd/MM/yyyy} - {msg.Event.Dates.EndDate:dd/MM/yyyy}"; var templateExpressionContext = new Dictionary <string, string> { ["eventType"] = msg.Event.Type, ["dates"] = datesStr, ["employee"] = msg.Owner.Name }; templateExpressionContext = new DictionaryMerge().Perform( templateExpressionContext, msg.Event.AdditionalData.ToDictionary(x => x.Key, x => x.Value)); var sender = this.emailNotificationConfig.NotificationSender; var recipient = msg.Approver.Email; var subject = this.emailNotificationConfig.Subject; var body = new TemplateExpressionParser().Parse(this.emailNotificationConfig.Body, templateExpressionContext); Context.System.EventStream.Publish( new NotificationEventBusMessage( new EmailNotification(sender, new[] { recipient }, subject, body))); break; case CalendarEventAssignedWithAdditionalData _: break; default: this.Unhandled(message); break; } }
private void SendNotification(CalendarEventWithAdditionalData message, IPushNotification notificationConfiguration) { var templateExpressionContext = new Dictionary <string, string> { ["employee"] = message.Owner.Name, ["startDate"] = message.Event.Dates.StartDate.ToString("dd/MM/yyyy") }; templateExpressionContext = new DictionaryMerge().Perform( templateExpressionContext, message.Event.AdditionalData.ToDictionary(x => x.Key, x => x.Value)); var content = new PushNotificationContent { Title = notificationConfiguration.Title, Body = new TemplateExpressionParser().Parse(notificationConfiguration.Body, templateExpressionContext), CustomData = new { message.Event.EventId, message.Owner.EmployeeId, ManagerId = message.Manager.EmployeeId, Type = message.NotificationType == NotificationType.Created ? CalendarEventPushNotificationTypes.SickLeaveCreatedManager : message.NotificationType == NotificationType.Prolonged ? CalendarEventPushNotificationTypes.SickLeaveProlongedManager : CalendarEventPushNotificationTypes.SickLeaveCancelledManager } }; Context.System.EventStream.Publish(new NotificationEventBusMessage( new PushNotification(content, message.ManagerPushTokens))); }
private void SendNotification(CalendarEventChangedWithAdditionalData message, IEmailWithFixedRecipientNotification notificationConfiguration) { var templateExpressionContext = new Dictionary <string, string> { ["employee"] = message.Employee.Name, ["employeeId"] = message.Employee.EmployeeId, ["startDate"] = message.Event.Dates.StartDate.ToString("dd/MM/yyyy"), ["endDate"] = message.Event.Dates.EndDate.ToString("dd/MM/yyyy") }; templateExpressionContext = new DictionaryMerge().Perform( templateExpressionContext, message.Event.AdditionalData.ToDictionary(x => x.Key, x => x.Value)); var templateExpressionParser = new TemplateExpressionParser(); var sender = notificationConfiguration.NotificationSender; var recipient = notificationConfiguration.NotificationRecipient; var subject = templateExpressionParser.Parse(notificationConfiguration.Subject, templateExpressionContext); var body = templateExpressionParser.Parse(notificationConfiguration.Body, templateExpressionContext); Context.System.EventStream.Publish( new NotificationEventBusMessage( new EmailNotification(sender, new[] { recipient }, subject, body))); }