Build on episode 06 by routing one approved destination from authenticated extensions 7101 and 7102. The example removes local access digit 9 and adds 86 only for a trunk that expects it. The FreeSWITCH v1.10.12 template and current documentation were checked. No live carrier calls were made.
Separate the dial string from the trunk destination
Record the number received by FreeSWITCH, the destination used for policy, and the string sent to the carrier. A handset can rewrite input before FreeSWITCH sees it. RFC 3966 distinguishes telephone numbers from dial strings, including local dialing instructions. A globally formatted number in your application does not determine the formatting required by a particular trunk.
Replace the existing test rule
Locate the actual configuration directory and the default context used by 7101 and 7102. Back up episode 06's dialplan/default/06_training_outbound.xml outside the included directory. Install the following as 07_training_outbound.xml in that directory. Review the location of the default/*.xml include and any earlier matching rule.
<include>
<!-- 沿用06期鉴权范围,只在内部default上下文加载 -->
<extension name="training-outbound-07">
<condition field="${sip_auth_username}" expression="^(?:7101|7102)$"/>
<!-- 替换为唯一获准的测试号码,暂时保留占位符即可做静态检查 -->
<condition field="destination_number" expression="^9(YOUR_TEST_NUMBER)$">
<!-- 只取括号捕获的号码,去掉接入码9 -->
<action application="set" data="training_number=$1"/>
<!-- 示例中继需要86前缀,仅在运营商确认后启用 -->
<action application="set" data="training_carrier_number=86${training_number}"/>
<!-- 沿用06期已验收的gateway,只在授权测试环境拨打 -->
<action application="bridge" data="sofia/gateway/training_carrier_reg/${training_carrier_number}"/>
<action application="hangup"/>
</condition>
</extension>
</include>
Replace YOUR_TEST_NUMBER with exactly one approved digits-only destination. Keep the anchors and capture group. Use the 86 concatenation only if the number lacks the country code and your carrier explicitly requires this format. Otherwise assign ${training_number} directly if the trunk expects domestic digits. Substitute the existing IP-authenticated gateway name if that was your choice in episode 06.
Understand the match and transformation
The first condition checks the authenticated channel identity. Caller ID is insufficient for this check. The noncapturing group does not consume a numbered capture. A failed condition stops subsequent conditions in this extension under the default break behavior. Other extensions can still be evaluated, so audit broader rules as well.
The second condition matches the complete destination. Digit 9 sits outside the capture, so $1 contains only the approved number. The set actions keep the stripped form and construct the carrier form without overwriting destination_number. The bridge reuses your existing trunk. It does not answer the inbound leg before attempting the bridge.
Add formats explicitly
Use a literal plus pattern such as [+] when matching a global form. Give each accepted format and allowed destination range an explicit rule before converting it. Blindly removing punctuation or prepending a country code can mishandle local numbers or extension parameters. Check any gateway destination-prefix before adding a prefix in the dialplan. Keep emergency, short-code and international routes outside the test change.
Verify the result and retain a rollback
Run reloadxml and inspect parsing errors. In a nonproduction environment, check three points. Use 7101 and 7102 to dial the approved target and compare the received destination, captured value and outbound Request-URI user. Try an adjacent number, a missing digit and an unauthorized test account to confirm this rule does not match and no broader route takes over. Verify that extension calling, IVR 7180 and queue 7190 still work. Redact signaling records. Live carrier tests can incur charges.
For a missed match, check the context, received destination, authenticated identity and earlier extensions. A successful reload alone does not prove your fragment was included. For a missing digit, inspect the capture before changing the carrier settings. For a doubled 86, check both dialplan and gateway rewriting. If the destination is correct and rejected, use the carrier response to inspect permissions and caller identity.
To roll back, move the new fragment out of the included directory, restore the episode 06 backup and run reloadxml. Repeat the authorized and internal routing checks. This XML-only change does not require restarting the trunk profile.