#!/usr/bin/perl use strict; use warnings; require ESL; use IO::Socket::INET; my $ip = "127.0.0.1"; my $sock = new IO::Socket::INET ( LocalHost => $ip, LocalPort => '8040', Proto => 'tcp', Listen => 1, Reuse => 1 ); die "Could not create socket: $!\n" unless $sock; my $host = "127.0.0.1"; my $port = "8021"; my $pass = "ClueCon"; my $con2 = new ESL::ESLconnection($host, $port, $pass); for(;;) { my $new_sock = $sock->accept(); my $pid = fork(); if ($pid) { print "New child pid $pid created...\n"; close($new_sock); next; } my $fd = fileno($new_sock); my $con = new ESL::ESLconnection($fd); my $info = $con->getInfo(); my $uuid = $info->getHeader("unique-id"); printf "Connected call %s, from %s\n", $uuid, $info->getHeader("caller-caller-id-number"); $con->execute("set", "hangup_after_bridge=false"); $con->execute("set", "continue_on_fail=true"); $con->execute("set", "ignore_early_media=true"); $con->execute("answer"); $con->execute("playback","ivr/ivr-welcome_to_freeswitch.wav"); $con->execute("sleep","500"); my $con2 = new ESL::ESLconnection($host, $port, $pass); my $out_uuid = $con2->api('create_uuid')->getBody(); my $out_job = $con2->bgapi("originate", "{ignore_early_media=true,hangup_after_bridge=false,continue_on_fail=false,originate_timeout=30,origination_uuid=$out_uuid}sofia/gateway/eliza-outbound/0410001000 9664"); my $job_uuid = $out_job->getHeader("Job-UUID"); print "Call to coach. Job-UUID : $job_uuid, call uuid : $uuid, out_uuid : $out_uuid \n"; my $stay_connected = 1; $con2->events("plain","all"); while($stay_connected) { print "loop...\n"; my $e = $con2->recvEvent(); if($e) { my $ev_uuid = $e->getHeader("Unique-ID"); if ( $ev_uuid && ($ev_uuid eq $out_uuid) ) { if ( $e->getHeader("Answer-State") eq "answered" ) { print "Out call $out_uuid got answered!!!\n\n"; goto BREAKLOOP; } else { print "Answer State : ".$e->getHeader("Answer-State")."\n"; } } else { #nothing... } } else { print "No event...\n"; #$con->execute("set", "playback_timeout_sec=20"); #$con->execute("playback",'$${hold_music}'); } } BREAKLOOP: #$con2->execute('uuid_break',"$out_uuid"); $con2->api("uuid_bridge $uuid $out_uuid"); $con->execute("hangup"); $con->disconnect(); $con2->disconnect(); close($new_sock); } print "BYE\n";