Skip to content

Commit

Permalink
Fixed a caller id issue for trunks (#9)
Browse files Browse the repository at this point in the history
- Fixed an issue where some mis configured customer PBX systems will send out a caller id with 011 instead of + or sending as NPAN or 1NPAN.
- Bump version to 0.3.3
  • Loading branch information
pramsky authored May 28, 2024
1 parent 4130776 commit 78ee867
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
68 changes: 37 additions & 31 deletions lib/numerus/classifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -265,29 +265,35 @@ defmodule Numerus.Classifier do
"""
@spec metadata(did :: bitstring()) :: {:ok, map()} | {:error, term()}
def metadata(did) when is_bitstring(did) do
case classify(did) do
# some trunking customers send out bs caller id such as using
# 011 instead of + while attempting to send an E164 caller id
#
# Lets just convert all leading 011 to + just to be sure
ndid = String.replace(did, ~r/^011/, "+")

case classify(ndid) do
{:ok, _} ->
case extract(did) do
case extract(ndid) do
{:ok, extracted} ->
case extracted["countrycode"] do
"1" ->
# this is a north american number under the NADP
case split(did) do
case split(ndid) do
{:error, _} -> {:error, :invalid_number}
{:ok, number} ->
case Numerus.Nadp.metadata(number["area_code"]) do
{:error, _} ->
# check to see if this number is tollfree
case Numerus.is_tollfree?(did) do
case Numerus.is_tollfree?(ndid) do
false -> {:error, :invalid_number}
true ->
result =
%{
"did" => did,
"normalized"=> Numerus.normalize(did),
"formatted" => Formatter.format(did),
"tollstate" => tollstate(did),
"region" => region(did),
"did" => ndid,
"normalized"=> Numerus.normalize(ndid),
"formatted" => Formatter.format(ndid),
"tollstate" => tollstate(ndid),
"region" => region(ndid),
"meta" => %{
"country" => %{
"name" => "",
Expand All @@ -304,11 +310,11 @@ defmodule Numerus.Classifier do
{:ok, meta} ->
result =
%{
"did" => did,
"normalized"=> Numerus.normalize(did),
"formatted" => Formatter.format(did),
"tollstate" => tollstate(did),
"region" => region(did),
"did" => ndid,
"normalized"=> Numerus.normalize(ndid),
"formatted" => Formatter.format(ndid),
"tollstate" => tollstate(ndid),
"region" => region(ndid),
"meta" => %{
"country" => %{
"name" => meta["country_name"],
Expand All @@ -329,11 +335,11 @@ defmodule Numerus.Classifier do
{:ok, meta} ->
result =
%{
"did" => did,
"normalized"=> Numerus.normalize(did),
"formatted" => Formatter.format(did),
"tollstate" => tollstate(did),
"region" => region(did),
"did" => ndid,
"normalized"=> Numerus.normalize(ndid),
"formatted" => Formatter.format(ndid),
"tollstate" => tollstate(ndid),
"region" => region(ndid),
"meta" => %{
"country" => %{
"name" => meta["name"],
Expand All @@ -347,15 +353,15 @@ defmodule Numerus.Classifier do
end
{:error, _} ->
# maybe this is an emergency or service number
case Enum.member?(service_dids(), did) do
case Enum.member?(service_dids(), ndid) do
true ->
result =
%{
"did" => did,
"normalized" => did,
"formatted" => did,
"tollstate" => tollstate(did),
"region" => region(did),
"did" => ndid,
"normalized" => ndid,
"formatted" => ndid,
"tollstate" => tollstate(ndid),
"region" => region(ndid),
"meta" => %{
"country" => %{
"name" => "UNITED STATES",
Expand All @@ -366,15 +372,15 @@ defmodule Numerus.Classifier do
}

{:ok, result}
false -> case Numerus.is_shortcode?(did) do
false -> case Numerus.is_shortcode?(ndid) do
true ->
result =
%{
"did" => did,
"normalized" => did,
"formatted" => did,
"tollstate" => tollstate(did),
"region" => region(did),
"did" => ndid,
"normalized" => ndid,
"formatted" => ndid,
"tollstate" => tollstate(ndid),
"region" => region(ndid),
"meta" => %{
"country" => %{
"name" => "UNITED STATES",
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Numerus.MixProject do
def project do
[
app: :numerus,
version: "0.3.2",
version: "0.3.3",
elixir: "~> 1.13",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down

0 comments on commit 78ee867

Please sign in to comment.