|
Lines 36-41
use strict;
Link Here
|
| 36 |
use warnings; |
36 |
use warnings; |
| 37 |
|
37 |
|
| 38 |
use C4::Context; |
38 |
use C4::Context; |
|
|
39 |
use File::Spec; |
| 39 |
|
40 |
|
| 40 |
|
41 |
|
| 41 |
|
42 |
|
|
Lines 70-90
sub send_sms {
Link Here
|
| 70 |
my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver(); |
71 |
my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver(); |
| 71 |
return unless $driver; |
72 |
return unless $driver; |
| 72 |
|
73 |
|
| 73 |
# warn "using driver: $driver to send message to $params->{'destination'}"; |
|
|
| 74 |
|
74 |
|
| 75 |
my ($sent, $sender); |
75 |
my ($sent, $sender); |
|
|
76 |
|
| 77 |
my $subpath = $driver; |
| 78 |
$subpath =~ s|::|/|; |
| 79 |
|
| 80 |
my $conf_file = File::Spec->catfile( |
| 81 |
C4::Context->config('installdir'), |
| 82 |
'etc', 'sms', 'driver', $subpath |
| 83 |
) . q{.yaml}; |
| 84 |
my %args; |
| 85 |
if ( -f $conf_file ) { |
| 86 |
require YAML; |
| 87 |
my $conf = YAML::LoadFile( $conf_file ); |
| 88 |
%args = map { q{_} . $_ => $conf->{$_} } keys %$conf; |
| 89 |
} |
| 90 |
|
| 76 |
eval { |
91 |
eval { |
| 77 |
# Create a sender |
92 |
# Create a sender |
| 78 |
$sender = SMS::Send->new( $driver, |
93 |
$sender = SMS::Send->new( |
| 79 |
_login => C4::Context->preference('SMSSendUsername'), |
94 |
$driver, |
| 80 |
_password => C4::Context->preference('SMSSendPassword'), |
95 |
_login => C4::Context->preference('SMSSendUsername'), |
| 81 |
); |
96 |
_password => C4::Context->preference('SMSSendPassword'), |
| 82 |
|
97 |
%args, |
|
|
98 |
); |
| 99 |
|
| 83 |
# Send a message |
100 |
# Send a message |
| 84 |
$sent = $sender->send_sms( to => $params->{'destination'}, |
101 |
$sent = $sender->send_sms( |
| 85 |
text => $params->{'message'}, |
102 |
to => $params->{destination}, |
| 86 |
); |
103 |
text => $params->{message}, |
|
|
104 |
); |
| 87 |
}; |
105 |
}; |
|
|
106 |
|
| 88 |
#We might die because SMS::Send $driver is not defined or the sms-number has a bad format |
107 |
#We might die because SMS::Send $driver is not defined or the sms-number has a bad format |
| 89 |
#Catch those errors and fail the sms-sending gracefully. |
108 |
#Catch those errors and fail the sms-sending gracefully. |
| 90 |
if ($@) { |
109 |
if ($@) { |
| 91 |
- |
|
|