Run a script when a call initiates AND ends

Hi fellow users,

I’m having a hard time trying to figure out how to execute a script when a call enters the system and again when it’s ended…

I need this because my ADSL line service also includes my PSTN phone number in SIP flavor (yacom Spain), so I have FreePBX handling it directly instead of the router provided by yacom. This reports me lots of possibilities, but I’m having an issue with the Deluge (bittorrent) daemon: If I upload over 30Kb/sec, the outgoing (upload) side of my phone calls gets very degraded (choppy, incomplete audio). My ADSL is supposed to be 20Mbps/1Mbps, but to hell with yacom’s marketing announcements…

The thing is I worte a small python script (available in the plugins forum of deluge-torrent.org, if anyone is interested) that allows me to dynamically change the upload rate, so I’d like to invoke a delugecontrol.py --max_upload_speed 10 when any call (incoming or outgoing) enters the system, and a delugecontrol.py --max_upload_speed 30 when the call ends (those values solve the audio problem so far).

Any idea on where could I hook my scripts?

Thanks!

Ivan.