Execute a script in every extensions i have after hanging up every call

Hi everyone!
I have dial plan like that:

exten => 5000,1,noop()
exten => 5000,n,agi(sms.php)
exten => 5000,n,hangup()

exten => 5002,1,NoOp()
exten => 5002,n,AGI(specific-call.php)
exten => 5002,n,Hangup()
exten => h,1,AGI(update-table.php)

Now I want to add src and dst to my own table and I wrote a PHP script for that, so I need to run a script after every call hang up independently which extension is executed.

What should I do?

I have tried h extension but it dose not work when I directly call to an agent(for example 200).

You would add a hangup handler that follows the channel no matter where it goes:


can i inject my file in macro-hangup call?

I don’t know what “macro-hangup” is, or what file you are referring to.

Macros have been removed in the latest version of Asterisk and their demise was first announced around Asterisk 1.6, so you should not be using a macro.

Also people here will have no idea what your AGI scripts do.

1 Like

Easiest thing would be to have an AMI or ARI script that listened for all events, and handled hangups accordingly.

Using ARI for this would be an off label use. The intended use of ARI is custom dialplan applications.

Most people wanting to run something on hangup want to access information from the channel, or from open CDRs, but the channel hangup and CDR finalisation would proceed in parallel with the AMI and ARI events.

I don’t understand what “off label” means. Something to do with medicine regulation?

yes i will use AMI. tnx.

I was using medicine as a metaphor. Off label there means you are using a medicine for a purpose for which it isn’t licensed. I generalised that to a purpose for which it wasn’t designed.

Nobody is “regulating” your use of free software.