Thanks to this original post by TheFug and input from MikeTelis we have had a good timing function on incoming calls. I have now added a day of the week option into the following inplan.
If you need more flexible timing on what phone rings on what day and time my new inplan with a time setting dialler function can give you these options.
This should make it easy to setup complex forwarding rules across various phones on different days and times of the day and different time-zones if needed.
The day settings are:
Sunday(0) to Saturday(6) for everyday calling
Saturday(6) to Sunday(0) for weekend only calling
Monday(1) to Friday(5)
wednesday(3) to wednesday(3) for wednesday only calling
inplan
Code: Select all
# inplan Set time defaults in dialler below,
# example (0730)7:30am (2330)11:30pm everyday Sunday(0) to Saturday(6) (GMT+11 hour) TimeZone.
$status = "Call Later" # default status message
def dialler(tocall, timer=60, starttime="0730", stoptime="2330", startday=0, endday=6, tz=11)
t = Time.now.utc + (tz*60*60)
logtime = t.strftime("%A(%w) (%H%M)%I:%M %p")
sys.log("#{logtime}") # Check Day and Time in Console output.
openday = startday > endday ? !(((endday+1)..(startday-1)) === t.wday) : (startday..endday) === t.wday
if openday
hhmm = t.strftime("%H%M")
openhours = stoptime < starttime ? !((stoptime...starttime) === hhmm) : (starttime...stoptime) === hhmm
if openhours
sys.log("calling #{tocall}")
$status = sys.Dial(tocall, timer)
sys.log("failed call to #{tocall}")
end
end
end
# The Following sets the incoming CALLERID NAME if not set
fromname = req.Header.From.FromName.to_s # create a copy of FromName
username = req.Header.from.FromURI.User.to_s # create a copy of userName
if fromname == "" or fromname == username # if FromName empty or the same as username
if username =~ /^[0-9]*[0-9]$/
fromname = req.Header.From.FromURI.host.to_s # if a number display caller's host, else full address.
else
fromname = username + " " + req.Header.From.FromURI.host.to_s
end
end
sys.SetFromHeader(fromname, nil, nil) # Set FromName for sys.Dial
sys.Log("FromName: '#{fromname}'")
dialler("#{sys.Username}@local",20) # 20sec ring between default times 7:30am to 11:30pm everyday
dialler("0487654321@ptel",20,"1700","1800",1,5) # mobile 5:00pm to 6:00pm Monday to Friday
dialler("0487654321@ptel",20,"0800","2200",6,0) # same mobile 8:00am to 10:00pm Saturday to Sunday
code = 480
if $status.to_s == 'Failed' then
$status = 'Busy or Offline'
code = 486
end
sys.log("failed code:#{code} #{$status}")
sys.Respond(code, "#{$status}")