Permalink
Browse files

Quick fix for phone numbers

  • Loading branch information...
Nick Craver
Nick Craver committed Dec 7, 2018
1 parent 7fec06b commit 1f0a77038496bac38d64614f0119e6f3fdb3734b
Showing with 23 additions and 6 deletions.
  1. +23 −6 Opserver.Core/Data/Pagerduty/PagerDutyAPI.OnCall.cs
@@ -151,18 +151,35 @@ public string FormattedAddress
{
get
{
var sb = StringBuilderCache.Get();
if (CountryCode.HasValue)
{
sb.Append("+").Append(CountryCode).Append(" ");
}
switch (Type)
{
case "sms_contact_method":
case "phone_contact_method":
// I'm sure no one outside the US uses this...
// we will have to fix this soon
// NOTE: C# port of Google's Phone number formatting Library can be found here:
// https://www.nuget.org/packages/libphonenumber-csharp/
return Regex.Replace(Address, @"(\d{3})(\d{3})(\d{4})", "$1-$2-$3");
switch (CountryCode)
{
case 1: // US
sb.Append(Regex.Replace(Address, @"(\d{3})(\d{3})(\d{4})", "($1) $2-$3"));
break;
case 61: // AU
sb.Append(Regex.Replace(Address, @"(\d{4})(\d{4})", "$1 $2"));
break;
// Do we want to increase our deployment payload by 50% to handle phone number formatting here?
// The options are crazy bad, so just doing a little for the moment...
default:
sb.Append(Address);
break;
}
break;
default:
return Address;
sb.Append(Address);
break;
}
return sb.ToStringRecycle();
}
}

0 comments on commit 1f0a770

Please sign in to comment.