From 7d9ab3b87aed944167d77244b00fbdd4224725e2 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 14 Nov 2024 14:30:42 +0200 Subject: Added support for SMS notifications on TS & X4. --- .../Controllers/PPCController.cs | 25 ++++++++++++++++++++++ .../Tango.MachineService/MachineServiceConfig.cs | 5 +++++ .../Properties/AssemblyInfo.cs | 2 +- .../Tango.MachineService.csproj | 9 +++++--- .../Web/Tango.MachineService/Web.config | 7 +++++- .../Web/Tango.MachineService/packages.config | 3 ++- 6 files changed, 45 insertions(+), 6 deletions(-) (limited to 'Software/Visual_Studio/Web/Tango.MachineService') diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs index 06b2fd232..d8f514c42 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/PPCController.cs @@ -25,6 +25,9 @@ using Tango.Core.Cryptography; using Tango.MachineService.Filters; using Tango.BL.DTO; using Z.EntityFramework.Plus; +using Twilio; +using Twilio.Rest.Api.V2010.Account; +using Twilio.Types; namespace Tango.MachineService.Controllers { @@ -48,6 +51,7 @@ namespace Tango.MachineService.Controllers { _pendingUploads = new List(); _pendingUpdates = new List(); + TwilioClient.Init(MachineServiceConfig.TWILIO_ACCOUNT_SID, MachineServiceConfig.TWILIO_AUTH_TOKEN); } public PPCController() @@ -830,6 +834,27 @@ namespace Tango.MachineService.Controllers #endregion + #region SMS + + [HttpPost] + [JwtTokenFilter] + public SendSMSResponse SendSMS(SendSMSRequest request) + { + var response = new SendSMSResponse(); + + if (MachineServiceConfig.TWILIO_ENABLE_SMS) + { + foreach (var phone in request.PhoneNumbers) + { + MessageResource.Create(from: MachineServiceConfig.TWILIO_FROM_NUMBER, to: new PhoneNumber(phone), body: request.Message); + } + } + + return response; + } + + #endregion + #region Version Upload [HttpPost] diff --git a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs index bdddbab8f..e8240fd46 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs @@ -25,5 +25,10 @@ namespace Tango.MachineService public static String FSE_TFS_USER_EMAIL => ConfigurationManager.AppSettings[nameof(FSE_TFS_USER_EMAIL)].ToString(); public static String SEND_GRID_API_KEY => ConfigurationManager.AppSettings[nameof(SEND_GRID_API_KEY)].ToString(); + + public static bool TWILIO_ENABLE_SMS => bool.Parse(ConfigurationManager.AppSettings[nameof(TWILIO_ENABLE_SMS)].ToString()); + public static String TWILIO_ACCOUNT_SID => ConfigurationManager.AppSettings[nameof(TWILIO_ACCOUNT_SID)].ToString(); + public static String TWILIO_AUTH_TOKEN => ConfigurationManager.AppSettings[nameof(TWILIO_AUTH_TOKEN)].ToString(); + public static String TWILIO_FROM_NUMBER => ConfigurationManager.AppSettings[nameof(TWILIO_FROM_NUMBER)].ToString(); } } \ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Web/Tango.MachineService/Properties/AssemblyInfo.cs index 131483550..5faac7b11 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Properties/AssemblyInfo.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Properties/AssemblyInfo.cs @@ -24,4 +24,4 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("3.0.22.0")] +[assembly: AssemblyVersion("3.0.23.0")] diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj index 3cb22c5b1..e011cf63c 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -182,8 +182,8 @@ ..\..\packages\Microsoft.SqlServer.SqlManagementObjects.140.17283.0\lib\net40\Microsoft.SqlServer.WmiEnum.dll - - ..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + ..\..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll ..\..\packages\Owin.1.0\lib\net40\Owin.dll @@ -269,6 +269,9 @@ ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll + + ..\..\packages\Twilio.7.6.0\lib\net35\Twilio.dll + True ..\..\packages\WebGrease.1.5.2\lib\WebGrease.dll @@ -507,7 +510,7 @@ False - + diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index 54cb322d9..8cc11ebb5 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -38,6 +38,11 @@ + + + + +