Asterisk+FreePBX禁止员工将通话转接至手机号的方案咨询
Got it, let's sort this out for you. You need to stop employees from transferring incoming calls to mobile numbers, but still let them dial mobiles directly — that’s a common requirement, and totally doable with FreePBX + Asterisk. Here are three solid methods to make this work:
Method 1: Custom Dialplan via FreePBX Custom Contexts
This is a flexible approach that lets you fine-tune exactly what gets blocked during transfers:
- Head to FreePBX → Admin → Custom Contexts and create a new context (name it something like
restrict-transfer-to-mobile). - Paste this dialplan code into the context (adjust the number patterns to match your region's mobile prefixes — example uses Chinese mobile numbers):
Theexten => _1[358]XXXXXXXXX,1,GotoIf($["${TRANSFERER}"!=""]?block:allow) exten => _1[358]XXXXXXXXX,n(block),Playback(privacy-you-are-not-authorized)&Hangup() exten => _1[358]XXXXXXXXX,n(allow),Dial(SIP/${EXTEN},20) # Add rules for numbers with country code too exten => _+861[358]XXXXXXXXX,1,GotoIf($["${TRANSFERER}"!=""]?block:allow) exten => _+861[358]XXXXXXXXX,n(block),Playback(privacy-you-are-not-authorized)&Hangup() exten => _+861[358]XXXXXXXXX,n(allow),Dial(SIP/${EXTEN},20)TRANSFERERvariable checks if the call is being transferred by a user — if yes, it blocks the mobile number; if it's a direct dial, it proceeds normally. - Assign this context to your employees' extensions: Go to FreePBX → Applications → Extensions, edit the target extension, switch to the Advanced tab, and set the
Contextto your new custom context (or add it toInclude Contextsif you want to keep existing rules). - Reload FreePBX config with
fwconsole reloadand test.
Method 2: Use FreePBX's Context Restrictions Module
If you prefer a GUI-based approach without editing code, the Context Restrictions module is perfect:
- First, install the module: Go to FreePBX → Admin → Module Admin, search for "Context Restrictions", install it, and enable it.
- Create a restriction rule: Navigate to Applications → Context Restrictions → Add Rule
- Name it something clear like "Block Transfer to Mobile"
- Set Restriction Type to "Transfer"
- Add your mobile number patterns under Dial Patterns (e.g.,
_1[358]XXXXXXXXX,_+861[358]XXXXXXXXX) - Set Action to "Block" and pick a warning prompt (like "privacy-you-are-not-authorized")
- Assign the rule to your employees: Go to Applications → Context Restrictions → Assign Rules, select the extensions you want to restrict, and link them to your new rule.
- Apply the config and test the transfer functionality.
Method 3: Direct Asterisk Config Edit (For Advanced Users)
If you're comfortable editing Asterisk files directly, modify extensions_custom.conf (never edit core files like extensions.conf directly — FreePBX will overwrite them):
- Open the file with your favorite editor:
nano /etc/asterisk/extensions_custom.conf - Add this code to the
[from-internal-custom]section (adjust number patterns as needed):[from-internal-custom] exten => _1[358]XXXXXXXXX,1,GotoIf($["${TRANSFERER}"!=""]?10:20) exten => _1[358]XXXXXXXXX,10,Playback(privacy-you-are-not-authorized) exten => _1[358]XXXXXXXXX,11,Hangup() exten => _1[358]XXXXXXXXX,20,Dial(SIP/${EXTEN},20) # Add country code variant exten => _+861[358]XXXXXXXXX,1,GotoIf($["${TRANSFERER}"!=""]?10:20) exten => _+861[358]XXXXXXXXX,10,Playback(privacy-you-are-not-authorized) exten => _+861[358]XXXXXXXXX,11,Hangup() exten => _+861[358]XXXXXXXXX,20,Dial(SIP/${EXTEN},20) - Save the file and restart Asterisk:
fwconsole restart
Quick Tips
- Always test both scenarios: Try transferring an incoming call to a mobile (should be blocked) and dialing a mobile directly (should work).
- Adjust the number patterns to match your region's mobile formats — for example, US numbers would use
_1[2-9]XX[2-9]XXXXXX. - If you need to block international mobiles, add patterns for those country codes too.
内容的提问来源于stack exchange,提问作者okamigo
相关产品推荐
相关产品推荐

