If Statement Recording – After Hours

Home » Asterisk Users » If Statement Recording – After Hours
Asterisk Users 5 Comments

In my dial plan I have these two lines:

exten => _NXXXXXX,n,Set(recordfilename=${CALLERID(num)}-${EXTEN}-${STRFTIME(${EPOCH},MST,%C%y-%m-%d-%H%M)}.wav)
exten => _NXXXXXX,n,MixMonitor(${recordfilename},b)

How to add “if” statement to execute these line only after let say 5pm. To record conversation only after 5pm.

5 thoughts on - If Statement Recording – After Hours

  • I’m trying to avoid type the same sub-routine on each pattern, so I included the time in [outgoing] first three lines.

    The way I understand if the time is past 17pm it will start recording, execute next two lines. But I’m not certain what will happen if the time is before 17pm will it go to “exten => 2 to it will go to in of the pattern in [goto-dialout].

    [outgoing]
    exten => s,1,GotoIfTime(17:00-24:00,*,*,*?outgoing,s,2) ;rec exten => s,n,Set(recordfilename=${CALLERID(num)}-${EXTEN}-${STRFTIME(${EPOCH},MST,%C%y-%m-%d-%H%M)}.wav)
    exten => s,n,MixMonitor(${recordfilename},b)

    include => blocked-numbers include => goto-dialout

    [goto-dialout]
    exten => _NXXXXXX,1,Dial(SIP/7780${EXTEN}@pstn-9998,60,tr)
    exten => _NXXXXXX,n,GotoIf($[$[“${DIALSTATUS}” = “BUSY”] | $[“${DIALSTATUS}” = “CONGESTION”]]?line2)
    exten => _NXXXXXX,n(line2),Dial(SIP/9780${EXTEN}@pstn-4444,60,tr)
    exten => _NXXXXXX,n,Hangup()

    exten => _18XXXXXXXXX,1,Set(CHANNEL(musicclass)

  • See ExecIf in the output of “core show applications”. The IF function might be useful, see “core show functions”. I assume the Asterisk Book also covers this.

    —–Original Message—

  • There are multiple ways to do time-of-day routing. ExecIf w/ IFTIME, GotoIfTime, and ExecIfTime. I put some examples below.

    Sincerely, Brian LaVallee

    [main]
    exten => _NXXXXXX,1,NoOP(Check Time)
    same => GotoIfTime(9:00-17:00,mon-fri,*,*?open:closed)
    [open]
    exten => _NXXXXXX,1,NoOP(Normal Call)
    [closed]
    exten => _NXXXXXX,1,NoOP(Take a Message)
    ; end

    [main]
    exten => _NXXXXXX,1,NoOP(Check Time)
    same => n,ExecIf(${IFTIME(9:00-17:00,mon-fri,*,*?1:0)}?Goto(closed))
    same => n,NoOp(Process Normal Call)
    [closed]
    exten => _NXXXXXX,1,NoOP(Take a Message)
    ; end

    [main]
    exten => _NXXXXXX,1,NoOP(Check Time)
    same => n,ExecIfTime(9:00-17:00,mon-fri,*,*?open)
    same => n,NoOp(Take a Message)
    [open]
    exten => _NXXXXXX,1,NoOP(Normal Call)
    ; end