How to execute custom code at start of macro-user-callerid?

To my knowledge, it is considered good practice place your own dialplan code in -custom contexts in _custom.conf files.

In the extensions_additional.conf the [macro-user-callerid] starts with
include => macro-user-callerid-custom

The place of this line seems to indicate that the included code is executed at the start of the macro,

However, the documentation of the include statement, e.g. on, states

Order of execution when using include statements

Asterisk will always look for a match in the current context before referencing any included contexts. If a matching entry is found, that entry is used. If no matching entry is found, Asterisk will look for a match in the first included context, then the next, and so on. It is also possible to have nested includes; that is, includes within includes.

Since you can only use the s extension in a macro,it looks like the custom include code is always executed last, if ever.
This seems also to be confirmed by a CLI show dialplan @macro-user-callerid, and also by viewing the dialplan executed,.

How and where can I place dialplan code which is excuted at the start of the [macro-user-callerid]?

this is a fatal issue, i had the same issue with callback, i was unable to check callerid numebr before passing to callback using macro-callback-custom (or something similar i did not remember)

imho, until this is not fixed, custom arrangements into dialplan are not feasible


every auto-generated context has an include => contextname-custom

In many cases, this is not usable, as you have learned from reading how Asterisk processes includes. This is just auto-generated everywhere as there is no harm and some places it is useful.

If you want to put your own code in an auto-generated context, you have two options:

You can write a module that spices into the beginning of the context and adds your code. Have a look at modules like blacklist which do that with inbound routes, or languages which splice into the middle of macro-user-callerid.

Your other option is to completely re-define the entire macro by copying it into the override file and then modifying it. Be very careful if you do this. First keep in mind that future updates to that macro, like new functionality or bug fixes, will be overwritten by your change. Secondly, make sure you replace every single priority that is in the original macro or include appropriate ‘hangup’ or alternative instructions because anything that you don’t cover will have ours blended into yours and you can get some really hard to find bugs.

As I see it now, this problem still exists, right?

Why not just start every auto-generated context at priority, say, 100 and use something like “s,n+10” (I think I read somewhere that this works)

This way, you would be able to actually use the custom macro contexts or am I missing something?

i think it’s not really fixed … i’ve got the same problem.
i wish i can do some change in the custom files.
my way is to copy the macro vom additional to override and make my changes … every time i make a update of freepbx i have to check if the macro has new code … no good solution