Time conditions for outbound routes

Discussion in 'General' started by kalderista, Jan 21, 2009.

  1. kalderista

    Joined:
    Oct 21, 2008
    Messages:
    179
    Likes Received:
    0
    Hi!

    Is it possible to set up time conditios for outbound routes. I want to call with differents trunks, and I have differents rates depending on the time, so I need to set up this.

    Any idea?

    Thanks.
     
  2. Mirko87

    Joined:
    Oct 20, 2008
    Messages:
    128
    Likes Received:
    0
    I don't think so... Because the Outbound depends directly by you.. So that.. if you want to call with another number you have to use the dial patterns.

    By the way the yours is a interesting problem, because if you don't use directly the PBX, but you want to make up a good service for a customer, you can't say to the customer: "Ehy, if it's afternoon dial with the 9 before the number...".

    Mirko
     
  3. kalderista

    Joined:
    Oct 21, 2008
    Messages:
    179
    Likes Received:
    0
    I see.

    It could be a nice functionality. Time to wait for the future...

    Thanks.
     
  4. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
  5. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
    I'll also suggest you try dicko's suggestion, but be aware that Custom Contexts is an unsupported third-party module, so every time FreePBX is upgraded you risk breakage.

    Another possible approach would be to do something along the lines of what's described in How to give a particular extension different or restricted trunk access for outgoing calls - you will probably have to read that (especially the last few paragraphs) to understand what I'm about to say.

    You could create two routes, one with all your usual dial patterns but with 0000329| prepended to each pattern and the other with 0000648| prepended to each pattern (you can use any two codes you want, but 329=DAY and 648=NITe on a touch tone pad, that's why I picked them for this example).

    Then you could add something like this (note this is incomplete, and that it is looking for U.S./Canada style numbers) to /etc/asterisk/extensions_custom.conf:

    Code:
    [custom-day-night]
    ;You need some dialplan code here to figure out what time it is
    ;if it is day go here
    exten => _1NXXNXXXXXX,1,Goto(from-internal,0000329${EXTEN},1)
    exten => _NXXNXXXXXX,1,Goto(from-internal,0000329${EXTEN},1)
    exten => _NXXXXXX,1,Goto(from-internal,0000329${EXTEN},1)
    exten => _.,1,Goto(from-internal,${EXTEN},1)
    ;else if it is night go here
    exten => _1NXXNXXXXXX,1,Goto(from-internal,0000648${EXTEN},1)
    exten => _NXXNXXXXXX,1,Goto(from-internal,0000648${EXTEN},1)
    exten => _NXXXXXX,1,Goto(from-internal,0000648${EXTEN},1)
    exten => _.,1,Goto(from-internal,${EXTEN},1)
    exten => h,1,Hangup()
    
    Then send your extensions to custom-day-night instead of from-internal. The only part of this I'm not showing you, because I've never had to code it, is how to determine what the time is. If you look at the page on Asterisk variables you can see all the predefined channel variables, some of which deal with the time. Also as a bonus, here is my time-of-day routine that may give you some idea of how these variables are used:

    Code:
    [custom-speaking-clock]
    exten => _.,1,Noop(Entering Custom Context: Speaking Clock Modified)
    exten => _.,n(est),NoOp(Speaking Clock for Eastern Time Zone)
    exten => _.,n,Set(TimeZn=EST5EDT)
    exten => _.,n,goto(scstart)
    exten => _.,n(cst),NoOp(Speaking Clock for Central Time Zone)
    exten => _.,n,Set(TimeZn=CST6CDT)
    exten => _.,n(scstart),Ringing
    exten => _.,n,Set(FutureTime=$[${EPOCH} + 8])
    exten => _.,n,Set(FutureTimeMod=$[${FutureTime} % 10])
    exten => _.,n,Set(FutureTime=$[${FutureTime} - ${FutureTimeMod}])
    exten => _.,n,Set(MaxConnectTime=$[${FutureTime} + 180])
    exten => _.,n(scringsomemore),Set(FutureTimeMod=$[${FutureTime} - ${EPOCH}])
    exten => _.,n,GotoIf($["${FutureTimeMod}" < "0"]?scanswer:scwaitasec)
    exten => _.,n(scwaitasec),wait(1)
    exten => _.,n,goto(scringsomemore)
    exten => _.,n(scanswer),Answer
    exten => _.,n(scplayagain),Set(FutureTime=$[${FutureTime} + 10])
    exten => _.,n,Set(FutureTimeMod=$[${FutureTime} % 60])
    exten => _.,n,wait(1)
    exten => _.,n,playback(at-tone-time-exactly)
    exten => _.,n,SayUnixTime(${FutureTime},${TimeZn},IM)
    exten => _.,n,GotoIf($["${FutureTimeMod}" = "0"]?scexactmin:scsaysecs)
    exten => _.,n(scexactmin),SayUnixTime(${FutureTime},${TimeZn},p)
    exten => _.,n,goto(scwaittobeep)
    exten => _.,n(scsaysecs),playback(and)
    exten => _.,n,SayUnixTime(${FutureTime},${TimeZn},S)
    exten => _.,n,playback(seconds)
    exten => _.,n(scwaittobeep),Set(FutureTimeMod=$[${FutureTime} - ${EPOCH}])
    exten => _.,n,GotoIf($["${FutureTimeMod}" < "1"]?scplaybeep:scwaitsectobeep)
    exten => _.,n(scwaitsectobeep),wait(1)
    exten => _.,n,goto(scwaittobeep)
    exten => _.,n(scplaybeep),playback(beep)
    exten => _.,n,Set(FutureTimeMod=$[${MaxConnectTime} - ${EPOCH}])
    exten => _.,n,GotoIf($["${FutureTimeMod}" < "1"]?scthatsall:scplayagain)
    exten => _.,n(scthatsall),GotoIf($["x${IVR_CONTEXT}" = "x"]?app-blackhole,hangup,1:${IVR_CONTEXT},return,1)
    exten => _.,n,Goto(app-blackhole,hangup,1)
    exten => h,1,Macro(hangupcall,)
    
    In the above code there are entry points for Eastern time or Central time - I use this by making a Custom Destination (from the Unembedded FreePBX Tools menu) that makes a call to
    Code:
    custom-speaking-clock,${EXTEN},est
    
    or for Central time
    Code:
    custom-speaking-clock,${EXTEN},cst
    
    And then using the appropriate Custom Destination as the target of a Misc Application. But the important thing here is that you can (perhaps) see how the code starts with the EPOCH variable and then does some fancy math to break out the time of day.

    Now, I hear you wondering if you could use the Time Conditions module in FreePBX to determine the time, instead of doing messy dial plan math. To which I would answer, sure you could, except for one thing. You could make the destinations of the Time Condition two Custom Destinations, each of which prepends the necessary code (0000329 or 0000648 using our previous example) and then goes to from-internal. The problem would be figuring out how to go from the extensions to the time condition. Maybe if you created the Time Conditions and then examined /etc/asterisk/extensions_additional.conf you could find the entry point for the time condition, then send your extensions there (instead of directly to from-internal). As I say, I've never tried to do this, but it shouldn't be too awfully difficult to figure out if you know anything at all about Asterisk dial plans.

    If you get it to work, please let us know which approach you used.
     
  6. wiseoldowl

    Joined:
    Aug 19, 2008
    Messages:
    251
    Likes Received:
    0
    I know this thread is a bit stale, but this question came up again tonight in a FreePBX forum, and I had a momentary flash of inspiration (or maybe it was indigestion, not really sure). :) Anyway, here's what I wrote there:

    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/nighttrunk/${EXTEN})
    exten => _[*0-9]!,n,Goto(app-blackhole,congestion,1)
    exten => _[*0-9]!,n(dayselect),Dial(SIP/daytrunk/${EXTEN})
    exten => _[*0-9]!,n,Goto(app-blackhole,congestion,1)
    exten => h,1,Hangup()

    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/$OUTNUM$@custom-timeselect

    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!
     

Share This Page