From 54d36a449b6ee197469dee5d669a6848314affe1 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Wed, 23 Sep 2015 16:31:26 +0300 Subject: [PATCH] Bug 14767: (follow-up) Use Unicode-parameter only when needed This patch makes Labyrintti driver use Unicode parameter only when required. In most cases in our local library we are fine with GSM 03.38. We will check if data is lost when comparing the decoded gsm0338 encoded message to the original message. Add it as optional feature in koha-conf - smsProviders - labyrintti - Unicode. To turn it on, set the value to "yes". For statistics, store the result in "metadata" field of message_queue if the message was sent as UTF-16. We also make a small fix to the response protocol since it is not in sync with what Labyrintti expects. Their delivery report wants a 200 OK response, not 201 or 204. --- Koha/REST/V1/Messages/Reports.pm | 4 ++-- SMS/Send/Labyrintti/Driver.pm | 21 +++++++++++++++++---- api/v1/swagger.json | 10 ++-------- etc/koha-conf.xml | 7 ++++++- t/db_dependent/Api/V1/Messages.pm | 35 ++--------------------------------- 5 files changed, 29 insertions(+), 48 deletions(-) diff --git a/Koha/REST/V1/Messages/Reports.pm b/Koha/REST/V1/Messages/Reports.pm index 5927161..514598b 100644 --- a/Koha/REST/V1/Messages/Reports.pm +++ b/Koha/REST/V1/Messages/Reports.pm @@ -28,10 +28,10 @@ sub create_labyrintti_report { status => 'failed', delivery_note => $args->{message}, }); - return $c->$cb('', 201); + return $c->$cb('', 200); } - return $c->$cb('', 204); + return $c->$cb('', 200); } 1; diff --git a/SMS/Send/Labyrintti/Driver.pm b/SMS/Send/Labyrintti/Driver.pm index 45256b5..515be0d 100644 --- a/SMS/Send/Labyrintti/Driver.pm +++ b/SMS/Send/Labyrintti/Driver.pm @@ -89,8 +89,6 @@ sub send_sms { $recipientNumber =~ s/'//g; $message =~ s/(")|(\$\()|(`)/\\"/g; #Sanitate " so it won't break the system( iconv'ed curl command ) - - my $base_url = "https://gw.labyrintti.com:28443/sendsms"; my $parameters = { 'user' => $self->{_login}, @@ -100,14 +98,29 @@ sub send_sms { 'unicode' => 'yes', }; + # check if we need to use unicode + # -> if unicode => yes, maxlength for 1 sms = 70 chars + # -> else maxlenght = 160 chars (140 bytes, GSM 03.38) + my $gsm0388 = decode("gsm0338",encode("gsm0338", $message)); + + if ($message ne $gsm0388 and C4::Context->config('smsProviders')->{'labyrintti'}->{'Unicode'} eq "yes"){ + $parameters->{'unicode'} = 'yes'; + C4::Letters::UpdateQueuedMessage({ + message_id => $params->{_message_id}, + metadata => 'UTF-16', + }); + } else { + $parameters->{'unicode'} = 'no'; + } + my $report_url = C4::Context->config('smsProviders')->{'labyrintti'}->{'reportUrl'}; if ($report_url) { my $msg_id = $params->{_message_id}; $report_url =~ s/\{messagenumber\}/$msg_id/g; $parameters->{'report'} = $report_url; } - - my $lwpcurl = LWP::Curl->new(auto_encode => 0); + + my $lwpcurl = LWP::Curl->new(); my $return = $lwpcurl->post($base_url, $parameters); if ($lwpcurl->{retcode} == 6) { diff --git a/api/v1/swagger.json b/api/v1/swagger.json index aeff614..6b70f83 100644 --- a/api/v1/swagger.json +++ b/api/v1/swagger.json @@ -537,14 +537,8 @@ "application/json" ], "responses": { - "201": { - "description": "Response for creating a new report. Required status ERROR", - "schema": { - "type": "string" - } - }, - "204": { - "description": "Response for receiving delivery report with status OK", + "200": { + "description": "Response for receiving the report.", "schema": { "type": "string" } diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml index e56c6f0..7a9f725 100644 --- a/etc/koha-conf.xml +++ b/etc/koha-conf.xml @@ -151,12 +151,17 @@ __PAZPAR2_TOGGLE_XML_POST__ + + diff --git a/t/db_dependent/Api/V1/Messages.pm b/t/db_dependent/Api/V1/Messages.pm index df4190a..ddbfc43 100644 --- a/t/db_dependent/Api/V1/Messages.pm +++ b/t/db_dependent/Api/V1/Messages.pm @@ -273,38 +273,7 @@ sub post_n_reportlabyrintti404 { return 1; } -sub post_n_reportlabyrintti204 { - my ($class, $restTest, $driver) = @_; - my $testContext = $restTest->get_testContext(); - my $activeUser = $restTest->get_activeBorrower(); - my $path = $restTest->get_routePath(); - - #Create the test context. - my $messages = t::lib::TestObjects::MessageQueueFactory->createTestGroup( - { - subject => "The quick brown fox", - content => "Jumps over the lazy dog.", - cardnumber => $activeUser->{'_result'}->{'_column_data'}->{cardnumber}, - message_transport_type => 'sms', - from_address => '11A001@example.com', - }, undef, $testContext, undef, undef); - - my $messagenumber = $messages->{'11A001@example.com'}->{message_id}; - $path =~ s/\{messagenumber\}/$messagenumber/; - $driver->post_ok( - $path => { Accept => 'application/x-www-form-urlencoded'} => - form => { - status => "OK", - message => "Message delivery succesful", - } - ); - $driver->status_is(204); - - t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); - return 1; -} - -sub post_n_reportlabyrintti201 { +sub post_n_reportlabyrintti200 { my ($class, $restTest, $driver) = @_; my $testContext = $restTest->get_testContext(); my $activeUser = $restTest->get_activeBorrower(); @@ -329,7 +298,7 @@ sub post_n_reportlabyrintti201 { message => "Test error delivery note", } ); - $driver->status_is(201); + $driver->status_is(200); my $message = C4::Letters::GetMessage($messagenumber); is($message->{delivery_note}, "Test error delivery note", "Delivery note for failed SMS received successfully."); -- 1.9.1