Action based on SIP Casue Code


I have been trying to get this to work for weeks but have not been able to draw the correct correlations… My requirement is to generate many calls and based on the SIP response take an action with a script. I am attempting to accomplish this with a perl script utilizing Asterisk::AMI and the originate action. I can generate the call and get back OriginateResponse info but that doesn’t seem sufficient:

[code]use Asterisk::AMI;

my $astman = Asterisk::AMI->new(
PeerAddr => ‘’,
PeerPort => ‘5038’,
Username => ‘admin’,
Secret => ‘password’

die “Unable to connect to asterisk” unless ($astman);

my $action = $astman->action({Action => ‘Originate’,
Channel => ‘SIP/GW1/1006’,
Callerid => 5555555555,
Async => true,
Context => default,
ActionID => “2”,
OriginateHack => 1,
Priority => 1});

print ($action->{‘COMPLETED’});
print “\n”;
print ($action->{‘Response’});
print “\n”;
print ($action->{‘GOOD’});
print “\n”;
print ($action->{‘ActionID’});
print “\n”;[/code]

I see there is a method of getting SIP cause codes with “${HASH(SIP_CAUSE” in extensions.conf

but I am totally lost on how to pull that back into my script. Is that sent back via AMI and my originate command?

Thank you in advance for your help,