Page 1 of 1

Renaming / Duplicating the wizard dial plans

Posted: Thu Dec 08, 2011 5:04 am
by raj2ras
Aaron,

Awesome job on the "Simple Wizard" dial plan. If you could add a feature to rename them and duplicate them, that would help. Currently no easy way to do it on any of the wizard DPs.

Re: Renaming / Duplicating the wizard dial plans

Posted: Thu Dec 08, 2011 10:36 am
by Aaron
Ok I'll add the request to the list. In regards to the duplication why would you do that?

Re: Renaming / Duplicating the wizard dial plans

Posted: Fri Dec 09, 2011 2:04 am
by raj2ras
Duplication just for testing/backup of different routing scenarios.

Also, do the wizards create/link to a "Ruby script" in the back? Is there any way to export/dump it out to a .txt file ? Lets say as one's Ruby skill improves, one can manipulate them further at code level.

Re: Renaming / Duplicating the wizard dial plans

Posted: Sun Dec 11, 2011 12:41 am
by Aaron
The Ruby script behind the Simple Wizard is as below. It's unlikely to be that useful since it doesn't create a normal line by line script of call forwards. Instead it works by retrieving and processing each simple wizard rule from a database table.

As an alternative you could take a look at mnipp's wizard at http://free2call.me/rubywizard.html which does generate a line-by-line script.

Code: Select all

def ProcessMatch(matchedRule)
	sys.Log("SimpleWizard matched on rule with #{matchedRule.Pattern}, command #{matchedRule.Command}, #{matchedRule.RuleCommandDescription}.")
	case matchedRule.Command
		when "Dial"
			sys.Dial(matchedRule.CommandParameter1 + "@" + matchedRule.CommandParameter2)
		when "DialAdvanced"
		    ringTime = matchedRule.CommandParameter2 != nil ? matchedRule.CommandParameter2.to_i : 0
			callDuration = matchedRule.CommandParameter3 != nil ? matchedRule.CommandParameter3.to_i : 0
			sys.Dial(matchedRule.CommandParameter1, ringTime, callDuration)
		when "Reject"
			sys.Respond(matchedRule.CommandParameter1.to_i, matchedRule.CommandParameter2)
		else
			sys.Log("Error command #{matchedRule.Command} not recognised.")
	end
end

sys.Log("SimpleWizard processing commenced.")
if sys.Out
	rules = lookup.GetSimpleWizardRules(sys.DialPlanName, "Out")
	rules.each{|rule| 
		#sys.Log("#{rule.Pattern} #{rule.Command} #{rule.RuleCommandDescription}")
		if rule.PatternType == "Exact" && rule.Pattern == req.URI.User
			ProcessMatch(rule)
		elsif rule.PatternType == "Prefix"
		    prefixPattern = "^" + rule.Pattern.TrimStart('_')
			prefixPattern = prefixPattern.sub("X", "[0-9]")
			prefixPattern = prefixPattern.sub("Z", "[1-9]")
			prefixPattern = prefixPattern.sub("N", "[2-9]")
			prefixPattern = prefixPattern.sub("*", "\*")
			prefixPattern = prefixPattern.sub("+", "\+")
		    if req.URI.User =~ /#{prefixPattern}/
			  ProcessMatch(rule)
			end
		elsif rule.PatternType == "Regex" && req.URI.User =~ /#{rule.Pattern}/
			ProcessMatch(rule)
		end
	}
else
	sys.Log("Incoming rule, FromName=#{req.Header.From.FromName}, FromURI=#{req.Header.From.FromURI.ToParameterlessString()}.")
	rules = lookup.GetSimpleWizardRules(sys.DialPlanName, "In")
	rules.each{|rule| 
		#sys.Log("#{rule.Pattern} #{rule.Command} #{rule.RuleCommandDescription}")
		if ((rule.ToSIPAccount == nil || rule.ToSIPAccount == (req.URI.User + "@" + sys.GetCanonicalDomain(req.URI.Host)) || 
				rule.ToSIPAccount == (req.URI.User.sub(/^.*\./, "") + "@" + sys.GetCanonicalDomain(req.URI.Host))) &&
		   (rule.TimePattern == nil || rule.IsTimeMatch(System::DateTimeOffset.UtcNow, sys.GetTimezone)) &&
		   (rule.Pattern == nil || req.Header.From.FromName =~ /#{rule.Pattern}/ || req.Header.From.FromURI.ToParameterlessString() =~ /#{rule.Pattern}/)) then
		     ProcessMatch(rule)
			 break
		end
	}
end

Re: Renaming / Duplicating the wizard dial plans

Posted: Mon Dec 12, 2011 2:04 am
by raj2ras
Hmmm... Too complex for my simple needs :shock: , but thanks for sharing. Some day I may be able to comprehend!