Dialplan pattern matching

exten => _XXXXXXX,1,Set(CALLERID(all)=“MT” <7182123456>)
same => n,Dial(SIP/1718${EXTEN}@flowroute,30,r)
same => n,Hangup

exten => _XXXXXXXXXX,1,Set(CALLERID(all)=“MT” <7182123456>)
same => n,Dial(SIP/1${EXTEN}@flowroute,30,r)
same => n,Hangup

Considering example above, depending on what was matched the second line changes. Is there a way to make single rule set, 3 lines instead of 6, that would work for both possibilities?

Also, can this portion “MT” <7182123456> be stored in a variable and reused with variable? Where and how can I do that?

Thanks in advance

What are the possible values of ${EXTEN}?

Depending on the answer, it may be easy to do it in four lines, or three if you realise that your third and sixth lines serve no useful purpose. Making it less than that is likely to result in much more complex code.

You can use variables, but you could have checked that for yourself.

exten => _NXXNXXXXXX,1,NoOP()
 same =>                      n,Set(CALLERID(all)="MT" <7182123456>)
 same =>                      n,Dial(SIP/1${EXTEN}@flowroute,30,r)
 same =>                      n,Hangup()
exten => _NXXXXXX,1,Goto(${CONTEXT},718${EXTEN},1)

It isn’t quite as short as you want but you get the idea.

[quote=“johnkiniston”] exten => _NXXNXXXXXX,1,NoOP() same => n,Set(CALLERID(all)="MT" <7182123456>) same => n,Dial(SIP/1${EXTEN}@flowroute,30,r) same => n,Hangup() exten => _NXXXXXX,1,Goto(${CONTEXT},718${EXTEN},1)
It isn’t quite as short as you want but you get the idea.[/quote]

Thanks a lot. This is excellent. In fact, as I used your example, I realized an answer to my original question, also.

If I match on regex target phone number, I could cancatenate substrings of “1718” and exten based on length.

If you know that there are no numbers in any other format, this should do it:

exten =>_X. ,1,Set(CALLERID(all)="MT" <7182123456>) exten => _XXXXXXX,n,Dial(SIP/1718${EXTEN}@flowroute,30,r) exten => _XXXXXXXXXX,s,Dial(SIP/1${EXTEN}@flowroute,30,r)

The disadvantage of this is that numbers not of the exact lengths will silently fail, rather than giving an an indication of the problem.

You could use _X. in the second line, so that all numbers at least get tried.

If these are NANP numbers with and without the long distance part, the other solution better reflects the underlying problem.