Custom forwarding for destination

Hi, I just got a freepbx box after having used a custom server that I installed asterisk on. I’ve been trying to copy over the functionality of the old asterisk server using the freepbx style (And I have to say I really like the style of freepbx).
I have a more complex dialplan but essentially, to get things going, I have an incoming route currently going to an announcement that goes to a ring group (or Misc Destination that goes to an extensions_custom.conf extention)

In my old system, I had an incoming context that would dial global variable like:

exten => s,1(calloffice),Dial(${GLOBAL(CALLOFFICE)},30,trm(bluebird)d);
exten => s,n,VoiceMail([email protected],us);
exten => s,n,Playback(vm-goodbye);
exten => s,n,Wait(2);
exten => s,n,Hangup();

Then I had extensions that would change the CALLOFFICE variable like:

exten => 402,n,PlayBack(bluebird/admin/number-has-been-forwarded-2pamcell);
exten => 402,n,PlayBack(goodbye);
exten => 402,n,Hangup();

By the way, in the old asterisk system I had the variables in [globals] like


Where I think the new way for cellphones (I’m not sure if this is correct and perhaps it’s better to set up virtual extensions) would be:

PAMCELL=Local/[email protected]

But in the logfiles when I try dialing 402 for example, it says

Set(“IAX2/106-7397”, “GLOBAL(CALLOFFICE)=”)

I assume it’s because there’s already a globals context, so my variables aren’t properly being seen. So my first question is if there’s a better way to get those variables into a globals context.

But more importantly, is there a better implementation of this sort of custom destination? I thought about Call Flow Control, but it seems I’d have to nest them to get multiple destinations to work correctly. Would that be correct? Is there another better way?
Thank you.

How are you defining your globals? There is a custom file for this purpose, /etc/asterisk/globals_custom.conf and after a core reload you can ensure they are set properly with dialplan show globals.

Using globals will work, but one often sees this type of thing done with Asterisk database entries, i.e:

Set(DB(OFFICE/PAMCELL)=Local/[email protected])

The database entries will survive an Asterisk restart.

If it was me, I would stick to FreePBX created contexts for your dial strings, from-internal, outbound-allroutes, etc so that future changes to your trunks don’t break things.

And finally, the majority of this can be done with the GUI using the third party module, Dynroutes which allows you to direct a call to a group of multiple destinations based on the value of an Asterisk variable.

Thanks for the tip on the globals_custom.conf! I was just putting another [globals] context in the extensions_custom.conf. But I like the idea of the DB even more. If I’m using the Set() command to set the variables into the DB, is there a way to run the command on start? Or do I just need to temporarily make an extension that will set those variables and they’ll stay in the database servers indefinitely? And is there a FreePBX database module where I can see and add to DB variables?

When you say sticking to FreePBX created contexts like outbound-allroutes, are you referring to the Outbound-US? And I don’t quite understand the “Local” keyword If I’m dialing

Local/[email protected]

What is Local? And I wrote Outbound-US as the name of one of the Outbound Routes. I guess I should just write

Local/[email protected]

Are all outbound routes by default in the from-internal context? Or are they in outbound-allroutes?
Or maybe the outbound routes are in outbound-allroutes which is included in from-internal, so both would work?
(and as a side question, is there any way to create custom outbound routes only accessible in custom contexts?)

Finally, in regards to the Dynroutes, thanks for the link! I can see how that would work although it looks like I’d have to set up a mysql connection in the route with my own database/table, but then i could easily update the the destinations of each number in the gui. Is that correct? You said based on the value of an Asterisk variable, but I only see using a database as an option. For something this simple, it would be nice to just use an asterisk variable. But if I do use a database as an option, how would I update that database through the dialplan? As I understand it, the DB edits the AstDB and not a MySQL database.

P.S. - I also had a thought about how if I’m using the extension like:

exten => s,1(calloffice),Dial(${DB(OFFICE/CALLOFFICE)},30,trm(bluebird)d);
exten => s,n,VoiceMail([email protected],us);
exten => s,n,Playback(vm-goodbye);
exten => s,n,Wait(2);
exten => s,n,Hangup();

Then it’s not going to follow other rules. Is there a way to set the DB variable to something that would go to another extension/ring group that would have it’s own rules set in the GUI in terms of time until voicemail, followme, and other rules? If I got rid of everything after Dial and just did

exten => 100,1,Dial(PJSIP/101)

Would it follow rules of the 101 extension in terms of background music, time to voicemail, followme, etc? How would I do that? And How could I dial a ring group (600 for example) instead of dialing PJSIP/101&PJSIP/102?
Thank you again.

Asterisk database entries will persist between restarts, so you only set once. You can use the Asterisk CLI to set initially or you can manually create dialplan to initialize them. If you look through the file /etc/asterisk/extensions_additional.conf and search for "DB" you will find many examples of reading and setting db entries.

It’s exactly what you would think it is, local is a channel meaning dialplan local to the PBX.

Very broadly, there are two primary contexts within FreePBX, from-internal is the context where all your trusted internal extensions are (or more correctly are included), and from-trunk (and its many aliases) is the context in which external calls arrive at your PBX. Generally you would use one of these depending on the direction the call is going. There are a handful of other useful contexts, outbound-allroutes being one.

Yes, the latter.

Keep looking, if you are on the latest version, there are multiple source types available in addition to MySQL.

As you guessed, if you use this in the dialplan:

exten => 100,1,Dial(PJSIP/101)

It will just ring device 100 with default settings and nothing else. If you instead use one of these:

exten => s,n,Dial(local/[email protected])
exten => s,n,Goto(from-internal,101,1)

It will use all of the settings you have configured in the GUI (follow-me, CF, DND, voicemail, etc)

And finally, for seamlessly bouncing between GUI and dialplan, you need to understand the Custom Destination module fully. Suppose you have this in extensions_custom.conf:

exten => s,1,Noop(This line will appear in the asterisk log)
exten => s,n,Return()

Then create a Custom Destination to custom-log-entry,s,1 and enable the ‘Return’ option and select the destination you want after the dialplan executes. You then use this Custom Destination in the GUI.