Capture HTTP response Code through AGI

All installation and configuration problems and questions

Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N

Capture HTTP response Code through AGI

Postby himanshu.jaiswal » Thu Sep 13, 2018 12:55 pm

Hello,

I want to build an IVR which takes input from customer and passes to http. Upon successful validation of the input http response code is 200 else 302 and i want to capture these codes and proceed to next IVR extensions. Below is the IVR and php file

IVR------------------------------
exten => _X.,1,Answer()
same => n,AGI(sample.php)
same => n,Set(_response=${code})
same => n,NoOp(--Response Code is ${response})

PHP file-----------------------------------
[root@go agi-bin]# cat sample.php
#!/usr/bin/php
<?php
$domain1 = 'https://www.google.com=XXXXXXX';

function get_http_response_code($domain1) {
$headers = get_headers($domain1);
return substr($headers[0], 9, 3);
}

$get_http_response_code = get_http_response_code($domain1);

$agi->set_variable('get_http_response_code',$code);
$agi->verbose($code);
?>


Kindly help in how can i build the IVR using AGI and PHP
himanshu.jaiswal
 
Posts: 7
Joined: Wed Aug 09, 2017 9:06 am

Re: Capture HTTP response Code through AGI

Postby himanshu.jaiswal » Fri Sep 14, 2018 7:26 am

Hello,

Below is my PHP file.
#!/usr/bin/php
<?php
$code ='00022489';
$domain1 = 'https://www.google.com='.$code;

function get_http_response_code($domain1) {
$headers = get_headers($domain1);
return substr($headers[0], 9, 3);
}

$get_http_response_code = get_http_response_code($domain1);

print "$get_http_response_code";

When i debug the AGI I am getting the output response code as below

-- User entered '00022489'
-- Executing [515007@testivr:5] GotoIf("SIP/8001-00000011", "1?valid:invalid") in new stack
-- Goto (ashacode,515007,6)
-- Executing [515007@testivr:6] AGI("SIP/8001-00000011", "google.php,00022489") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/google.php
<SIP/8001-00000011>AGI Tx >> agi_request: ashacodes.php
<SIP/8001-00000011>AGI Tx >> agi_channel: SIP/8001-00000011
<SIP/8001-00000011>AGI Tx >> agi_language: en
<SIP/8001-00000011>AGI Tx >> agi_type: SIP
<SIP/8001-00000011>AGI Tx >> agi_uniqueid: 1536927822.17
<SIP/8001-00000011>AGI Tx >> agi_version: 1.8.23.0-1_centos5.go RPM by demian@goautodial.com
<SIP/8001-00000011>AGI Tx >> agi_callerid: 0000000000
<SIP/8001-00000011>AGI Tx >> agi_calleridname: 8001
<SIP/8001-00000011>AGI Tx >> agi_callingpres: 0
<SIP/8001-00000011>AGI Tx >> agi_callingani2: 0
<SIP/8001-00000011>AGI Tx >> agi_callington: 0
<SIP/8001-00000011>AGI Tx >> agi_callingtns: 0
<SIP/8001-00000011>AGI Tx >> agi_dnid: 515007
<SIP/8001-00000011>AGI Tx >> agi_rdnis: unknown
<SIP/8001-00000011>AGI Tx >> agi_context: ashacode
<SIP/8001-00000011>AGI Tx >> agi_extension: 515007
<SIP/8001-00000011>AGI Tx >> agi_priority: 6
<SIP/8001-00000011>AGI Tx >> agi_enhanced: 0.0
<SIP/8001-00000011>AGI Tx >> agi_accountcode: 8001
<SIP/8001-00000011>AGI Tx >> agi_threadid: 47308491569472
<SIP/8001-00000011>AGI Tx >> agi_arg_1: 00022489
<SIP/8001-00000011>AGI Tx >>
<SIP/8001-00000011>AGI Rx << 200
<SIP/8001-00000011>AGI Tx >> 510 Invalid or unknown command

I want to capture 200 from <SIP/8001-00000011>AGI Rx << 200 and pass it to dial plan
himanshu.jaiswal
 
Posts: 7
Joined: Wed Aug 09, 2017 9:06 am


Return to Support

Who is online

Users browsing this forum: No registered users and 98 guests

cron