Do not send autoresponse emails when merging tickets

Moderator: crythias

Locked
paulkoer
Znuny newbie
Posts: 2
Joined: 13 Nov 2014, 17:23
Znuny Version: 3.3.7
Real Name: Paul Koerbitz
Company: PPRO

Do not send autoresponse emails when merging tickets

Post by paulkoer »

I have created a custom PostMaster filter to merge tickets in case a customer sends a new email but still has a ticket open. For reference, I'll paste the code for this filter below.

I now have the following problem: We usually want to send an autoresponse to the customer when a new ticket is created. However, when a ticket is merged automatically we do _not_ want to send this auto-response. Is there a simple way to achieve this?

Many thanks in advance

PS: Code for the merge filter:

Code: Select all

package Kernel::System::PostMaster::MergeEagerCustomerMails;

use strict;
use warnings;

use vars qw($VERSION);
$VERSION = 0.01;

use Kernel::System::Ticket;

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    $Self->{Debug} = $Param{Debug} || 0;

    # get needed objects
    for my $Object (
        qw(ConfigObject LogObject DBObject TimeObject MainObject EncodeObject ParserObject)
        )
    {
        $Self->{$Object} = $Param{$Object} || die "Got no $Object!";
    }

    $Self->{TicketObject} = Kernel::System::Ticket->new(%Param);

    return $Self;
}

sub Run {
    my ( $Self, %Param ) = @_;
    print STDERR %Param;

    # FIXME: Not sure what is needed ...
    for my $Needed (qw(TicketID)) {
        if ( !$Param{$Needed} ) {
            $Self->{LogObject}->Log(
                Priority => 'error',
                Message  => "Need $Needed!",
            );
            return;
        }
    }
    my %GetParam = %{ $Param{GetParam} };

    # We'll only use the first 'from' address
    my ( $EmailAddress ) = $Self->{ParserObject}->SplitAddressLine(
        Line => $GetParam{From},
    );
    print STDERR $EmailAddress;

    # search existing tickets for that email address. We only take the first ticket
    # that we find and will merge with that one.
    my @TicketIDs = $Self->{TicketObject}->TicketSearch(
        Result => 'ARRAY',
        From => $EmailAddress,
        States => ['new'],
        Limit => 20,
        UserID => 1, # ???
    );

    my $TicketID;
    for ( @TicketIDs ) {
        if ( $_ != $Param{TicketID} ) {
            $TicketID = $_;
        }
    }

    if ( $TicketID ) {
        print STDERR "Found Ticket with ID: " . $TicketID;
        $Self->{TicketObject}->TicketMerge(
            MainTicketID => $TicketID,
            MergeTicketID => $Param{TicketID},
            UserID => 1, # ???
        );
    } else {
        print STDERR "Didn't found any tickets for email address " . $EmailAddress;
    }

    return 1;
}

1;
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Do not send autoresponse emails when merging tickets

Post by crythias »

set header X-OTRS-Loop=1
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
paulkoer
Znuny newbie
Posts: 2
Joined: 13 Nov 2014, 17:23
Znuny Version: 3.3.7
Real Name: Paul Koerbitz
Company: PPRO

Re: Do not send autoresponse emails when merging tickets

Post by paulkoer »

Thank you for the fast response.

this might be a stupid question, but I have a hard time figuring out _where_ in the code I need to set that header. Can I just set it in the variable

Code: Select all

GetParam
?

thank you.
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Do not send autoresponse emails when merging tickets

Post by reneeb »

Yes
Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
Locked