Time conditions for outgoing calls

Hello everybody!

Do you know any way to route outgoing calls in a time condition basis? I can see “Time conditions” module but as I can see it work for incoming calls.

I’am using 2.4.0 FreePBX version.

Regards

you are correct time conditions is for incoming not outgoing.

How about you explain what you are attempting to do so that we can see if we have a way to achieve what you need.

I need route calls starting at 6 (mobile number) to different sip gateways. For example, I call to 600123654 and if time at that moment is before that 14PM i must route it to sip gateway number one, and if time is after 14PM i will route it to sip gateway number two. I get different prices for mobile destinations depending of the time.

Regards

Interesting. My first thought would be to start with the technique suggested in How to give a particular extension different or restricted trunk access for outgoing calls - note the third example block of code, which looks like this (you will have to read the document for this to make sense):

[custom-trunk-selector-1]
exten => 911,1,Goto(from-internal,0000999${EXTEN},1)
exten => _1NXXNXXXXXX,1,Goto(from-internal,0000999${EXTEN},1)
exten => _NXXNXXXXXX,1,Goto(from-internal,0000999${EXTEN},1)
exten => _NXXXXXX,1,Goto(from-internal,0000999${EXTEN},1)
exten => _[*0-9]!,1,Goto(from-internal,${EXTEN},1)
exten => h,1,Hangup()

Suppose you made two outbound routes instead of one - call one “day” and the other “night” - and for “night” you use a prefix of 0000999 (as shown above) and for day you use some other prefix, maybe 0000888. Then about the only thing you would need is a GotoIfTime statement - for example:

[custom-trunk-selector-1]
exten => _[*0-9]!,1,GotoIfTime(08:00-05:00|*|*|*?custom-dayroute-1)
exten => 911,1,Goto(from-internal,0000999${EXTEN},1)
exten => _1NXXNXXXXXX,1,Goto(from-internal,0000999${EXTEN},1)
exten => _NXXNXXXXXX,1,Goto(from-internal,0000999${EXTEN},1)
exten => _NXXXXXX,1,Goto(from-internal,0000999${EXTEN},1)
exten => _[*0-9]!,1,Goto(from-internal,${EXTEN},1)
exten => h,1,Hangup()

[custom-dayroute-1]
exten => 911,1,Goto(from-internal,0000888${EXTEN},1)
exten => _1NXXNXXXXXX,1,Goto(from-internal,0000888${EXTEN},1)
exten => _NXXNXXXXXX,1,Goto(from-internal,0000888${EXTEN},1)
exten => _NXXXXXX,1,Goto(from-internal,0000888${EXTEN},1)
exten => _[*0-9]!,1,Goto(from-internal,${EXTEN},1)
exten => h,1,Hangup()

BUT see my next message for a much better way!

After giving this a bit more thought, I realized that a better way would be to use one outbound route, but make the destination a CUSTOM trunk which would point to a context you create in extensions_custom.conf. In that context you’d have a GotoIfTime statement that would select one of two actual trunks, depending on the time. Here is how I would suggest doing it, but note this is untested!

Create a new context in extensions_custom.conf - it should look something like this:

[custom-timeselect]
exten => _[*0-9]!,1,GotoIfTime(08:00-05:00|*|*|*?dayselect)
exten => _[*0-9]!,n,Dial(SIP/[b][i]nighttrunk[/i][/b]/${EXTEN})
exten => _[*0-9]!,n,Goto(app-blackhole,congestion,1)
exten => _[*0-9]!,n(dayselect),Dial(SIP/[b][i]daytrunk[/i][/b]/${EXTEN})
exten => _[*0-9]!,n,Goto(app-blackhole,congestion,1)
exten => h,1,Hangup()

EDIT: Above edited to add congestion statements - see next comment.

See this page for an explanation of how to set the time in the GotoIfTime statement (note that if you are using Asterisk 1.6 you must replace the | separators with commas) - or if you get stuck, you can always create a dummy Time Condition in FreePBX (so you can use the GUI to specify your time condition settings), save it and save changes, and then open extensions_additional.conf and search for the [timeconditions] context header - you will see how FreePBX would construct the GotoIfTime statement according to the parameters you’ve entered, and you can copy that into your context (then you can delete the dummy Time Condition).

Replace daytrunk and nighttrunk with the actual names of trunks you want to use for day and night calls, as shown in your trunks list. Replace SIP with whatever technology is actually used by the trunk (such as IAX2, etc.), if it’s not SIP.

Next, create a CUSTOM trunk. In the Dial text box, enter this:

Local/[email protected]

Finally, have your route use the custom trunk rather than calling one of the two trunks directly. NOTE THAT ALL OF THIS IS UNTESTED - please let us know if it works for you!

Hello!

I have no gateways now so I tried to check if it works calling two different extensions, day-extension and night-extension. What I can see is that if I am at night it will execute:

exten => _[*0-9]!,n,Dial(SIP/night-extension)

and If night-extension is busy then it will Dial:

exten => _[*0-9]!,n(dayselect),Dial(SIP/day-extension)

Would it have the same behaviour dialing through the SIP Gateway?

Regards

So try this:

[custom-timeselect]
exten => _[*0-9]!,1,GotoIfTime(08:00-05:00|*|*|*?dayselect)
exten => _[*0-9]!,n,Dial(SIP/[b][i]nighttrunk[/i][/b]/${EXTEN})
exten => _[*0-9]!,n,Goto(app-blackhole,congestion,1)
exten => _[*0-9]!,n(dayselect),Dial(SIP/[b][i]daytrunk[/i][/b]/${EXTEN})
exten => _[*0-9]!,n,Goto(app-blackhole,congestion,1)
exten => h,1,Hangup()

That should prevent the unwanted fallthru if the trunk is unavailable. Note that if fallthru does occur at the trunk level, that implies that you could add additional trunks to try before giving up, though I’m not sure if it would work that way with a trunk or not. In any case I’m going to edit my original post to add the congestion statements - they can’t hurt anything and would stop unwanted fallthru. Again, please let me know how this works for you.