Skip to content

Instantly share code, notes, and snippets.

@g3rhard
Created November 15, 2016 07:39
Show Gist options
  • Save g3rhard/30ec0c3222c67e3bbbd92d2e4c81a2dc to your computer and use it in GitHub Desktop.
Save g3rhard/30ec0c3222c67e3bbbd92d2e4c81a2dc to your computer and use it in GitHub Desktop.
AGI connector with OTRS
#!/usr/bin/perl
#
# AGI connector with OTRS
#
# Written by: Kiriru Trofimov <[email protected]>
#
#initialize
use Asterisk::AGI;
use SOAP::Lite;
$AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
my $tests = 0;
my $pass = 0;
my $fail = 0;
my $User = 'otrs_soap_user';
my $Pw = 'otrs_soap_password';
my $RPC = new SOAP::Lite( proxy => 'http://ip_address/otrs/rpc.pl', uri => 'http://ip_address/Core' );
$datestring = localtime();
#setup callback
$AGI->setcallback(\&mycallback);
#setup log file
open(my $fh, '>', 'otrs.agi.log');
#check agi
print $fh "$datestring\n";
print $fh "AGI Environment Dump:\n";
foreach $i (sort keys %input) {
print $fh " -- $i = $input{$i}\n";
}
print $fh "Caller ID: ";
print $fh "$input{callerid}\n";
# create a new ticket number
print $fh "NOTICE: TicketObject->TicketCreateNumber()\n";
my $SOM = $RPC->Dispatch( $User, $Pw, 'TicketObject', 'TicketCreateNumber' );
die $SOM->fault()->{faultstring} if $SOM->fault();
my $TicketNumber = $SOM->result();
print $fh "NOTICE: New Ticket Number is: $TicketNumber\n";
# get ticket attributes
print $fh "NOTICE: TicketObject->TicketGet(TicketID => 1)\n";
$SOM = $RPC->Dispatch( $User, $Pw, 'TicketObject', 'TicketGet', TicketID => 1 );
die $SOM->fault()->{faultstring} if $SOM->fault();
my %Ticket = $SOM->result();
print $fh "NOTICE: Ticket Number is: $Ticket{TicketNumber}\n";
print $fh "NOTICE: Ticket State is: $Ticket{State}\n";
print $fh "NOTICE: Ticket Queue is: $Ticket{Queue}\n";
# create a ticket
my %TicketData = (
Title => 'asterisk otrs',
Queue => 'Raw',
Lock => 'unlock',
Priority => '3 normal',
State => 'new',
CustomerID => $input{callerid},
CustomerUser => '[email protected]',
OwnerID => 1,
UserID => 1,
);
print $fh "NOTICE: TicketObject->TicketCreate(%TicketData)\n";
$SOM = $RPC->Dispatch( $User, $Pw, 'TicketObject', 'TicketCreate', %TicketData );
die $SOM->fault()->{faultstring} if $SOM->fault();
my $TicketID = $SOM->result();
print $fh "NOTICE: TicketID is $TicketID\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment