我用這個dial plan作為in plan就可以了. 我也是從網上copy and paste的, 略做了小修改. 如果哪位對語法領悟得好, 也許可以把這段代碼修改得更精練.
# ******************************* D I A L ********************************
# ******************************* M A I N ********************************
begin
sys.Log("** Call from #{req.Header.From.ToString()} to #{req.URI.User} **")
t = Time.now + ((Tz+8)*60*60) # Get current time and adjust to local. SS Server is in GMT-8
sys.Log(t.strftime('Local time: %c'))
if sys.In # If incoming call...
name = req.Header.from.FromURI.User.to_s # get a copy of caller's number
# Prefix 10-digit numbers with "1" (US country code).
# Some DID send Caller ID without country code
name = ('1' + name) if name =~ /^[2-9]\d\d[2-9]\d{6}$/
name.sub!(/^011/,'') # Remove 011 prefix added by Google Voice
sys.Log("FromName: '#{name}'")
req.Header.From.FromName = name # Set FromName for sys.Dial
# Change FromURI.User, too - or else Bria won't find contact in its phonebook!
req.Header.from.FromURI.User = name
sys.Log("FromName: '#{name}'")
req.Header.From.FromName = name # Set FromName for sys.Dial
if sys.IsAvailable() # If my ATA is registered
callswitch("#{sys.Username}@local") # forward all incoming calls to it
elsif (8..23) === t.hour # else forward calls to my home
sys.Log("#{sys.Username} is not online, forwarding call to home number...")
callswitch("0",35) # Note that '0' is in my speed dial list
end
sys.Respond(480, "#{sys.Username} Not online") # switch to voice mail
else # Outbound call ...
# check if it's URI or phone number.
# If destination's host is in our domain, it's a phone call
num = req.URI.User.to_s; reqHost = req.URI.Host.to_s # Get User and Host
host = reqHost.downcase.slice(/[^:]+/) # Convert to lowercase and delete optional ":port"
num
callswitch(num)
end
sys.Respond(@code,@reason) # Forward error code to ATA
rescue
# Gives a lot more details at what went wrong (borrowed from Myatus' dialplan)
sys.Log("** Error: " + $!) unless $!.to_s =~ /Thread was being aborted./
end