Page 1 of 2

Selecting chars from ${EXTEN} variable in Simple Wizard

Posted: Tue Jul 10, 2012 8:43 pm
by raj2ras
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 ?

Re: Selecting chars from ${EXTEN} variable in Simple Wizard

Posted: Thu Jul 12, 2012 4:04 pm
by Aaron
Try using a dial string value of #{req.URI.User[0, 10]}.

Re: Selecting chars from ${EXTEN} variable in Simple Wizard

Posted: Fri Jul 13, 2012 10:21 pm
by raj2ras
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

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

Posted: Fri Jul 13, 2012 10:55 pm
by raj2ras
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

Posted: Sat Jul 14, 2012 8:54 am
by Aaron
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

Posted: Mon Jul 23, 2012 4:52 pm
by raj2ras
waiting...

Re: Selecting chars from ${EXTEN} variable in Simple Wizard

Posted: Sun Jul 29, 2012 2:04 am
by Aaron
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

Posted: Wed Aug 01, 2012 5:30 am
by raj2ras
Thanks. Working fine now :-)

Re: Selecting chars from ${EXTEN} variable in Simple Wizard

Posted: Thu Jan 02, 2020 1:19 am
by raj2ras
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

Re: Selecting chars from ${EXTEN} variable in Simple Wizard

Posted: Thu Jan 02, 2020 10:17 am
by Aaron
Yes.