0

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).

Flole
  • 55
  • 8

1 Answers1

0

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.

arheops
  • 15,544
  • 1
  • 21
  • 27
  • I'll give that a try in a minute, thanks! And for outgoing calls I have to put it in a special context or how can I handle that? As my default context includes many extens it would be the easiest if I could just include it and have a script run before and after that, is that possible? – Flole Aug 25 '17 at 19:35
  • You can put in dialling option gosub on answer(U), in which you can check channle name. But i am afraid that will be much more complex staff. – arheops Aug 25 '17 at 20:57
  • Yeah that will definetely be more complex as I would have to add it to absolutely every Dial command, which are a few hundred. Thanks for your help, I did some minor changes to your solution and it works absolutely great now! – Flole Aug 25 '17 at 22:11
  • If you have add it to every dial command, that mean your dialplan is very bad structured. Most of PBX have in ONE place dialling flags. However you still can do it using vim replace or sed. – arheops Aug 26 '17 at 07:25
  • Well I have several phones so I need an exten for every phone as every phone has an internal number. Then I have about 15 "real" phone numbers that need to be sent to different phones. I'm always willing to improve the way I work, so if there's a different approach on how it's done I will definitely look at it! – Flole Aug 26 '17 at 13:21
  • Userevent have channel variable, which can be used to get your phone id. – arheops Aug 26 '17 at 17:28
  • I'm trying to achieve something like this but instead of muting a TV I'm trying to mute the Windows system audio. Would love some help if you got this working @Flole? – daneee Nov 21 '19 at 13:49