Skip to content

Commit 963535b

Browse files
authored
Merge pull request #237 from Resgrid/develop
CU-868f7hkrj Fixed Novu provider for ios and bugfix for voice.
2 parents 3a4fde6 + 16571c2 commit 963535b

File tree

5 files changed

+49
-59
lines changed

5 files changed

+49
-59
lines changed

Core/Resgrid.Config/ChatConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static class ChatConfig
1313
public static string NovuUnitFcmProviderId = "";
1414
public static string NovuUnitApnsProviderId = "";
1515
public static string NovuResponderFcmProviderId = "";
16+
public static string NovuResponderApnsProviderId = "";
1617
public static string NovuDispatchUnitWorkflowId = "unit-dispatch";
1718
public static string NovuDispatchUserWorkflowId = "user-dispatch";
1819
public static string NovuMessageUserWorkflowId = "user-message";
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
namespace Resgrid.Model.Providers
1+
using System.Threading.Tasks;
2+
3+
namespace Resgrid.Model.Providers
24
{
35
public interface IOutboundVoiceProvider
46
{
5-
void CommunicateCall(string phoneNumber, UserProfile profile, Call call);
7+
Task<bool> CommunicateCallAsync(string phoneNumber, UserProfile profile, Call call);
68
}
7-
}
9+
}

