2013-06-21 13:34:59 -07:00
|
|
|
package DDG::Goodie::HelpLine;
|
2014-08-20 11:45:33 -07:00
|
|
|
# ABSTRACT: Provide localized suicide intervention phone numbers.
|
2013-06-21 12:43:57 -07:00
|
|
|
|
2015-02-22 12:09:29 -08:00
|
|
|
use strict;
|
2013-06-21 12:43:57 -07:00
|
|
|
use DDG::Goodie;
|
|
|
|
|
2015-05-29 15:18:03 -07:00
|
|
|
use YAML::XS 'LoadFile';
|
2013-06-24 11:33:36 -07:00
|
|
|
|
2016-02-23 08:20:37 -08:00
|
|
|
my $triggers = LoadFile(share('triggers.yml'));
|
2014-10-06 06:13:35 -07:00
|
|
|
|
|
|
|
triggers any => @$triggers;
|
2013-06-24 11:33:36 -07:00
|
|
|
|
2013-06-21 12:43:57 -07:00
|
|
|
zci answer_type => 'helpline';
|
2014-09-27 06:42:57 -07:00
|
|
|
zci is_cached => 0;
|
2013-06-21 12:43:57 -07:00
|
|
|
|
2016-02-23 08:20:37 -08:00
|
|
|
my $helplines = LoadFile(share('helplines.yml'));
|
2014-10-06 06:13:35 -07:00
|
|
|
my %suicide_phrases = map { $_ => 1 } @$triggers;
|
2013-06-21 12:43:57 -07:00
|
|
|
|
2013-06-24 11:33:36 -07:00
|
|
|
handle query_lc => sub {
|
|
|
|
my $query = shift;
|
2014-01-23 14:13:20 -08:00
|
|
|
|
|
|
|
return unless exists $suicide_phrases{$query};
|
|
|
|
|
|
|
|
# Display the result.
|
2014-10-06 06:13:35 -07:00
|
|
|
my $helpline = $helplines->{$loc->country_code};
|
|
|
|
return unless $helpline;
|
|
|
|
|
|
|
|
my @contacts = @{$helpline->{contacts}};
|
2016-05-22 09:00:30 -07:00
|
|
|
my $numbers_data = {map { $_->{name} => $_->{phone}; } @contacts};
|
2014-10-06 06:13:35 -07:00
|
|
|
my $operation = '24 Hour Suicide Hotline';
|
|
|
|
$operation .= 's' if (scalar @contacts > 1);
|
|
|
|
$operation .= ' in ' . $helpline->{display_country};
|
2016-05-18 09:53:43 -07:00
|
|
|
|
2016-06-06 09:13:05 -07:00
|
|
|
return "$operation",
|
2016-05-22 09:00:30 -07:00
|
|
|
structured_answer => {
|
2016-05-15 10:25:20 -07:00
|
|
|
data => {
|
2016-05-18 09:53:43 -07:00
|
|
|
title => $operation,
|
2016-05-22 09:00:30 -07:00
|
|
|
record_data => $numbers_data,
|
2016-05-15 10:25:20 -07:00
|
|
|
},
|
|
|
|
templates => {
|
2016-05-18 09:53:43 -07:00
|
|
|
group => "list",
|
|
|
|
options => {
|
2016-05-22 09:00:30 -07:00
|
|
|
content => 'record',
|
2016-05-18 09:53:43 -07:00
|
|
|
}
|
2016-05-15 10:25:20 -07:00
|
|
|
}
|
2016-05-18 09:53:43 -07:00
|
|
|
};
|
2013-06-21 12:43:57 -07:00
|
|
|
};
|
|
|
|
|
2013-06-21 13:34:59 -07:00
|
|
|
1;
|