3 # Copyright 2007 Liblime
4 # Copyright 2015 Biblibre
5 # Copyright 2016 Catalyst
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 C4::SMS - send SMS messages
28 my $success = C4::SMS->send_sms({ message => 'This is my text message',
29 destination => '212-555-1212' });
33 A wrapper for SMS::Send.
35 Can use a yaml file for config, the path to which is in the koha-conf.xml
36 <sms_send_config>__KOHA_CONF_DIR__/sms_send/</sms_send_config>
38 Each file needs to be in the format of
39 __KOHA_CONF_DIR__/sms_send/<driver>.yaml
41 For example for SMS::Send::UK::Kapow the config would be
43 /etc/koha/sites/instancename/sms_send/UK/Kapow.yaml for package install
45 /etc/koha/sms_send/UK/Kapow.yaml for tarball
47 A underscore character is prepended to all parameter names so they are
48 treated as driver-specific options (leading underscore must not appear
65 # The previous implmentation used username and password.
66 # our $user = C4::Context->config('smsuser');
67 # our $pwd = C4::Context->config('smspass');
77 foreach my $required_parameter ( qw( message destination ) ) {
78 # Should I warn in some way?
79 return unless defined $params->{ $required_parameter };
82 eval { require SMS
::Send
; };
84 # we apparently don't have SMS::Send. Return a failure.
88 # This allows the user to override the driver. See SMS::Send::Test
89 my $driver = exists $params->{'driver'} ?
$params->{'driver'} : $self->driver();
90 return unless $driver;
95 my $subpath = $driver;
99 File
::Spec
->catfile( C4
::Context
->config('sms_send_config'), $subpath )
102 if ( -f
$conf_file ) {
104 my $conf = YAML
::LoadFile
( $conf_file );
105 %args = map { q{_} . $_ => $conf->{$_} } keys %$conf;
110 $sender = SMS
::Send
->new(
112 _login
=> C4
::Context
->preference('SMSSendUsername'),
113 _password
=> C4
::Context
->preference('SMSSendPassword'),
118 $sent = $sender->send_sms(
119 to
=> $params->{destination
},
120 text
=> $params->{message
},
124 #We might die because SMS::Send $driver is not defined or the sms-number has a bad format
125 #Catch those errors and fail the sms-sending gracefully.
130 # warn 'failure' unless $sent;
141 # return 'US::SprintPCS';
142 return C4
::Context
->preference('SMSSendDriver');