Core/Resgrid.Services/CommunicationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public async Task<bool> SendCallAsync(Call call, CallDispatch dispatch, string d
208208
{
209209

210210
if (!Config.SystemBehaviorConfig.DoNotBroadcast || Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId))
211-
_outboundVoiceProvider.CommunicateCall(departmentNumber, profile, call);
211+
await _outboundVoiceProvider.CommunicateCallAsync(departmentNumber, profile, call);
212212
}
213213
catch (Exception ex)
214214
{

Providers/Resgrid.Providers.Messaging/NovuProvider.cs

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System.Text;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
32
using Newtonsoft.Json.Linq;
43
using Novu.Domain.Models.Subscribers;
4+
using RabbitMQ.Client;
55
using Resgrid.Config;
66
using Resgrid.Framework;
77
using Resgrid.Model;
88
using Resgrid.Model.Providers;
99
using Resgrid.Providers.Bus.Models;
10+
using System.Text;
1011

1112

1213
namespace Resgrid.Providers.Messaging
@@ -196,7 +197,7 @@ public async Task<bool> UpdateUserSubscriberFcm(string userId, string code, stri
196197

197198
public async Task<bool> UpdateUserSubscriberApns(string userId, string code, string token)
198199
{
199-
return await UpdateSubscriberApns($"{code}_User_{userId}", token, ChatConfig.NovuUnitApnsProviderId);
200+
return await UpdateSubscriberApns($"{code}_User_{userId}", token, ChatConfig.NovuResponderApnsProviderId);
200201
}
201202

202203
public async Task<bool> UpdateUnitSubscriberFcm(int unitId, string code, string token)
@@ -221,7 +222,7 @@ private async Task<bool> SendNotification(string title, string body, string reci
221222
httpClient.DefaultRequestHeaders.Add("Authorization", $"ApiKey {ChatConfig.NovuSecretKey}");
222223
httpClient.DefaultRequestHeaders.Add("idempotency-key", Guid.NewGuid().ToString());
223224

224-
string androidChannelName = GetAndroidChannelName(eventCode);
225+
string channelName = GetAndroidChannelName(eventCode);
225226
// Build request payload
226227
var payload = new
227228
{
@@ -230,24 +231,21 @@ private async Task<bool> SendNotification(string title, string body, string reci
230231
{
231232
subject = title,
232233
body = body,
233-
//inAppAvatar
234-
//arrowImage
235-
236234
},
237235
overrides = new
238236
{
239237
fcm = new
240238
{
241239
android = new
242240
{
243-
priority = androidChannelName == "calls" ? "high" : "normal",
241+
priority = channelName == "calls" ? "high" : "normal",
244242
notification = new
245243
{
246244
channelId = type,
247245
defaultSound = true,
248-
sticky = androidChannelName == "calls" ? true : false,
246+
sticky = channelName == "calls" ? true : false,
249247
//priority = androidChannelName == "calls" ? 5 : 3,
250-
priority = androidChannelName == "calls" ? "max" : "default",
248+
notification_priority = channelName == "calls" ? "PRIORITY_MAX" : "PRIORITY_DEFAULT",
251249
},
252250
data = new
253251
{
@@ -256,29 +254,35 @@ private async Task<bool> SendNotification(string title, string body, string reci
256254
eventCode = eventCode,
257255
type = type
258256
}
259-
}//,
260-
//data = new
261-
//{
262-
// title = title,
263-
// message = body,
264-
// eventCode = eventCode,
265-
// type = type
266-
//}
267-
}
257+
},
258+
},
259+
apns = new
260+
{
261+
badge = count,
262+
sound = new
263+
{
264+
name = GetSoundFileNameFromType(Platforms.iOS, type),
265+
critical = channelName == "calls" ? 1 : 0,
266+
volume = 1.0f
267+
},
268+
type = type,
269+
category = channelName,
270+
eventCode = eventCode,
271+
},
272+
268273
},
269274
to = new[]{ new
270275
{
271276
subscriberId = recipientId
272277
}},
273278
};
274279

280+
var payloadString = JsonConvert.SerializeObject(payload);
275281
var content = new StringContent(
276-
JsonConvert.SerializeObject(payload, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }),
282+
payloadString,
277283
Encoding.UTF8,
278284
"application/json");
279285

280-
281-
282286
var result = await httpClient.PostAsync("v1/events/trigger", content);
283287

284288
return result.IsSuccessStatusCode;
@@ -317,53 +321,31 @@ private string GetSoundFileNameFromType(Platforms platform, string type)
317321
{
318322
if (type == ((int)PushSoundTypes.CallEmergency).ToString())
319323
{
320-
if (platform == Platforms.iOS)
321-
return "callemergency.caf";
322-
323324
return "callemergency.wav";
324325
}
325326
else if (type == ((int)PushSoundTypes.CallHigh).ToString())
326-
327327
{
328-
if (platform == Platforms.iOS)
329-
return "callhigh.caf";
330-
331-
return "callhigh.mp3";
328+
return "callhigh.wav";
332329
}
333330
else if (type == ((int)PushSoundTypes.CallMedium).ToString())
334331
{
335-
if (platform == Platforms.iOS)
336-
return "callmedium.caf";
337-
338-
return "callmedium.mp3";
332+
return "callmedium.wav";
339333
}
340334
else if (type == ((int)PushSoundTypes.CallLow).ToString())
341335
{
342-
if (platform == Platforms.iOS)
343-
return "calllow.caf";
344-
345-
return "calllow.mp3";
336+
return "calllow.wav";
346337
}
347338
else if (type == ((int)PushSoundTypes.Notifiation).ToString())
348339
{
349-
if (platform == Platforms.iOS)
350-
return "notification.caf";
351-
352-
return "notification.mp3";
340+
return "notification.wav";
353341
}
354342
else if (type == ((int)PushSoundTypes.Message).ToString())
355343
{
356-
if (platform == Platforms.iOS)
357-
return "message.caf";
358-
359-
return "message.mp3";
344+
return "message.wav";
360345
}
361346
else
362347
{
363-
if (platform == Platforms.iOS)
364-
return $"{type}.caf";
365-
366-
return $"{type}.mp3";
348+
return $"{type}.wav";
367349
}
368350
}
369351

Providers/Resgrid.Providers.Number/OutboundVoiceProvider.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using Resgrid.Model;
34
using Resgrid.Model.Providers;
45
using Twilio;
@@ -11,15 +12,15 @@ namespace Resgrid.Providers.NumberProvider
1112
{
1213
public class OutboundVoiceProvider : IOutboundVoiceProvider
1314
{
14-
public void CommunicateCall(string phoneNumber, UserProfile profile, Call call)
15+
public async Task<bool> CommunicateCallAsync(string phoneNumber, UserProfile profile, Call call)
1516
{
1617
if (profile == null)
17-
return;
18+
return false;
1819

1920
TwilioClient.Init(Config.NumberProviderConfig.TwilioAccountSid, Config.NumberProviderConfig.TwilioAuthToken);
2021

2122
if (!profile.VoiceForCall)
22-
return;
23+
return false;
2324

2425
string number = phoneNumber;
2526

@@ -38,7 +39,8 @@ public void CommunicateCall(string phoneNumber, UserProfile profile, Call call)
3839
options.Method = "GET";
3940
//options.IfMachine = "Continue";
4041

41-
var phoneCall = CallResource.Create(options);
42+
var phoneCall = await CallResource.CreateAsync(options);
43+
return true;
4244
}
4345
}
4446

@@ -51,9 +53,12 @@ public void CommunicateCall(string phoneNumber, UserProfile profile, Call call)
5153
options.Method = "GET";
5254
//options.IfMachine = "Continue";
5355

54-
var phoneCall = CallResource.Create(options);
56+
var phoneCall = await CallResource.CreateAsync(options);
57+
return true;
5558
}
5659
}
60+
61+
return false;
5762
}
5863
}
5964
}

0 commit comments

Comments
 (0)