How to return some variables in only one variable (Invoker)

English! place to talk about development, programming and coding
Post Reply
crynof
Znuny newbie
Posts: 24
Joined: 20 Mar 2020, 20:23
Znuny Version: 6.0
Real Name: Camilo

How to return some variables in only one variable (Invoker)

Post by crynof »

Hi!, i trying to merge the content of some variables and then return them in only one variable.

I want to send a ticket data to telegram chat, and i had half resolved, but i have one problem. The predefined URL that send data to telegram allow one variable only as text.

Code: Select all

https://api.telegram.org/bot<token>/sendMessage?chat_id=<group chat id >&text=<our text>
As can you see, i can send a plain text, but I could also add a variable by placing it after ":"

Code: Select all

https://api.telegram.org/bot<token>/sendMessage?chat_id=<group chat id >&text=<our text>:TicketID
Is the only method that allow 1 variable of all avaiblables on Data array.

I was thinking of creating the return of several variables in one from the invoker controller (test.pm), such as

Code: Select all

my %merge = TicketNumber + Title.
Where merge is a new variable that contain multiple data.

How could I do that?

Thank you very much for your willingness to help me.
Cheers
skullz
Znuny superhero
Posts: 617
Joined: 24 Feb 2012, 03:58
Znuny Version: LTS and Features
Real Name: Mo Azfar
Location: Kuala Lumpur, MY
Contact:

Re: How to return some variables in only one variable (Invoker)

Post by skullz »

I assumed you already got the ticket id ? in that case, you can access another ticket attributes by

Code: Select all

	my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
	
	# get ticket content
	my %Ticket = $TicketObject->TicketGet(
        TicketID => $TicketID,
	UserID        => 1,
	DynamicFields => 0,
	Extended => 0,
    );
    
   my $text = "$Ticket{TicketNumber} ($Ticket{Title}) bla bla bla bla";
    
crynof
Znuny newbie
Posts: 24
Joined: 20 Mar 2020, 20:23
Znuny Version: 6.0
Real Name: Camilo

Re: How to return some variables in only one variable (Invoker)

Post by crynof »

skullz wrote: 05 May 2020, 20:38 I assumed you already got the ticket id ? in that case, you can access another ticket attributes by

Code: Select all

	my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
	
	# get ticket content
	my %Ticket = $TicketObject->TicketGet(
        TicketID => $TicketID,
	UserID        => 1,
	DynamicFields => 0,
	Extended => 0,
    );
    
   my $text = "$Ticket{TicketNumber} ($Ticket{Title}) bla bla bla bla";
    
Many thanks skullz, something like that is that i need.

I was thinking how to integrate this code on my code but i dont know how to return text.

In return method returns Data %Ticket Objetc, but i dont know where i should put $text variable to will be returned.

How can i adapt you example?.


My code:

Code: Select all

package Kernel::GenericInterface::Invoker::Test::Test;

#use strict;
use warnings;
use Kernel::System::Ticket;
use Kernel::System::VariableCheck qw(IsString IsStringWithData);

our $ObjectManagerDisabled = 1;

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

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

    # check needed params
    if ( !$Param{DebuggerObject} ) {
        return {
            Success      => 0,
            ErrorMessage => "Got no DebuggerObject!"
        };
    }

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

    return $Self;
}

sub PrepareRequest {
# get ticket object
	
	use Kernel::System::ObjectManager;
    local $Kernel::OM = Kernel::System::ObjectManager->new();
    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
	
	#--------------------------------------------------------------------------------
	
    my ( $Self, %Param ) = @_;
	
	my %Ticket = $TicketObject->TicketGet( TicketID => $Param{Data}->{TicketID} );
	


	return {
			Success => 1,
			Data => {
						%Ticket
					}
			};
}

sub HandleResponse {
    my ( $Self, %Param ) = @_;

    # if there was an error in the response, forward it
    if ( !$Param{ResponseSuccess} ) {
        return {
            Success      => 0,
            ErrorMessage => $Param{ResponseErrorMessage},
        };
    }

    return {
        Success => 1,
        Data    => $Param{Data},
    };
}

1;
Thanks!!
Cheers
crynof
Znuny newbie
Posts: 24
Joined: 20 Mar 2020, 20:23
Znuny Version: 6.0
Real Name: Camilo

Re: How to return some variables in only one variable (Invoker)

Post by crynof »

Hi, i tried to return some variables apart from TicketID, but is not possible.

Code: Select all

package Kernel::GenericInterface::Invoker::Test::Test;

#use strict;
use warnings;
use Kernel::System::Ticket;
use Kernel::System::VariableCheck qw(IsString IsStringWithData);

our $ObjectManagerDisabled = 1;

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

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

    # check needed params
    if ( !$Param{DebuggerObject} ) {
        return {
            Success      => 0,
            ErrorMessage => "Got no DebuggerObject!"
        };
    }

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

    return $Self;
}

sub PrepareRequest {
# get ticket object
	
	use Kernel::System::ObjectManager;
    local $Kernel::OM = Kernel::System::ObjectManager->new();
    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
	
	#--------------------------------------------------------------------------------
	
    my ( $Self, %Param ) = @_;
	
		# get ticket content
	my %Ticket = $TicketObject->TicketGet(
        TicketID => $Param{Data}->{TicketID},
		);
		
		
		
	    my %Title = $TicketObject->TicketGet(
		Title => $Param{Data}->{Title},
			);
			
			
    
	
	return {
			Success => 1,
			Data => {
						%Ticket,
						%Title,
					}
			};
}

sub HandleResponse {
    my ( $Self, %Param ) = @_;

    # if there was an error in the response, forward it
    if ( !$Param{ResponseSuccess} ) {
        return {
            Success      => 0,
            ErrorMessage => $Param{ResponseErrorMessage},
        };
    }

    return {
        Success => 1,
        Data    => $Param{Data},
    };
}

1;
In this tutorial says about that

https://weekly-geekly.github.io/article ... index.html


OTRS only sends the ticket ID when an event occurs. Stated that you can pass other parameters. However, this was not possible. As a result, upon the occurrence of an event, the external system receives the TicketID, and it itself calls the OTRS for complete information. The guys from the forum did much the same. It breeds additional appeals, but in our case it is not critical.


Exist any way to return other data from ticket, not only TicketID?


Many thanks
Post Reply