diff --git a/Core/Resgrid.Config/ChatConfig.cs b/Core/Resgrid.Config/ChatConfig.cs index 6a3563af..e5aa6cec 100644 --- a/Core/Resgrid.Config/ChatConfig.cs +++ b/Core/Resgrid.Config/ChatConfig.cs @@ -13,6 +13,7 @@ public static class ChatConfig public static string NovuUnitFcmProviderId = ""; public static string NovuUnitApnsProviderId = ""; public static string NovuResponderFcmProviderId = ""; + public static string NovuResponderApnsProviderId = ""; public static string NovuDispatchUnitWorkflowId = "unit-dispatch"; public static string NovuDispatchUserWorkflowId = "user-dispatch"; public static string NovuMessageUserWorkflowId = "user-message"; diff --git a/Core/Resgrid.Model/Providers/IOutboundVoiceProvider.cs b/Core/Resgrid.Model/Providers/IOutboundVoiceProvider.cs index bed17395..60877203 100644 --- a/Core/Resgrid.Model/Providers/IOutboundVoiceProvider.cs +++ b/Core/Resgrid.Model/Providers/IOutboundVoiceProvider.cs @@ -1,7 +1,9 @@ -namespace Resgrid.Model.Providers +using System.Threading.Tasks; + +namespace Resgrid.Model.Providers { public interface IOutboundVoiceProvider { - void CommunicateCall(string phoneNumber, UserProfile profile, Call call); + Task CommunicateCallAsync(string phoneNumber, UserProfile profile, Call call); } -} \ No newline at end of file +} diff --git a/Core/Resgrid.Services/CommunicationService.cs b/Core/Resgrid.Services/CommunicationService.cs index 1424c64d..68a0d3e6 100644 --- a/Core/Resgrid.Services/CommunicationService.cs +++ b/Core/Resgrid.Services/CommunicationService.cs @@ -208,7 +208,7 @@ public async Task SendCallAsync(Call call, CallDispatch dispatch, string d { if (!Config.SystemBehaviorConfig.DoNotBroadcast || Config.SystemBehaviorConfig.BypassDoNotBroadcastDepartments.Contains(departmentId)) - _outboundVoiceProvider.CommunicateCall(departmentNumber, profile, call); + await _outboundVoiceProvider.CommunicateCallAsync(departmentNumber, profile, call); } catch (Exception ex) { diff --git a/Providers/Resgrid.Providers.Messaging/NovuProvider.cs b/Providers/Resgrid.Providers.Messaging/NovuProvider.cs index 3adbbbd3..21854657 100644 --- a/Providers/Resgrid.Providers.Messaging/NovuProvider.cs +++ b/Providers/Resgrid.Providers.Messaging/NovuProvider.cs @@ -1,12 +1,13 @@ -using System.Text; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Novu.Domain.Models.Subscribers; +using RabbitMQ.Client; using Resgrid.Config; using Resgrid.Framework; using Resgrid.Model; using Resgrid.Model.Providers; using Resgrid.Providers.Bus.Models; +using System.Text; namespace Resgrid.Providers.Messaging @@ -196,7 +197,7 @@ public async Task UpdateUserSubscriberFcm(string userId, string code, stri public async Task UpdateUserSubscriberApns(string userId, string code, string token) { - return await UpdateSubscriberApns($"{code}_User_{userId}", token, ChatConfig.NovuUnitApnsProviderId); + return await UpdateSubscriberApns($"{code}_User_{userId}", token, ChatConfig.NovuResponderApnsProviderId); } public async Task UpdateUnitSubscriberFcm(int unitId, string code, string token) @@ -221,7 +222,7 @@ private async Task SendNotification(string title, string body, string reci httpClient.DefaultRequestHeaders.Add("Authorization", $"ApiKey {ChatConfig.NovuSecretKey}"); httpClient.DefaultRequestHeaders.Add("idempotency-key", Guid.NewGuid().ToString()); - string androidChannelName = GetAndroidChannelName(eventCode); + string channelName = GetAndroidChannelName(eventCode); // Build request payload var payload = new { @@ -230,9 +231,6 @@ private async Task SendNotification(string title, string body, string reci { subject = title, body = body, - //inAppAvatar - //arrowImage - }, overrides = new { @@ -240,14 +238,14 @@ private async Task SendNotification(string title, string body, string reci { android = new { - priority = androidChannelName == "calls" ? "high" : "normal", + priority = channelName == "calls" ? "high" : "normal", notification = new { channelId = type, defaultSound = true, - sticky = androidChannelName == "calls" ? true : false, + sticky = channelName == "calls" ? true : false, //priority = androidChannelName == "calls" ? 5 : 3, - priority = androidChannelName == "calls" ? "max" : "default", + notification_priority = channelName == "calls" ? "PRIORITY_MAX" : "PRIORITY_DEFAULT", }, data = new { @@ -256,15 +254,22 @@ private async Task SendNotification(string title, string body, string reci eventCode = eventCode, type = type } - }//, - //data = new - //{ - // title = title, - // message = body, - // eventCode = eventCode, - // type = type - //} - } + }, + }, + apns = new + { + badge = count, + sound = new + { + name = GetSoundFileNameFromType(Platforms.iOS, type), + critical = channelName == "calls" ? 1 : 0, + volume = 1.0f + }, + type = type, + category = channelName, + eventCode = eventCode, + }, + }, to = new[]{ new { @@ -272,13 +277,12 @@ private async Task SendNotification(string title, string body, string reci }}, }; + var payloadString = JsonConvert.SerializeObject(payload); var content = new StringContent( - JsonConvert.SerializeObject(payload, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), + payloadString, Encoding.UTF8, "application/json"); - - var result = await httpClient.PostAsync("v1/events/trigger", content); return result.IsSuccessStatusCode; @@ -317,53 +321,31 @@ private string GetSoundFileNameFromType(Platforms platform, string type) { if (type == ((int)PushSoundTypes.CallEmergency).ToString()) { - if (platform == Platforms.iOS) - return "callemergency.caf"; - return "callemergency.wav"; } else if (type == ((int)PushSoundTypes.CallHigh).ToString()) - { - if (platform == Platforms.iOS) - return "callhigh.caf"; - - return "callhigh.mp3"; + return "callhigh.wav"; } else if (type == ((int)PushSoundTypes.CallMedium).ToString()) { - if (platform == Platforms.iOS) - return "callmedium.caf"; - - return "callmedium.mp3"; + return "callmedium.wav"; } else if (type == ((int)PushSoundTypes.CallLow).ToString()) { - if (platform == Platforms.iOS) - return "calllow.caf"; - - return "calllow.mp3"; + return "calllow.wav"; } else if (type == ((int)PushSoundTypes.Notifiation).ToString()) { - if (platform == Platforms.iOS) - return "notification.caf"; - - return "notification.mp3"; + return "notification.wav"; } else if (type == ((int)PushSoundTypes.Message).ToString()) { - if (platform == Platforms.iOS) - return "message.caf"; - - return "message.mp3"; + return "message.wav"; } else { - if (platform == Platforms.iOS) - return $"{type}.caf"; - - return $"{type}.mp3"; + return $"{type}.wav"; } } diff --git a/Providers/Resgrid.Providers.Number/OutboundVoiceProvider.cs b/Providers/Resgrid.Providers.Number/OutboundVoiceProvider.cs index 022f61a6..204983aa 100644 --- a/Providers/Resgrid.Providers.Number/OutboundVoiceProvider.cs +++ b/Providers/Resgrid.Providers.Number/OutboundVoiceProvider.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using Resgrid.Model; using Resgrid.Model.Providers; using Twilio; @@ -11,15 +12,15 @@ namespace Resgrid.Providers.NumberProvider { public class OutboundVoiceProvider : IOutboundVoiceProvider { - public void CommunicateCall(string phoneNumber, UserProfile profile, Call call) + public async Task CommunicateCallAsync(string phoneNumber, UserProfile profile, Call call) { if (profile == null) - return; + return false; TwilioClient.Init(Config.NumberProviderConfig.TwilioAccountSid, Config.NumberProviderConfig.TwilioAuthToken); if (!profile.VoiceForCall) - return; + return false; string number = phoneNumber; @@ -38,7 +39,8 @@ public void CommunicateCall(string phoneNumber, UserProfile profile, Call call) options.Method = "GET"; //options.IfMachine = "Continue"; - var phoneCall = CallResource.Create(options); + var phoneCall = await CallResource.CreateAsync(options); + return true; } } @@ -51,9 +53,12 @@ public void CommunicateCall(string phoneNumber, UserProfile profile, Call call) options.Method = "GET"; //options.IfMachine = "Continue"; - var phoneCall = CallResource.Create(options); + var phoneCall = await CallResource.CreateAsync(options); + return true; } } + + return false; } } }