Selecting chars from ${EXTEN} variable in Simple Wizard

Feedback, issues & questions regarding the use of the Telis Wizard and Simple Wizard dial plans.
raj2ras
Posts: 132
Joined: Tue Nov 08, 2011 2:13 am

Selecting chars from ${EXTEN} variable in Simple Wizard

Postby raj2ras » Tue Jul 10, 2012 8:43 pm

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 ?

User avatar
Aaron
Site Admin
Posts: 4550
Joined: Thu Jul 12, 2007 12:13 am

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

Postby Aaron » Thu Jul 12, 2012 4:04 pm

Try using a dial string value of #{req.URI.User[0, 10]}.

raj2ras
Posts: 132
Joined: Tue Nov 08, 2011 2:13 am

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

Postby raj2ras » Fri Jul 13, 2012 10:21 pm

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.

raj2ras
Posts: 132
Joined: Tue Nov 08, 2011 2:13 am

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

Postby raj2ras » Fri Jul 13, 2012 10:55 pm

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

User avatar
Aaron
Site Admin
Posts: 4550
Joined: Thu Jul 12, 2007 12:13 am

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

Postby Aaron » Sat Jul 14, 2012 8:54 am

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.

raj2ras
Posts: 132
Joined: Tue Nov 08, 2011 2:13 am

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

Postby raj2ras » Mon Jul 23, 2012 4:52 pm

waiting...

User avatar
Aaron
Site Admin
Posts: 4550
Joined: Thu Jul 12, 2007 12:13 am

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

Postby Aaron » Sun Jul 29, 2012 2:04 am

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]}.

raj2ras
Posts: 132
Joined: Tue Nov 08, 2011 2:13 am

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

Postby raj2ras » Wed Aug 01, 2012 5:30 am

Thanks. Working fine now :-)


Return to “Dial Plan Wizards (Telis & Simple)”

Who is online

Users browsing this forum: No registered users and 1 guest