diff --git a/lib/NGCP/Panel/Controller/API/SMS.pm b/lib/NGCP/Panel/Controller/API/SMS.pm index cedf5b88ea..204a7efe01 100644 --- a/lib/NGCP/Panel/Controller/API/SMS.pm +++ b/lib/NGCP/Panel/Controller/API/SMS.pm @@ -133,13 +133,7 @@ sub create_item { } my $error_msg = ""; - - my $coding; - if(NGCP::Panel::Utils::Utf8::is_within_ascii($resource->{text})) { - $coding = 0; - } else { - $coding = 2; - } + my $coding = NGCP::Panel::Utils::SMS::get_coding($resource->{text}); NGCP::Panel::Utils::SMS::send_sms( c => $c, caller => $resource->{caller}, diff --git a/lib/NGCP/Panel/Utils/SMS.pm b/lib/NGCP/Panel/Utils/SMS.pm index 4fa3668822..ed6a454fec 100644 --- a/lib/NGCP/Panel/Utils/SMS.pm +++ b/lib/NGCP/Panel/Utils/SMS.pm @@ -9,6 +9,24 @@ use Module::Load::Conditional qw/can_load/; use NGCP::Panel::Utils::Utf8; +sub get_coding { + my $text = shift; + + # if unicode, we have to use utf8 encoding, limiting our + # text length to 70; otherwise send as default + # encoding, allowing 160 chars + + my $coding; + if(NGCP::Panel::Utils::Utf8::is_within_ascii($text) || + NGCP::Panel::Utils::Utf8::is_within_latin1($text)) { + $coding = 0; + } else { + $coding = 2; + } + + return $coding; +} + sub send_sms { my (%args) = @_; my $c = $args{c}; @@ -23,14 +41,7 @@ sub send_sms { } unless(defined $coding) { - # if unicode, we have to use utf8 encoding, limiting our - # text length to 70; otherwise send as default - # encoding, allowing 160 chars - if(NGCP::Panel::Utils::Utf8::is_within_ascii($text)) { - $coding = 0; - } else { - $coding = 2; - } + $coding = get_coding($text); } my $schema = $c->config->{sms}{schema};