# Type: Input and output # Category: Configuration # Description: Asks for approval before asking other questions # Dialog: Hi -> -> MainProject -> MainIssue -> MainActivity # Uses: YesNo # Timeout: 5 min # Author: Andriy Lesyuk use Orangutan::User; new Orangutan::Context( request => sub { my ($context, $user) = @_; if ($user->IsSet(USER_UNCONFIGURED)) { my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->InsertForeignHandler($context, 300); $user->Unset(USER_UNCONFIGURED); return Orangutan::Context::Random( 'I have some questions... Can we talk now?', 'I have a couple of questions... Can we talk now?' ); } else { return 'Damn! Wanted to ask something but forgot what exactly...'; } } else { return undef; } }, response => [ '^(?:let\'s talk )?later!*\.*$' ], handler => sub { my ($context, $user, $item, $answer) = @_; if (($item == -1) && ($answer eq 'Y')) { if (!$user->GetProject) { my $mainproject = $user->GetResponse('MainProject'); if ($mainproject) { $user->AddRequest($mainproject); } } else { $user->SendMessage([ 'Well... I was going to ask about your main project... But you already set it.', 'Seems you have already answered the questions I was going to ask...' ]); } } else { $main::config->Context('Ok')->Tell($user); } my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->RemoveForeignHandler($context); } return undef; }, ontimeout => sub { my ($context, $user) = @_; $user->SendMessage('Ok...'); my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->RemoveForeignHandler($context); } }, timeout => 300, weight => sub { my ($context, $user) = @_; if ($user->IsSet(USER_UNCONFIGURED)) { return ( 10, -10, undef ); } else { return ( undef, undef, undef ); } } ); # kate: syntax perl