Skip to content

Commit 1321fa2

Browse files
committed
CU-8687aj3gt Bug fixes for Novu send paths.
1 parent 5884a75 commit 1321fa2

File tree

10 files changed

+769
-720
lines changed

10 files changed

+769
-720
lines changed

Core/Resgrid.Config/ChatConfig.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public static class ChatConfig
1010
public static string NovuApplicationId = "";
1111
public static string NovuSecretKey = "";
1212

13-
public static string NovuUnitFcmProviderId = "";
14-
public static string NovuUnitApnsProviderId = "";
15-
public static string NovuResponderFcmProviderId = "";
16-
public static string NovuResponderApnsProviderId = "";
13+
public static string NovuUnitFcmProviderId = "firebase-cloud-messaging-7Z5wHFPpQ";
14+
public static string NovuUnitApnsProviderId = "unit-apns";
15+
public static string NovuResponderFcmProviderId = "respond-firebase-cloud-messaging";
16+
public static string NovuResponderApnsProviderId = "respond-apns";
1717
public static string NovuDispatchUnitWorkflowId = "unit-dispatch";
1818
public static string NovuDispatchUserWorkflowId = "user-dispatch";
1919
public static string NovuMessageUserWorkflowId = "user-message";

Core/Resgrid.Model/Services/ICommunicationService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface ICommunicationService
1919
/// <param name="profile">The profile.</param>
2020
/// <returns>Task&lt;System.Boolean&gt;.</returns>
2121
Task<bool> SendMessageAsync(Message message, string sendersName, string departmentNumber, int departmentId,
22-
UserProfile profile = null);
22+
UserProfile profile = null, Department department = null);
2323

2424
/// <summary>
2525
/// Sends the call asynchronous.
@@ -110,6 +110,6 @@ Task<bool> SendTextMessageAsync(string userId, string title, string message, int
110110
/// <param name="profile">The profile.</param>
111111
/// <returns>Task&lt;System.Boolean&gt;.</returns>
112112
Task<bool> SendCalendarAsync(string userId, int departmentId, string message, string departmentNumber,
113-
string title = "Notification", UserProfile profile = null);
113+
string title = "Notification", UserProfile profile = null, Department department = null);
114114
}
115115
}

Core/Resgrid.Services/CalendarService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public async Task<bool> NotifyNewCalendarItemAsync(CalendarItem calendarItem)
469469
// Notify the entire department
470470
foreach (var profile in profiles)
471471
{
472-
await _communicationService.SendCalendarAsync(profile.Key, calendarItem.DepartmentId, message, departmentNumber, title, profile.Value);
472+
await _communicationService.SendCalendarAsync(profile.Key, calendarItem.DepartmentId, message, departmentNumber, title, profile.Value, department);
473473
}
474474
}
475475
else
@@ -487,9 +487,9 @@ public async Task<bool> NotifyNewCalendarItemAsync(CalendarItem calendarItem)
487487
foreach (var member in group.Members)
488488
{
489489
if (profiles.ContainsKey(member.UserId))
490-
await _communicationService.SendNotificationAsync(member.UserId, calendarItem.DepartmentId, message, departmentNumber, department, title, profiles[member.UserId]);
490+
await _communicationService.SendCalendarAsync(member.UserId, calendarItem.DepartmentId, message, departmentNumber, title, profiles[member.UserId], department);
491491
else
492-
await _communicationService.SendNotificationAsync(member.UserId, calendarItem.DepartmentId, message, departmentNumber, department, title, null);
492+
await _communicationService.SendCalendarAsync(member.UserId, calendarItem.DepartmentId, message, departmentNumber, title, null, department);
493493
}
494494
}
495495
}

