text stringlengths 0 152 |
|---|
global variable. |
Time-Based Conditional Branching with GotoIfTime() |
Another way to use conditional branching in your dialplan is with the GotoIfTime() |
application. Whereas GotoIf() evaluates an expression to decide what to do, GotoIf |
Time() looks at the current system time and uses that to decide whether or not to fol‐ |
low a different branch in the dialplan. |
The most obvious use of this application is to give your callers a different greeting |
before and after normal business hours. |
The syntax for the GotoIfTime() application looks like this: |
GotoIfTime(times,days_of_week,days_of_month,months?label) |
4 If you want to test this (which you do), you can pick one of your working lab devices, and in the asterisk |
database, under the ps_endpoints table, set the callerid field to '8885551212'. Then you can make a call |
from it to 214 to see the block in action. |
UPDATE asterisk.ps_endpoints SET callerid='8885551212' WHERE id='<endpoint you chose as the |
victim>' |
5 But we do it this way because it’s easier to read. |
172 |
| |
Chapter 10: Deeper into the Dialplan |
In short, GotoIfTime() sends the call to the specified label if the current date and |
time match the criteria specified by times, days_of_week, days_of_month, and |
months. Let’s look at each argument in more detail: |
times |
This is a list of one or more time ranges, in a 24-hour format. As an example, |
9:00 A.M. through 5:00 P.M. would be specified as 09:00-17:00. The day starts at |
0:00 and ends at 23:59. |
It is worth noting that times will properly wrap around. So, if |
you wish to specify the times your office is closed, you might |
write 18:00-9:00 in the times parameter, and it will perform |
as expected. Note that this technique works as well for the |
other components of GotoIfTime(). For example, you can |
write sat-sun to specify the weekend days. |
days_of_week |
This is a list of one or more days of the week. The days should be specified as mon, |
tue, wed, thu, fri, sat, and/or sun. Monday through Friday would be expressed |
as mon-fri. Tuesday and Thursday would be expressed as tue&thu. |
Note that you can specify a combination of ranges and single |
days, as in: sun-mon&wed&fri-sat, or, more simply: wed&fri- |
mon. |
days_of_month |
This is a list of the numerical days of the month. Days are specified by the num‐ |
bers 1 through 31. The 7th through the 12th would be expressed as 7-12, and the |
15th and 30th of the month would be written as 15&30. This can be useful for |
holidays, which often fall on the same day of the month, but not typically on the |
same day of the week.6 |
months |
This is a list of one or more months of the year. The months should be written as |
jan-apr for a range, and separated with ampersands when wanting to include |
nonsequential months, such as jan&mar&jun. You can also combine them like so: |
jan-apr&jun&oct-dec. |
6 We have no idea how to implement Easter, but are open to suggestions. |
Conditional Branching |
| |
173 |
If you wish to match on all possible values for any of these arguments, simply put an |
* in for that argument. |
The label argument can be any of the following: |
• A priority label within the same extension, such as time_has_passed |
• An extension and a priority within |
the |
same context, |
such as |
123,time_has_passed |
• A context, extension, and priority, such as incoming,123,time_has_passed |
Now that we’ve covered the syntax, let’s look at a couple of examples. The following |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.