This page is a companion to the AstriCon 2021 presentation by Lorne Gaetz (Youtube link here). In places in the video, there are references to dialplan which are shared below.
MySQL Lookup Source Example
The goal of this example is to illustrate how to set up a Dynamic Route showing how to use the MySQL lookup source. The MySQL query is a weak attempt to determine from the CDR the most recent extension to which the inbound CID has spoken. For production, this should be considered a starting point for developing something more useful, perhaps follow up in the FreePBX Community forum for ideas.
Asterisk Variable Example
The idea behind this example is to create a sort of Call Flow Control that allows a call to be branched to one of many destinations based on whatever has been set, and not limited to just the 2 allowed by the Call Flow Control Module. We create one dynroute to collect DTMF from a caller and store it permanently to the Asterisk database. We create a second independent dynroute that reads the previously stored value and branches the call based on that result. Updating the value is just a matter of dialing into the first dynroute whenever needed and setting a new value via DTMF.
First Dynamic Route
Create a dynroute that prompts caller for DTMF. In this case, we accept single digit values between 1-4. To store the value, the Source type is set to "Asterisk Variable", saved input is set to 'dyncfc' and the expression used is:
Second Dynamic Route
This is the dynroute used to route the inbound caller. No caller input is required, just set source type to Asterisk Variable with the following expression
Then create Dynamic Route Entries for each of the valid values, in this case single digits between 1 and 4:
Caller Survey Example
In this example we show how to set up an automated caller survey where we prompt a caller for input to a few questions, and then send the responses to an API. It illustrates a scenario where you chain several dynroutes together one after another, and how you reference values collected in one dyroute in a later dynroute
Q1 Dynamic Route
In this dynroute we Enable DTMF Input an play a system recording to a caller. We accept a single DTMF digit and store the value in Input Variable name, q1. There is no branching, caller is sent to Q2 as the default destination
Q2 Dynamic Route
Nearly identical to Q1, except we play a different system recording and save DTMF input to variable named q2. Caller is sent to the Post Survey dynroute.
Post Survey Dynamic Route
We create a third dynroute with no caller input. Source Type is set to URL, enable substitutions is set and we use a URL from https://postb.in for testing. We add GET args to the URL where we reference the previously collected DTMF values from the caller by using the variable name in square brackets.
Not included in the video, but if you don't have an API to post caller data, you could send it from the pbx as an email instead. You would set Source Type to Asterisk Variable, Disable Substitutions and use the following asterisk variable expression with the appropriate places edited for your use case:
AGI File Example
In this example we show how to use the AGI option in Dynamic Routes. We have an agi file on the system located in /var/lib/asterisk/agi-bin named dynroutes-test.agi. The script is owned by asterisk:asterisk, it's executable and it's created with unix EOL characters. File contents are:
The file sets an asterisk channel variable called "agi-random", so we create a dynroute with the path and file name to the agi and the variable in question:
The agi-random var can have a value between 1 and 4 so we set a destination for each: