Asterisk how check if a number is busy before dialing it - asterisk

As a beginner that just installed his first asterix server I came across a small issue. i want to check if a number that i dial is busy or not before actually dialing it.
So for example I would call 0904 => number busy => redirect to 0905
However I don't want it to dial 0904 first if its busy but just instantly redirect it to 0905 instead.
I have a very basic setup with just 3 users. 2 of them are in a queue "support" one of them is in the queue "admin"
I have seen and read a little about checking if a channel is available but i didn't fully understand that and I'm not sure if it could be done easier.
Here is my simple dialplan, if i call *12 my simple python script will just execute the Dial command to the 0904.
exten => *12,1,Answer()
same => n,set(PHONE_EXTEN=0904)
same => n,AGI(test-agi.py,${PHONE_EXTEN})
same => n,Hangup()

There is no way know if external number is busy.
If number is your extension, you can count calls using GROUP/GROUP_COUNT or you can check extensions states and hints, like described in docs
https://wiki.asterisk.org/wiki/display/AST/Extension+State+and+Hints
https://wiki.asterisk.org/wiki/display/AST/Device+State

Related

Recording Normal Calls and Conference calls in Asterisk

Set up Asterisk 13.1 on Ubuntu 16.04,Calls are Working fine as well as conference calls.However I have two Question regarding the recording of calls in asterisk.
This is the extensions.conf.
[default]
exten => 1000,1,MixMonitor(${CALLERID(num)}-${STRFTIME(|EST5EDT|%m%d%Y-%H%M%S)}.gsm)
same => n,Dial(SIP/1000)
exten => 1001,1,MixMonitor(${CALLERID(num)}-${STRFTIME(|EST5EDT|%m%d%Y-%H%M%S)}.gsm)
same => n,Dial(SIP/1001)
exten => 100,1,Answer()
exten => 100,n,Authenticate(234)
same => n,MixMonitor(${CALLERID(num)}-${STRFTIME(|EST5EDT|%m%d%Y-%H%M%S)}.gsm)
same => n,ConfBridge(1234)
And this is confbridge.conf
conf => 1234
[1234]
record_conference = yes
1)Is it necessary to define MixMonitor for every call(As I have done above for user 1000 and 1001) ,or is there a possibility where you can define it once and all calls in your asterisk server get recorded.
2)When the Conference call is recorded ,suppose if there are two users in the conf room,there are two audio files generated instead of one,What changes do I make so theres is only one recorded audio file of the full conference?
In asterisk it is nessesary do any action you want DO.
In your case you can use mixmonitor command in every dialplan, use pattern to do that command for large list, use external macro or gosub function and call it for calls you want be recorded.
For conference you can start enother call with mixmon(third call) using Originate or you can use internal recording.
For ANY record you can have Monitor(two files for each side of call) or mixmonitor(same, but 1st party in left channel, 2nd party in right channel, so file is single).
So if you have 2 files, you just have non-mixed variant. Consult conference room options for mixed version.

Multiple CDR records Asterisk 13

Running Asterisk 13.12.1, FreePBX 13.0.192.19.
We had to install new server and since we previously used much older asterisk, there were some fixes applied. We DIDN'T update previous, but we made clean install, just copied dialplans, sip config etc.
The problem is that we are now having multiple CDR records per call. We previously had NOCDR lines for local contexts, and we tried I have tried to change those to exten => _X!,1,Set(CDR_PROP(disable)=1) but that didn't work at all.
Here is the example:
[main context]
exten => remote-mon-1,1,Dial(SIP/lokal300&SIP/lokal301&Local/06xxxxxx#shift-remote-1&Local/06xxxxxx#shift-remote-2&Local/06xxxxxx#shift-remote-3&Local/06xxxxxx#shift-remote-4&Local/06xxxxxx#shift-remote-5&Local/06xxxxxx#shift-remote-6,,m(remote)M(whoanswered,remote))
[shift-remote-1]
exten => _X!,1,Set(CDR_PROP(disable)=1)
exten => _X!,n,Dial(SIP/gsm10/${EXTEN},540)
Basically what the above does is calling two local phones (300 and 301) as well as multiple (6) remote mobile phones via gsm gateway.
1) So CDR PROP is completely ignored (I think someone said how its not working with Local context but I need confirmation). How can I fix it?
2) Any other ideas how to avoid creating multiple CDR record for each call?
Thank you!
Update: As this was flagged as a duplicate of Asterisk 13.4 cdr engine is creating 2 records per call , I need to explain that In that question the solution is applying unofficial patch, which is not something we want to do. I was looking for official approved way on why CDR_PROP is not working correctly. Furthermore (I just checked) the link to patch in that post is not working, as site is unreachable. One more reason to not flag this as duplicate.
1) use NoCDR, not forget add '/n' to local channels
pro-sip*CLI> core show application NOCDR
-= Info about application 'NoCDR' =-
[Synopsis]
Tell Asterisk to not maintain a CDR for this channel.
[Description]
This application will tell Asterisk not to maintain a CDR for the current
channel. This does *NOT* mean that information is not tracked; rather, if the
channel is hung up no CDRs will be created for that channel.
If a subsequent call to ResetCDR occurs, all non-finalized CDRs created for the
channel will be enabled.
NOTE: This application is deprecated. Please use the CDR_PROP function to
disable CDRs on a channel.
[Syntax]
NoCDR()
[Arguments]
Not available
[See Also]
ResetCDR(), CDR_PROP
2) Read /etc/asterisk/cdr.conf params.

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

WaitExten during the call

Scenario:
Asterisk receives incoming call to a DID number
Asterisk forwards incoming call to a mobile number using PSTN termination.
Call is answered on a mobile
Question:
Is there a possibility to transfer call to a different extension during the call ?
yes,but require guru level.
it can be done by writing special application or using conference or using AMI.
probably easy way is conference
Yes. This is very straight forward.
Presuming your DID is 1-234-567-8900 and your moble is 1-987-654-3210:
exten => _12345678900,1,NoOp(Call for DID to Mobile)
same => n, Dial(DAHDI/g1/19876543210,30,t)
same => n, HangUp()
The dial option "t" allows "...the called user to transfer the call by hitting the blind xfer keys (features.conf)"
Further reading: http://www.voip-info.org/wiki/view/Asterisk+cmd+Dial

Playing a music file before call connects using Asterisk

I have an asterisk server. I use the server to connect an incoming call to another extension based on a few key presses. There is a certain time lag (after the key/extension press and before the call connects). How can I play a small music file (of my choice) in this period? There are some constraints that come to my mind:
The music should play only as long as the call does not connect. So, the method used should be a non-locking one.
Any help on this is most welcome.
Thanks,
Sriram
Use the m flag to the Dial application, to play music on hold while the call is connecting.
exten => 9000,1,Noop
exten => 9000,n,Answer
exten => 9000,n,Dial(SIP/device,0,m)
I think Background is your friend (http://www.voip-info.org/wiki/view/Asterisk+cmd+BackGround)

Resources