Selecting chars from ${EXTEN} variable in Simple Wizard
Selecting chars from ${EXTEN} variable in Simple Wizard
In advanced dial, the "simple wizard" processes removing chars from front. For e.g. 00${EXTEN:3} will change 011971xxxx to 00971xxxx
Now, how do I extract only first 10 digits?
For e.g. re-dialled pattern on keypad is 188812312345678, I want only 1st 10 digits. But advanced dial -> ${EXTEN:0:10}@MyProvider does not work. How do I ?
Now, how do I extract only first 10 digits?
For e.g. re-dialled pattern on keypad is 188812312345678, I want only 1st 10 digits. But advanced dial -> ${EXTEN:0:10}@MyProvider does not work. How do I ?
Re: Selecting chars from ${EXTEN} variable in Simple Wizard
Try using a dial string value of #{req.URI.User[0, 10]}.
Re: Selecting chars from ${EXTEN} variable in Simple Wizard
I thought that was brilliant, but unfortunately does not work. Tried it both with "Dial" and "DialAdvanced" and also with {req.URI.User.to_s}
The value is never returned and the script interprets it as
The value is never returned and the script interprets it as
Code: Select all
DialPlan 22:16:39:985 sip1(4604): Information response 100 Trying for sip:#{req.URI.User.to_s}@voip.myprovider.com.
DialPlan 22:16:39:985 sip1(4604): Response 401 Unauthorized for sip:#{req.URI.User.to_s}@voip.myprovider.com.
Re: Selecting chars from ${EXTEN} variable in Simple Wizard
Unfortunately my Ruby knowledge is too rudimentary for deBugging. Pasting the SimpleWizard source code below for reference.
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: Selecting chars from ${EXTEN} variable in Simple Wizard
Unfortunately I'm not in a position to dig deeper into the issue at the moment, being on a family holiday, but will take another look when I get back which is in about a week.
Re: Selecting chars from ${EXTEN} variable in Simple Wizard
The approach I originally suggested was not supported. I've now modified the Simple Wizard Ruby script so that it is supported (but only in dial plan command parameters). So that means you can now use #{req.URI.User[0, 10]}.
Re: Selecting chars from ${EXTEN} variable in Simple Wizard
Thanks. Working fine now
Re: Selecting chars from ${EXTEN} variable in Simple Wizard
Can the Simple Wizard support parameters under DialAdvanced? For e.g. ${EXTEN:3}@Provider_Z[dt=5,fd=0987654321]
Ref: viewtopic.php?f=20&t=6483&p=27281&hilit ... +id#p27281
Ref: viewtopic.php?f=20&t=6483&p=27281&hilit ... +id#p27281