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, $error ) = C4::SMS->send_sms(
30 message => 'This is my text message',
31 destination => '212-555-1212'
37 A wrapper for SMS::Send.
39 Can use a yaml file for config, the path to which is in the koha-conf.xml
40 <sms_send_config>__KOHA_CONF_DIR__/sms_send/</sms_send_config>
42 Each file needs to be in the format of
43 __KOHA_CONF_DIR__/sms_send/<driver>.yaml
45 For example for SMS::Send::UK::Kapow the config would be
47 /etc/koha/sites/instancename/sms_send/UK/Kapow.yaml for package install
49 /etc/koha/sms_send/UK/Kapow.yaml for tarball
51 A underscore character is prepended to all parameter names so they are
52 treated as driver-specific options (leading underscore must not appear
69 # The previous implmentation used username and password.
70 # our $user = C4::Context->config('smsuser');
71 # our $pwd = C4::Context->config('smspass');
81 foreach my $required_parameter ( qw( message destination ) ) {
82 # Should I warn in some way?
83 return unless defined $params->{ $required_parameter };
86 eval { require SMS::Send; };
88 # we apparently don't have SMS::Send. Return a failure.
92 # This allows the user to override the driver. See SMS::Send::Test
93 my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver();
94 return ( undef, 'SMS_SEND_DRIVER_MISSING' ) unless $driver;
98 my $subpath = $driver;
101 # Extract additional SMS::Send arguments from file
102 my $sms_send_config = C4::Context->config('sms_send_config');
103 my $conf_file = defined $sms_send_config
104 ? File::Spec->catfile( $sms_send_config, $subpath )
106 $conf_file .= q{.yaml};
109 if ( -f $conf_file ) {
111 my $conf = YAML::XS::LoadFile( $conf_file );
112 %args = map { q{_} . $_ => $conf->{$_} } keys %$conf;
115 # Extract additional SMS::Send arguments from the syspref
116 # Merge with any arguments from file with syspref taking precedence
117 if ( C4::Context->preference('SMSSendAdditionalOptions') ) {
118 my $sms_send_config_syspref = C4::Context->yaml_preference('SMSSendAdditionalOptions');
119 %args = ( %args, %$sms_send_config_syspref ) if $sms_send_config_syspref;
124 $sender = SMS::Send->new(
126 _login => C4::Context->preference('SMSSendUsername'),
127 _password => C4::Context->preference('SMSSendPassword'),
132 $sent = $sender->send_sms(
133 to => $params->{destination},
134 text => $params->{message},
138 #We might die because SMS::Send $driver is not defined or the sms-number has a bad format
139 #Catch those errors and fail the sms-sending gracefully.
142 return ( undef, $@ );
144 # warn 'failure' unless $sent;
155 # return 'US::SprintPCS';
156 return C4::Context->preference('SMSSendDriver');