3
votes

I'm new to asterisk, and I have an issue about using include statement.

I have a context named "app-calltrace-perform" from FreePBX, used when people press *69 to trace their call.

[app-calltrace-perform]
include => app-calltrace-perform-custom
exten => s,1,Answer
...
exten => t,n,Macro(hangupcall,)

The "app-calltrace-perform" written in extensions_additional.conf which will be overwritten when users submit something about dialplan on the Web gui. So I have to write my own context "app-calltrace-perform-custom" on another file called extensions_custom.conf

[app-calltrace-perform-custom]
exten => s,1,Answer()
same => n,VERBOSE("Something here")
same => n,Playback(hello-world)
same => n,Hangup()

Note that extensions_additional.conf and extensions_custom.conf was already included from extensions.conf

Then I do dialplan reload and try again, but dialplan do not play my context at all (no verbose, no play hello-world).

I've found something useful in https://wiki.asterisk.org/wiki/display/AST/Include+Statements+Basics

Asterisk will always try to find a matching extension in the current context first, and only follow the include statement to a new context if there isn't anything that matches in the current context.

So now I dont know how to use my custom context for stuffs like this. Sorry if this a dumb question, but if you have any idea, pleas guide me through.

Edit
This is where app-calltrace-perform called from

[app-calltrace] include => app-calltrace-custom exten => *69,1,Goto(app-calltrace-perform,s,1)

Now i'm using another extension (*12345) defined in context app-calltrace-custom, It works well but is hard coded so cannot modified by the Web Gui

End Edit

Thanks in advance
Loi Dang

2

2 Answers

3
votes

Asterisk dialplan matching work this way

[context1]
exten => 1,1,Noop(1)
include =>context2
include =>context3
exten => i,1,Noop(invalid extension)
[context2]
exten => 1,1,Noop(2)
exten => 2,1,Noop(3)
[context3]
exten => 1,1,Noop(4)
exten => 2,1,Noop(5)
exten => _X,1,Noop(other)

Let's say you call context1

when called 1 will be selected command from context1, becuase it EXIST in context. Same if you use wildcard.

When called 2 will be selected 2 from context2, first included context When called any other number (for example 3) will be selected "other" in context3(becuase it not presented in context nor in prevous included context)

If called 12 which not present in any contextes, will be execute "invalid" extension

2
votes

You'll need to have something that's distinguishing in your included context in order for the dialplan to know to use it. Since you've used the s extension in both, it uses the matching extension in the current context, first. As you've found in the documentation.

The s extension is the "start" extension, and used when there's no known dialed extension.

First, double check your file include is in the [globals] context in extensions.conf

[globals]
#include extensions_custom.conf

Then, include as you have done:

[app-calltrace-perform]
include => app-calltrace-perform-custom
exten =>   s,1,Answer
same =>      n,Noop(Testing 1234)
same =>      n,Hangup()

But, you need something differentiating in your included context. So for example:

[app-calltrace-perform-custom]
exten => *69,1,Answer()
same =>      n,Playback(hello-world)
same =>      n,Hangup()

So if you have a device that uses the [app-calltrace-perform] and they dial *69, they'll be subject to the [app-calltrace-perform-custom] extension.

Also, it's considered good practice to have a Hangup() ending each included context as you've done (good job). In order to prevent a possible mistake resulting in toll-fraud. Just wanted to note that for future stackoverflowers.