Created
August 24, 2016 16:17
-
-
Save reneeb/375bfc2c04232c14417315c71833209e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Self->{'PostMaster::PreFilterModule'}->{'9931313-CustomerUser'} = { | |
Module => 'Kernel::System::PostMaster::Filter::CustomerByPhone', | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- | |
# Kernel/System/PostMaster/Filter/CustomerByPhone.pm - the global PostMaster module for OTRS | |
# Copyright (C) 2016 Perl-Services.de, http://perl-services.de | |
# -- | |
# This software comes with ABSOLUTELY NO WARRANTY. For details, see | |
# the enclosed file COPYING for license information (AGPL). If you | |
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt. | |
# -- | |
package Kernel::System::PostMaster::Filter::CustomerByPhone; | |
use strict; | |
our @ObjectDependencies = qw( | |
Kernel::System::Log | |
Kernel::System::CustomerUser | |
); | |
sub new { | |
my $Type = shift; | |
my %Param = @_; | |
# allocate new hash for object | |
my $Self = {}; | |
bless( $Self, $Type ); | |
return $Self; | |
} | |
sub Run { | |
my ( $Self, %Param ) = @_; | |
my $LogObject = $Kernel::OM->Get('Kernel::System::Log'); | |
my $CustomerUserObject = $Kernel::OM->Get('Kernel::System::CustomerUser'); | |
for my $Needed (qw(JobConfig GetParam)) { | |
if ( !$Param{$Needed} ) { | |
$LogObject->Log( | |
Priority => 'error', | |
Message => "Need $Needed!", | |
); | |
return; | |
} | |
} | |
my %Mail = %{ $Param{GetParam} || {} }; | |
return 1 if $Mail{From} !~ m{voicemail\@}; | |
my ($PhoneNumber) = $Mail{Subject} =~ m{<([0-9+]+)>}; | |
return 1 if !$PhoneNumber; | |
my %CustomerUsers = $CustomerUserObject->CustomerSearch( | |
Search => $PhoneNumber, | |
Valid => 1, | |
Limit => 5, | |
); | |
if ( !%CustomerUsers ) { | |
$LogObject->Log( | |
Priority => 'debug', | |
Message => 'No user found', | |
); | |
return 1; | |
} | |
if ( 2 <= scalar keys %CustomerUsers ) { | |
$LogObject->Log( | |
Priority => 'debug', | |
Message => 'Ambiguous search result: Found more than one customer for ' . $PhoneNumber, | |
); | |
return 1; | |
} | |
my ($User) = keys %CustomerUsers; | |
my %CustomerUser = $CustomerUserObject->CustomerUserDataGet( | |
User => $User, | |
); | |
$Param{GetParam}->{'X-OTRS-CustomerNo'} = $CustomerUser{CustomerID}; | |
$Param{GetParam}->{'X-OTRS-CustomerUser'} = $User; | |
return 1; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment