asteriskasteriskami

Asterisk run script on Phone Answer and Outgoing Call


I'm trying to make my Asterisk run a script whenever a certain phone (Sip Phone) answers or makes an outgoing call and when it ends that call. The purpose of that is to automatically mute my TV when a call is done with the phone in the same room.

I've tried using the System command but that doesn't get information about the phone that answered. As I am having multiple phones ringing, I can not distinguish if it was indeed the phone next to the TV or a completely different phone. Same problem I am having for outgoing calls.

Is there a different approach to this? I also tried using the AMI but I haven't found a way to get the status of a specific peer (Offline, Online, In Call, lagged).


Solution

  • Lets say you have ext sip/111

    Support extension

    [from-internal-very-special]
    exten => 111,1,UserEvent(TVRingStarted)
    same => n,Set(CHANNEL(hangup_handler_push)=from-internal-very-special,ends,1)
    same => n,Dial(SIP/111,,U(from-internal-very-special,answer,1))
    
    exten =>answer,1,UserEvent(TVRingAnswer)
    same => n,Set(GOSUB_RESULT=);we accept call
    same => n,Return;continue
    
    exten => ends,1,Noop(end of call)
    same => n,UserEvent(TVRingEnds)
    same => n,Return;
    

    After that call extension as Local/111@from-internal-very-special/n instead of SIP/111

    You will have user events you can parse via AMI. Or you can replace that by System calls as you wish.