Core/Resgrid.Services/CallEmailTemplates/OttawaKingstonTorontoTemplate.cs

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,48 +49,84 @@ public async Task<Call> GenerateCall(CallEmail email, string managingUser, List<
4949
if (String.IsNullOrEmpty(email.Subject))
5050
return null;
5151

52-
string[] sections = email.TextBody.Split(new[] {" ALPHA 512 "}, StringSplitOptions.None);
53-
string[] sectionOneParts = sections[0].Split(new[] {" "}, StringSplitOptions.None);
54-
55-
Call c = new Call();
56-
c.Notes = email.TextBody;
57-
c.Name = sections[1].Trim();
58-
c.LoggedOn = DateTime.UtcNow;
59-
c.Priority = priority;
60-
c.ReportingUserId = managingUser;
61-
c.Dispatches = new Collection<CallDispatch>();
62-
c.CallSource = (int)CallSources.EmailImport;
63-
c.SourceIdentifier = email.MessageId;
64-
c.NatureOfCall = sections[1].Trim();
65-
c.IncidentNumber = sectionOneParts[0].Trim();
66-
c.ExternalIdentifier = sectionOneParts[0].Trim();
67-
68-
if (users != null && users.Any())
52+
try
6953
{
70-
foreach (var u in users)
54+
string[] sections = email.TextBody.Split(new[] { " ALPHA 512 " }, StringSplitOptions.None);
55+
string[] sectionOneParts = sections[0].Split(new[] { " " }, StringSplitOptions.None);
56+
57+
Call c = new Call();
58+
c.Notes = email.TextBody;
59+
c.Name = sections[1].Trim();
60+
c.LoggedOn = DateTime.UtcNow;
61+
c.Priority = priority;
62+
c.ReportingUserId = managingUser;
63+
c.Dispatches = new Collection<CallDispatch>();
64+
c.CallSource = (int)CallSources.EmailImport;
65+
c.SourceIdentifier = email.MessageId;
66+
c.NatureOfCall = sections[1].Trim();
67+
c.IncidentNumber = sectionOneParts[0].Trim();
68+
c.ExternalIdentifier = sectionOneParts[0].Trim();
69+
70+
if (users != null && users.Any())
7171
{
72-
CallDispatch cd = new CallDispatch();
73-
cd.UserId = u.UserId;
72+
foreach (var u in users)
73+
{
74+
CallDispatch cd = new CallDispatch();
75+
cd.UserId = u.UserId;
7476

75-
c.Dispatches.Add(cd);
77+
c.Dispatches.Add(cd);
78+
}
7679
}
77-
}
7880

79-
// Search for an active call
80-
if (activeCalls != null && activeCalls.Any())
81+
// Search for an active call
82+
if (activeCalls != null && activeCalls.Any())
83+
{
84+
var activeCall = activeCalls.FirstOrDefault(x => x.IncidentNumber == c.IncidentNumber);
85+
86+
if (activeCall != null)
87+
{
88+
activeCall.Notes = c.Notes;
89+
activeCall.LastDispatchedOn = DateTime.UtcNow;
90+
91+
return activeCall;
92+
}
93+
}
94+
95+
return c;
96+
}
97+
catch (Exception ex)
8198
{
82-
var activeCall = activeCalls.FirstOrDefault(x => x.IncidentNumber == c.IncidentNumber);
99+
Call c = new Call();
100+
c.Name = email.Subject;
101+
c.NatureOfCall = $"ERROR PROCESSING DISPATCH EMAIL, Unprocessed email body: {email.TextBody}";
83102

84-
if (activeCall != null)
103+
if (users != null && users.Any())
85104
{
86-
activeCall.Notes = c.Notes;
87-
activeCall.LastDispatchedOn = DateTime.UtcNow;
105+
foreach (var u in users)
106+
{
107+
CallDispatch cd = new CallDispatch();
108+
cd.UserId = u.UserId;
88109

89-
return activeCall;
110+
c.Dispatches.Add(cd);
111+
}
90112
}
91-
}
92113

93-
return c;
114+
// Search for an active call
115+
if (activeCalls != null && activeCalls.Any())
116+
{
117+
var activeCall = activeCalls.FirstOrDefault(x => x.IncidentNumber == c.IncidentNumber);
118+
119+
if (activeCall != null)
120+
{
121+
activeCall.Notes = c.Notes;
122+
activeCall.LastDispatchedOn = DateTime.UtcNow;
123+
124+
return activeCall;
125+
}
126+
}
127+
128+
return c;
129+
}
94130
}
95131
}
96132
}

Core/Resgrid.Services/CommunicationService.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public CommunicationService(ISmsService smsService, IEmailService emailService,
3939
_userStateService = userStateService;
4040
}
4141

