0

I trying to use ooma with asterisk for my home setup, so I have 2 lines assigned to the same number forwarded through FXO gateways into asterisk. Outbound calls seem to work fine, but on inbound I have issue - both lines ring at the same time so on my IP phone I see multiple inbound calls from the same number. What is the simplest way to make that 2 incoming look like 1 call?

I tried to use DEVICE_STATE() function:

[from-ooma1]
exten => s, 1, GotoIf($["${DEVICE_STATE(SIP/ooma2)}"="RINGING"]?hang)
        same => n, Goto(incoming,s,1)
        same => n(hang),Hangup()

[from-ooma2]
exten => s, 1, GotoIf($["${DEVICE_STATE(SIP/ooma1)}"="RINGING"]?hang)
        same => n, Goto(incoming,s,1)
        same => n(hang),Hangup()

so on ring on one line if another one is already ringing to drop it. Unfortunately this does not work, as DEVICE_STATE has only 2 states NOT_INUSE and INUSE (or I do not know how to make it to report RINGING state), and I cannot drop on "IN_USE" state.

Note: my subject maybe misleading, to clarify - I need to prevent two lines ringing at the same time, but when first line answered and still in use, second one should allows to pass incoming call.

Slava
  • 43,454
  • 1
  • 47
  • 90

2 Answers2

1

You can count calls to any single entity by using function GROUP

[macro-stdvoip]
; ${ARG1} - full dial string
; Return ${DIALSTATUS} = CHANUNAVAIL if ${VOIPMAX} exceeded
exten => s,1,Set(GROUP()=trunkgroup1) ;Set Group
exten => s,2,GotoIf($[${GROUP_COUNT(trunkgroup1)} > ${VOIPMAX}]?103) ;Exceeded?
exten => s,3,Dial(${ARG1}) ;dial it
exten => s,103,SetVar(DIALSTATUS=CHANUNAVAIL) ;deny call

https://www.voip-info.org/wiki/view/Asterisk+func+group

arheops
  • 15,544
  • 1
  • 21
  • 27
  • Thanks, but it is not clear from documentation when GROUP_COUNT resets, I need to allow inbound ring on second channel when first one answered but still in use. – Slava Feb 09 '18 at 15:05
  • GROUP not reset till end of call. I.e it count current calls. If you need "reset" after some dialplan point, just creat enother group after that point and calculate difference. You control yourself via gotoIF what to do in every case. Sorry, i am not gooing do your work for you, i can just show direction – arheops Feb 09 '18 at 15:34
  • You can use on-answer handler(dial param M) to count answered calls in other group. – arheops Feb 09 '18 at 15:35
  • Actualy seams like you can clear by dooing Set(GROUP(category)=) (checked in source code) – arheops Feb 09 '18 at 15:37
  • I am not asking to do work for me. Problem is (if I understand correctly) if I reset GROUP before dial I can still get second call during ringing, if I do after I will prevent ringing when first call answered but still in use. So this solution does not work then. – Slava Feb 09 '18 at 15:45
  • Ah on-answer handler can reset GROUP, looks like this can work, let me try to implement – Slava Feb 09 '18 at 15:51
  • You have try. Answer handler is very special and limited thing. But for sure you can do it via external app like func_odbc+ some table. – arheops Feb 09 '18 at 19:28
  • Unfortunately Dial with macro does not work, as macro executed for called channel, so I cannot reset the group. :( – Slava Feb 10 '18 at 19:57
  • Finally made it work using yet another group, thanks for your help – Slava Feb 10 '18 at 21:59
  • Yes, macro is very limited and running on new channel. Dial options have other params which run gosub on CALLED channel, see "core show applicaiton dial". For high load you have use external option(fastagi/memcached/nosql/sql). – arheops Feb 11 '18 at 08:38
  • M() and U() both use called channel, so no difference for my purpose :( No I do not have high load, only 2 channels, I just need them to work reliable. My solution with 2 groups seem fine, so thanks for your help – Slava Feb 11 '18 at 20:17
  • No.There is methods which run on caller. https://wiki.asterisk.org/wiki/display/AST/Pre-Dial+Handlers – arheops Feb 12 '18 at 18:38
  • I cannot use predial - I need to reset group after call accepted, not before – Slava Feb 12 '18 at 21:33
0

Just in case somebody needs similar solution here is what works for me:

[from-ooma]
exten => 1,1,Set(CALLERID(number)=O:9${CALLERID(number)})
        same => n,Set(GROUP()=ooma)
        same => n,GotoIf($[${GROUP_COUNT(ooma)}>${GROUP_COUNT(ooma-answer)} + 1]?hang)
        same => n,Goto(incoming,s,1)
        same => n(hang),Hangup()

[macro-resetG]
exten => s,1,Set(GROUP()=${IF($[ "${ARG1:0:8}" = "SIP/ooma" ]?ooma-answer)})
        same => n,MacroExit

[incoming]
exten => s,1,Verbose(1,Caller ${CALLERID(all)} incoming call)
        same => n,Dial(SIP/1&SIP/2,20,TtM(resetG^${CHANNEL}))
        same => n,Hangup()

so I use another group to count how many calls from ooma is answered (condition in macro is used because there could be other incoming calls)

Slava
  • 43,454
  • 1
  • 47
  • 90