FreePBX: How to embed my code correctly?

Colleagues, I have been working with “clean” Asterisk all my life and I’m used to being in a situation where I write dialplan code “from scratch”.
Now I have a need to embed my code into an already working FreePBX installation and I don’t quite understand how to do it correctly. I really don’t want my code to be overwritten with new versions of the original FreePBХ files on the next update.

I need to include code to interact with the CRM information module, which would be executed when an incoming call comes in, when it is answered, and when the call ends. Queues are not used yet. Are there any standard methods for this in FreePBX?

Grateful for the replies,
Ogogon.

You can apply custom dial plans at Admin → Config Edit → extensions_custom.conf

@lgaetz also has a great session on working with custom dial plans.

Welcome to the forum @ogogon!

There are a few supported ways, it depends on what you want to do.

If you want to preprocess an inbound trunk call with dialplan before it hits an inbound route, you would set the trunk context GUI fields to something like from-trunk-preprocess (names are arbitrary) and then add the following to extensions_custom.conf:

[from-trunk-preprocess]
exten => _.,1,Noop(Entering user defined context from-trunk-preprocess in extensions_custom.conf)
exten => _.,n,     whatever
; addn'l lines as required
exten => _.,n,GoTo(from-trunk,${EXTEN},1)

Now suppose you want to add a FreePBX GUI destination with your own dialplan so you could set up a call flow in the GUI like Inbound Route → Custom Dialplan → Ring Group → etc. You do this with a Custom Destination. Browse to Admin, Custom Destination and add a gosub target to something like from-internal-ogogon,s,1 with this stub in extensions_custom.conf

[from-internal-ogogon]
exten => s,1,Noop(Entering user defined context from-internal-ogogon in extensions_custom.conf)
exten => s,n,     whatever
; addn'l lines as required
exten => s,n,Return

Enable the return option in the Custom Destination and choose the next step in the call flow.

There are dialplan hooks for use cases that don’t fit neatly into the above techniques which are discussed in detail here: Hooking for fun and income

You can see above how to add dialplan for incoming calls. In the same place you can add a hangup handler to have dialplan when the call ends. There is no easy way to hook the freepbx dialplan on call answer. Technically it can be done by overwriting the freepbx generated dialplan used for the call confirm option in FMFM, but it would be fragile. Thats something that could be done by monitoring AMI events.

1 Like

I see that when the local caller answers, the macro-auto-blkvm macro is called. The first line of this macro includes the macro-auto-blkvm-custom macro.

In the file extensions_custom.conf I created a macro with this name.

[macro-auto-blkvm-custom]
exten => s,1(start),NoOp(AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA !!!)
exten => s,n,Goto(macro-auto-blkvm,s,1)

Next, I gave the command

core reload

To my regret, my macro did not start running. Only the macro-auto-blkvm macro is executed.

What am I doing wrong?

This trips all of us up when we first start delving into freepbx customizations. There’s a thread here from 15 years ago with me posing the same question. The custom includes are a legacy of some early design features that has lingered, but in essence they are pretty much completely unusable. There might be one or two of the hundreds of custom includes that can be used, but my advice is to forget they exist.

I’ve enumerated above the supported ways to add your own dialplan, but what you’re asking is how to change freepbx generated dialplan. The way to do this is to copy the context you want to change from extensions_additional.conf into extensions_override_freepbx.conf. Then you’re free to make whatever edits you want, and the updated context you create in this file will supercede the one in ext additional when the dialplan reload happens.

Generally using the override is strongly discouraged, as you have no certainty that future changes to FreePBX generated dialplan will be compatible with your overrides. In practice things generally work, but you’ll probably have to revisit these changes after major upgrades.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.