Context in asterisk

I’m using asterisk. But I don’t understand many context in asterisk. Context in file zapata.conf

hidecallerid=no callwaitingcallerid=yes ;threewaycalling=yes ;cancallforward=yes ;callreturn=yes [b]context=from-zaptel[/b] signalling=fxs_ks usecallerid=yes echocancel=yes echocancelwhenbridged=no echotraining=800 rxgain=4.0 txgain=4.0 rxwink=300 group=0 pickupgroup=0 channel=1-4 immediate=yes

And context in sip_general_additional.conf

vmexten=*97 disallow=all allow=ulaw allow=alaw [b]context=from-internal[/b] callerid=Unknown notifyringing=yes notifyhold=yes limitonpeers=yes tos_sip=cs3 tos_audio=ef tos_video=af41

And in configure of a agent

[1001] type=friend secret=1001 qualify=yes port=5060 pickupgroup= nat=yes mailbox=1001@device host=dynamic dtmfmode=rfc2833 dial=SIP/1001 [b]context=from-internal[/b] canreinvite=no callgroup= callerid= 1001 <1001> accountcode= call-limit=50

I don’t understand when any incoming call or internal call then which context is used at the biginning? such as “from-zaptel” or “from-internal”?

Thanks in advance!

A context is a place in your dialplan where an incoming call will enter it.

A call from your PSTN-line will enter your dialplan in the context [from-zaptel].
A SIP-phone will enter your dialplan in the context [from-internal].

So in extensions.conf you will find :

[code][from-zaptel]
exten => s,1,NoOP(do something)
exten => s,n,Dial(someone)

[from-internal]
exten => 1001,1,Dial(SIP/1001)
exten => 1002,1,Dial(someone)[/code]

By letting a SIP/IAX-client or a trunk entering your dialplan in a certain context, you limit this ‘user’ to be able to call certain extensions and execute certain dialplan-logic.
You can also see this as a sort of built-in security.

[quote=“jonaskellens”]A context is a place in your dialplan where an incoming call will enter it.

A call from your PSTN-line will enter your dialplan in de context [from-zaptel].
A SIP-phone will enter your dialplan in the context [from-internal].

So in extensions.conf you will find :

[code][from-zaptel]
exten => s,1,NoOP(do something)
exten => s,n,Dial(someone)

[from-internal]
exten => 1001,1,Dial(SIP/1001)
exten => 1002,1,Dial(someone)[/code]

By letting a SIP/IAX-client or a trunk entering your dialplan in a certain context, you limit this ‘user’ to be able to call certain extensions and execute certain dialplan-logic.
You can also see this as a sort of built-in security.[/quote]

Thanks you! now I understard. But with configure following:

[from-zaptel] exten => s,1,NoOP(do something) exten => s,n,Dial(someone)

When inbound calls, "from-zapte"l context is loaded the first. But when outbound calls what context is loaded the first? from-zaptel or from-internal

[quote=“manhhoa1611”]When inbound calls, "from-zapte"l context is loaded the first. But when outbound calls what context is loaded the first? from-zaptel or from-internal[/quote]When your user agent [1001] makes a call, it is defined in his SIP-account that a call will enter the dialplan in the context [from-internal].
You defined this in his SIP-account :

[1001] type=friend secret=1001 qualify=yes port=5060 pickupgroup= nat=yes mailbox=1001@device host=dynamic dtmfmode=rfc2833 dial=SIP/1001 context=from-internal canreinvite=no callgroup= callerid= 1001 <1001> accountcode= call-limit=50
The extensions you have defined in your context [from-internal] are the extensions that this user can call.

Example :[code][from-internal]
exten => _888XXX,1,Dial(SIP/${EXTEN})

[from-internal-2]
exten => 300,1,Dial(SIP/${EXTEN})[/code]…makes that your user 1001 can form a number of 6 digits where the first 3 need to be an ‘8’. The dialed extension will be contacted through a SIP-channel.
User [1001] will not be able to call extension 300 !

It’s not about what context gets loaded first… or what context is defined first in extensions.conf.

openboox.com/book/asterisk_the_f … nd_edition