Is there a Hangup trigger

Im new to freepbx and was wondering if there was a way to run a php script when there was a hangup and pass info to the php file like src,dst duration fields. Im using fsockopen to make the call but i have no idea when the call is over. If there is a better way to do this please let me know. Thanks in advance.

The ‘H’ context in the dial plan is what you are looking for.

Asterisk, The definitive Guide, is the best reference to Asterisk Dialplan code.

This is probably a newbie response. Im using fsockopen to make the call not a dial plan. Unless when i call through fsockopen it uses the dial plan. Can you please help me out and give me a example, file locations etc. I tried goggling but don’t understand what im suppose to update. Thanks for your help

I thought fsockopen was a PHP function. I am not a developer, keep it simple. How are you originating the call to Asterisk?

here is the code to initiate the call. I was trying to add a account code or userfield but could get that to work, if i could just make the call and get or put in a custom id i would be good to go. Thanks for your help

$ex = $_GET['ex']; $number = $_GET['number']; $strUser = "admin";#specify the asterisk manager username you want to login with $strSecret = "#####";#specify the password for the above user #specify the channel (extension) you want to receive the call requests with $strChannel = "SIP/".$ex; $strContext = "from-internal"; #specify the amount of time you want to try calling the specified channel before hangin up $strWaitTime = "30"; #specify the priority you wish to place on making this call $strPriority = "1"; #specify the maximum amount of retries $strMaxRetry = "2"; //$number=strtolower($_REQUEST['number']); $number=strtolower($number); $pos=strpos ($number,"local"); if ($number == null) : exit() ; endif ; if ($pos===false) : $errno=0 ; $errstr=0 ; $strCallerId = "Web Call $number"; $oSocket = fsockopen ("localhost", 5038, &$errno, &$errstr, 20); if (!$oSocket) { echo "$errstr ($errno)
\n"; } else { fputs($oSocket, "Action: login\r\n"); fputs($oSocket, "Events: off\r\n"); fputs($oSocket, "Username: $strUser\r\n"); fputs($oSocket, "Secret: $strSecret\r\n\r\n"); fputs($oSocket, "Action: originate\r\n"); fputs($oSocket, "Channel: $strChannel\r\n"); fputs($oSocket, "WaitTime: $strWaitTime\r\n"); fputs($oSocket, "CallerId: $strCallerId\r\n"); fputs($oSocket, "Exten: $number\r\n"); fputs($oSocket, "Context: $strContext\r\n"); fputs($oSocket, "Priority: $strPriority\r\n\r\n"); fputs($oSocket, "Action: Logoff\r\n\r\n"); sleep(2); fclose($oSocket); } echo "Extension $strChannel should be calling $number." ; else : exit() ; endif ;

You are using a php wrapper around the AMI (Asterisk Manager Interface) by default available on tcp/5038. I suggest you familiarize yourself with that interface first, for a quick intro:-

http://www.voip-info.org/wiki/view/Asterisk+manager+API

for the meat and potatoes

http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html/asterisk-book.html#asterisk-DP-Basics

You can send your call anywhere in your dialplan with AMI, but it is up to your dialplan to handle the “h” extension if and when the call gets there.

Ok, see the context variable? Every context has an H destination. That code is executed on hangup.

That updates the dcontext column i believe in the db. I was trying to look how i would use that to fire off a script or place data in the userfield i’ve tried a bunch of different variations with no success. Thanks for the help im trying to read docs to see how to do it, not finding much though.