42-
public async Task<bool> SendMessageAsync(Message message, string sendersName, string departmentNumber, int departmentId, UserProfile profile = null)
42+
public async Task<bool> SendMessageAsync(Message message, string sendersName, string departmentNumber, int departmentId, UserProfile profile = null, Department department = null)
4343
{
4444
if (Config.SystemBehaviorConfig.DoNotBroadcast && !Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId))
4545
return false;
@@ -79,6 +79,7 @@ public async Task<bool> SendMessageAsync(Message message, string sendersName, st
7979
{
8080
var spm = new StandardPushMessage();
8181
spm.MessageId = message.MessageId;
82+
spm.DepartmentCode = department?.Code;
8283

8384
if (message.SystemGenerated)
8485
spm.SubTitle = "Msg from System";
@@ -124,6 +125,7 @@ public async Task<bool> SendCallAsync(Call call, CallDispatch dispatch, string d
124125
spc.Priority = call.Priority;
125126
spc.ActiveCallCount = 1;
126127
spc.DepartmentId = departmentId;
128+
spc.DepartmentCode = call.Department?.Code;
127129

128130
if (call.CallPriority != null && !String.IsNullOrWhiteSpace(call.CallPriority.Color))
129131
{
@@ -335,7 +337,7 @@ public async Task<bool> SendNotificationAsync(string userId, int departmentId, s
335337
return true;
336338
}
337339

338-
public async Task<bool> SendCalendarAsync(string userId, int departmentId, string message, string departmentNumber, string title = "Notification", UserProfile profile = null)
340+
public async Task<bool> SendCalendarAsync(string userId, int departmentId, string message, string departmentNumber, string title = "Notification", UserProfile profile = null, Department department = null)
339341
{
340342
if (Config.SystemBehaviorConfig.DoNotBroadcast && !Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId))
341343
return false;
@@ -364,6 +366,7 @@ public async Task<bool> SendCalendarAsync(string userId, int departmentId, strin
364366
var spm = new StandardPushMessage();
365367
spm.Title = "Calendar";
366368
spm.SubTitle = $"{title} {message}";
369+
spm.DepartmentCode = null;
367370

368371
try
369372
{
@@ -467,6 +470,7 @@ public async Task<bool> SendTroubleAlertAsync(TroubleAlertEvent troubleAlertEven
467470
spc.Priority = (int)CallPriority.Emergency;
468471
spc.ActiveCallCount = 1;
469472
spc.DepartmentId = departmentId;
473+
spc.DepartmentCode = call.Department?.Code;
470474

471475
string subTitle = String.Empty;
472476
if (!String.IsNullOrWhiteSpace(unitAddress))

Core/Resgrid.Services/PushService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public async Task<bool> PushMessage(StandardPushMessage message, string userId,
112112

113113
try
114114
{
115-
await _novuProvider.SendUserMessage(message.Title, message.SubTitle, userId, message.DepartmentCode, string.Format("M{0}", message.MessageId), null);
115+
if (!string.IsNullOrWhiteSpace(message.DepartmentCode))
116+
await _novuProvider.SendUserMessage(message.Title, message.SubTitle, userId, message.DepartmentCode, string.Format("M{0}", message.MessageId), null);
116117
}
117118
catch (Exception ex)
118119
{
@@ -143,7 +144,7 @@ public async Task<bool> PushNotification(StandardPushMessage message, string use
143144
}
144145
try
145146
{
146-
await _novuProvider.SendUserMessage(message.Title, message.SubTitle, userId, message.DepartmentCode, string.Format("N{0}", message.MessageId), null);
147+
await _novuProvider.SendUserNotification(message.Title, message.SubTitle, userId, message.DepartmentCode, string.Format("N{0}", message.MessageId), null);
147148
}
148149
catch (Exception ex)
149150
{

Providers/Resgrid.Providers.Messaging/NovuProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ private async Task<bool> SendNotification(string title, string body, string reci
231231
{
232232
subject = title,
233233
body = body,
234+
id = eventCode
234235
},
235236
overrides = new
236237
{

0 commit comments

Comments
 (0)