From 26779e0c0dc44465e3c79345db4286a1be292401 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Thu, 27 Jun 2024 23:34:44 -0600 Subject: [PATCH] Add chimes --- README.md | 3 +++ chimes/README.md | 17 +++++++++++++++++ chimes/chimes.sh | 27 +++++++++++++++++++++++++++ chimes/custom-context.conf | 8 ++++++++ 4 files changed, 55 insertions(+) create mode 100644 chimes/README.md create mode 100644 chimes/chimes.sh create mode 100644 chimes/custom-context.conf diff --git a/README.md b/README.md index 1961d76..289b82d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # fpbx-stuff +## A big ol' collection of FreePBX scripts and configurations I've made or found useful. +### [chimes](chimes) +This is a simple setup to make your phone system page a page group and play a chime at noon in any number of timezones. \ No newline at end of file diff --git a/chimes/README.md b/chimes/README.md new file mode 100644 index 0000000..c7650a8 --- /dev/null +++ b/chimes/README.md @@ -0,0 +1,17 @@ +# Noon Chimes + +This is a simple setup to make your phone system page a page group and play a chime at noon in any number of timezones. + +## Installation +1. Choose a chime sound and upload it to FreePBX through Admin > System Recordings. +2. Set up a custom context in Admin > Config Edit. Paste the contents of `custom-context.conf` into the file, save, and apply the config. +3. Set up a Custom Dest in Admin > Custom Destinations. Set the target to `chimes,s,1` and give it any description. +4. Set up the script `chimes.sh` in `/root/chimes.sh` and make it executable with `chmod +x /root/chimes.sh`. +5. Set up crontab with the following line: `0 * * * * /root/chimes.sh`. + +## Configuration +There really isn't any, other than modifying the shell script to set what timezones you want to make chime at noon. +If you want to trigger the chime at a specific time, use cron to run `/var/lib/asterisk/bin/callback "page-group-number-here" chimes.s.1 0 0 "Ik5vb24gQ2hpbWUiIDw+"` at the desired time. I think you should be able to look up how to set up a cron job for that. + +If you want to change the Caller ID it uses, base64 encode the callerid string you want to use and replace that at the end of the callback command. +A valid caller id looks like `"NAME" `, or just `"NAME"` or ``. The base64 encoded string for `"Noon Chime" <1234>` is `Ik5vb24gQ2hpbWUgPDEyMzQ+`. \ No newline at end of file diff --git a/chimes/chimes.sh b/chimes/chimes.sh new file mode 100644 index 0000000..b364e8c --- /dev/null +++ b/chimes/chimes.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Define time zone names +declare -A time_zone_names + +# Time Zone page group array +time_zone_names=( ["1234"]="America/New_York" ["5678"]="America/Denver" ) + +# Function to check if it's noon in a specific time zone and trigger the callback command +check_noon() { + number="$1" # Get the time zone number + time_zone="${time_zone_names["$number"]}" # Get the corresponding time zone name + TZ="$time_zone" # Set the time zone + current_time=$(TZ="$time_zone" date +'%H') # Get the current hour in the specified time zone + + if [ "$current_time" -eq 12 ]; then + echo "It's noon in $time_zone" + /var/lib/asterisk/bin/callback "$number" chimes.s.1 0 0 "Ik5vb24gQ2hpbWUiIDw+" + else + echo "It's not noon in $time_zone" + fi +} + +# Loop through the time zone numbers and check if it's noon +for number in "${!time_zone_names[@]}"; do + check_noon "$number" +done \ No newline at end of file diff --git a/chimes/custom-context.conf b/chimes/custom-context.conf new file mode 100644 index 0000000..1374a67 --- /dev/null +++ b/chimes/custom-context.conf @@ -0,0 +1,8 @@ +[chimes] +exten => s,1,Wait(1) +exten => s,n,Playback(custom/my-chime-file) +; exten => s,n,SayUnixTime(STRFTIME(),,IMp) +; exten => s,n,Playback(digits/12) +; exten => s,n,Playback(digits/oclock) +; exten => s,n,Playback(digits/p-m) +exten => s,n,Hangup() \ No newline at end of file