forwarding call if callee/device is offline - asterisk

I need to forward calls based on whether the end-device is turned on/off.
If the device is on, call the number normally, else forward it to the other members of the department.
exten => _[0-9]X,1,Dial(SIP/${EXTEN}dev, 120) ;if phone is offline, execute line below
Dial(SIP/01dev&SIP/02dev&SIP/03dev, 16)
How can i determine whether or not a device is turned off?

A simple dialplan implantation for that can be checking the DIALSTATUS and using ExecIf - if didn't get an answer with 1st dial, do the 2nd dial:
exten => _[0-9]X,1,Dial(SIP/${EXTEN}dev, 120) ;your 1st line
same => n,ExecIf($["${DIALSTATUS}" != "ANSWER"]?Dial(SIP/01dev&SIP/02dev&SIP/03dev, 16))
Note that 1st device can be "on" and dial will not return with ANSWER (BUSY, NOANSWER, CANCEL, etc.), but guess you want to make the 2nd dial even if device is "on" but did not answer.

Related

Asterisk Freepbx - hide external number on user's display after forwarding

For some reason I can not find the necessary information on the Internet.
Subscriber A has set forwarding to an external number (output to the city goes through a sip trunk). I want this external number to be hidden for subscriber B, when he calls subscriber A.
How to implement?
Those. In my understanding there should be a condition:
If the call was forwarded and a call was made to a number that starts with _11X (exit to the city) Then perform the callerid replacement function.
####################################################################
Update:
Perhaps I explained incorrectly.
For example, I call from number 2222 to number 3333 (these numbers are located on Asterisk). Call forwarding to mobile number 11444555566 is set on number 3333 (Calls to external numbers go through sip trunk to siemens)
So, when I call like this, I see that the call goes to number 3333, but when the mobile number 11444555566 answers, then I see this number 11444555566 on the my phone, but I would not want it to be visible on the display, because we consider mobile number information to be private.
And I would like to hide this number only if forwarding to numbers _11 is set
On FreePBX, I can make a custom dialplan in extensions_custom.conf, but I need a hint.
for example, I now have a simple dialplan for external outgoing calls in extensions_custom, i want to hide ${EXTEN} on the phone display:
[dial-siemens]
exten => _11.,1,Set(CALLERID(num)=${CALLERID(num)})
exten => _11.,n,Dial(PJSIP/${EXTEN}#Siemens,120)
exten => _11.,n,Hangup()
####################################################################
UPDATE:
I continued to look for a solution and something worked, but not completely.
It turned out to remove the number from the phone display with such a dialplan setting, the I option helped.
exten => _11X.,1,Set(CONNECTEDLINE(num)=fwd to external)
exten => _11X.,n,Dial(PJSIP/${EXTEN}#Siemens,,I)
exten => _11X.,n,Hangup()
Now, when dialing an external number _11, I see "fwd to external" instead of the number. This is what I need.
Now I need to make the rule only run when the call has been redirected. Need help.
There is no need in do anything like that.
If you have DID forwarded to asterisk PBX and customer A call to that did - there is no any way for customer know where call was send. External number, sip device, artifact intelligence system, conference etc - all will looks the same. Customer should know only DID's number.
If you need customer B not know callerid of customer A, you just should replace CALLERID on the router you are using to call B. I.e put one of your did in CALLERID field at outbound routes and select "force callerid".
Hint: You can have multiple outbound rules per trunk, with different prefixes.
it seems to work like that:
[dial-siemens]
exten => _11X.,1,ExecIf($["${DB(CF/${CONNECTEDLINE(num)})}"!=""]?Macro(dial-siemens-cf-external,${EXTEN}),s,1)
exten => _11X.,n,Dial(PJSIP/${EXTEN}#Siemens,120)
exten => _11X.,n,Hangup()
[macro-dial-siemens-cf-external]
exten => s,1,Set(CONNECTEDLINE(num)=fwd to external)
exten => s,n,Dial(PJSIP/${ARG1}#Siemens,,I)
exten => s,n,Hangup()

Asterisk forward a call to number A and when A hangs up, forward to B

My use case is really simple: Asterisk is the middleman, it receives the call from outside and it forwards to A, when A hangs up, I want to forward it to B immediately. Is it sufficient to make another Dial?
Do you have any example?
+12345 --- Asterisk------------------ B
| when A hangs up call B
|
A
If A is called with the Dial application, you could use the 'g' option and put the call to B after the first Dial to A.
According with the Dial documentation:
g - Proceed with dialplan execution at the next priority in the current extension if the destination channel hangs up
In the following example, dialing 1001 asterisk calls first SIP/A. If A hangups, asterisk calls B. It is not necessary the option 'g' in the last call. I leave it to be able of modifying the Dial in a future or in case I wanted to grow the chain. Note the last Hangup that, if there was not option 'g' it would not be strictly necessary, but even without 'g' option can be convenient (if you put timeouts and you want to play sounds if the timeout comes).
exten => 1001, 1, Dial(SIP/A,,gm)
same => n, Dial(SIP/B,,gm)
same => n, Hangup()

Generating IVR on Asterisk without duration, get DTMF input from user and then process it

I hope cyber Asterisk gurus would be able to help me in this regard. I am trying to create an IVR filter using Asterisk. My desired configuration goal is:
1:When a user dial into the Asterisk, the user should hear IVR(but there should be no charging on initial IVR). I want to send the IVR in in initial 183 Session in progress without any duration starting on my phone.
2:Once a user input some digit via DTMF, then the call should be processed and charging etc should take place
I would really appreciate you guys input in this regard. Thanks
You can use power of local channel combine with NoCDR. In beginning of your IVR use NoCDR() function, and after DTMF check use Dial to local channel contex with rest of yout logic.
[ivr]
exten => 100,1,NoCDR()
exten => 100,n(read),Read(variable)
exten => 100,n,GotoIf($[ ${variable} = 1 ]?go_1:read)
exten => 100,n(go_1)Dial(Local/${exten}#dtmf_1_logic)
[dtmf_1_logic]
.....
In that case you should have one CDR from dtmf_1_logic context with call duration with you are looking for

Changing the caller number in an incoming call in asterisk

I am using asterisk.I have DID in which 4 numbers are mapped(stored in my database) so when user calls to that DID number the call is forwarded to the any one number mapped on that did.
My problem is that when user calls to DID the one of the four executive receive calls from the DID number not with user number .This is my part of dialplan code the call is routed from another context(not given below) to the direct context
[direct]
exten => start,1,noop(######START######)
same => n,mysql(Query resultid ${connid} SELECT number from database);;;DDDDDD
same => n,MYSQL(Fetch fetchid ${resultid} number )
same => n,mysql(clear ${resultid})
same => n,set(__NUMBER=${number})
same => n,dial(DAHDI/g0/0${NUMBER},20,mM(ANSWEREDED))
[macro-ANSWEREDED]
exten => s,1,noop(CALL_ANSWERED)
exten => s,n,Mixmonitor(/recordings/record.wav)
How can i change the number that flashes on executive number(number mapped on DID) to the caller number?
Thanks in advance.
1) Every asterisk book have example. Doing asterisk coding without reading book - not so nice idea
2) callerid can be set like this
same => n,set(__NUMBER=${number})
same => n,set(CALLERID(num)=123445678)
same => n,dial(DAHDI/g0/0${NUMBER},20,mM(ANSWEREDED))
3) If you use pstn dahdi connection(FXO card), that will not work. If you use digital connection, it can work if provider support that.
4) Use of app_mysql is depricated. Use func_odbc or realtime.
5) Use of mixmonitor inside on-call macro is extremly bad practice. Use mixmonitor with 'b' option before call out.

multiple dtmf input in asterik dialplan

In asterisk dialplan why it is so when dtmf input is two or more digits and if a digit is
pressed when the prompt is being played it goes into i extension(invalid extension) as in
case of single digit dtmf input if digit is pressed as the prompt is being played it moves
into the right extension? thanks
Here's another example where a user must enter a 4 digit PIN to continue in the dialplan:
[Login]
exten = s,1,Playback(/var/lib/asterisk/sounds/custom/login)
exten = s,n,Set(rightPIN=1234)
exten = s,n,Read(inPIN,/var/lib/asterisk/sounds/custom/enterPIN,4)
exten = s,n,GotoIf($["${inPIN}" = "${rightPIN}"]?pin-accepted,1)
; Didn't go to pin-accepted, so play badPIN and hangup
exten = s,n,Playback(/var/lib/asterisk/sounds/custom/badPINgoodbye)
exten = s,n,Hangup()
; correct pin, play something
exten = pin-accepted,1,Playback(/var/lib/asterisk/sounds/custom/something)
...
The third parameter of the Read() application is how many digits to wait for. For more information on Read, see Asterisk Wiki: Read
Edit: There's also a dialplan app called Authenticate that does this quite well.
This will depend on how your diaplan is configured, but it sounds like you are using the background() application. Background() will listen for DTMF and then route to an extension in the current context on the 1st unambiguous match.
For example if you have 1, 2 and 100 in the context then pressing 2 will route directly to 2 (because it's unambiguous.) Pressing 1 will wait for a timeout because background() doesn't know if you are going to 1 or 100. After the timeout it will route to 1. Pressing 3 will go to the i special extension because there's is not extensions in the current context that start with 3.
If the desired behavior is to route from your IVR context to one of your internal phones then you need to include the phones context inside the IVR context:
[phones]
exten => 100,1,Dial(SIP/phone1)
exten => 101,1,Dial(SIP/phone2)
...
[IVR]
exten => s,1,Background(message)
exten => 1,1,Queue(Sales)
exten => 2,1,Queue(Support)
exten => i,1,Playback(pbx-invalid)
include => phones
More info in official documentation:
https://wiki.asterisk.org/wiki/display/AST/Application_BackGround
I recomend you start from reading this:
http://astbook.asteriskdocs.org/en/2nd_Edition/asterisk-book-html-chunk/asterisk-CHP-5-SECT-1.html
or ORelly's book "Asterisk the future of telephony".

Resources