Greetings all.
So nobody has to ask for the code and instructions -
Any feedback or addons or contributions would be welcome
Below is the information on how to implement the "Talking Clock" code
in the 3CX Phone System.
Also see the extra bit at the bottom of this about dial different numbers to get different
messages.
STEP 1-
In the 3CX Phone System web interface, login and goto > Digital Receptionist > Add
Put in the Virtual Extension number you want to use for the talking clock in this field. eg 555
Put the Name in this field. eg Talking Clock
In the Prompt field select the "Browse" button and goto
eg "C:\Program Files\3CX PhoneSystem\Data\Ivr\Prompts\beep.wav"
(Any prompt in your 3CX Phone System will do. The Talking Clock does not actually use this prompt, however the
3CX Phone System web page will complain if the prompt field is left empty).
Then go to the bottom of the page and click the "OK" button
STEP 2 -
Open Notepad in windows and copy the code below (Including START OF SCRIPT and END OF SCRIPT lines) into notepad.
Save the file as "TalkingClock.php" into the "3CX PhoneSystem\Data\Ivr\Vxml" folder
eg "C:\Program Files\3CX PhoneSystem\Data\Ivr\Vxml\TalkingClock.php" or wherever it's installed in your system.
// START OF SCRIPT. --------------------------------------------------
<?php
//------------------------------------------------------------------
//
// TALKING CLOCK FOR 3CX Phone System ( BY DS & DB )
//
//------------------------------------------------------------------
// AUDIO OPTIONS. TRUE or FALSE
$DATE_Audio = TRUE; //Read out the Date
$TIME_Audio = TRUE; //Read out the Time
$TIME_FIRST = FALSE; //Read the Time before the Date
$MIDNIGHT_Audio = TRUE; // Say Midnight instead of AM
$BYE_Audio = TRUE; // Say Thankyou Goodbye at the end
//------------------------------------------------------------------
// SET AUDIO OPTIONS TO INITIAL VALUES.
$TODAY_IS_Day_Audio_1 = TRUE;
$Day_Audio_1 = TRUE; $Day_Audio_2 = TRUE;
$Month_Audio_1 = TRUE;
$Year_Audio_1 = TRUE; $Year_Audio_2 = TRUE; $Year_Audio_3 = TRUE; $Year_Audio_4 = TRUE;
$THE_TIME_IS_Audio_1 = TRUE;
$Minute_Audio_1 = TRUE; $Minute_Audio_2 = TRUE;
$Hour_Audio_1 = TRUE;
$AMPM_Audio_1 = TRUE;
//------------------------------------------------------------------
// GET DATE AND TIME FROM SYSTEM CLOCK AND EXTRACT INDIVIDUAL VALUES.
$Now_ALL = date('ymdhiA'); // Get the Date and Time.
$Now_Year = substr($Now_ALL, 0, 2); // Extract the Year value (with leading zero).
$Now_Month = substr($Now_ALL, 2, 2); // Extract the Month value (with leading zero).
$Now_Day = substr($Now_ALL, 4, 2); // Extract and Format the Day value (with leading zero).
$Now_Hour = ltrim(substr($Now_ALL, 6, 2), '0'); // Extract the Hour value in 12hr format (with no leading zero).
$Now_Minute = substr($Now_ALL, 8, 2); // Extract the Minute Value (with leading zero).
$Now_AMPM = substr($Now_ALL, 10, 2); // Extract AM or PM value.
//------------------------------------------------------------------
// PROCESS AND FORMAT THE YEAR VALUE.
$Now_Year_Left = substr($Now_Year, 0, 1);
$Now_Year_Right = substr($Now_Year, 1, 1);
// Check to see if Right Digit of Year is 1 to 9 and specify second audio stream.
if($Now_Year_Right >= 1 && $Now_Year_Right <= 9){$Now_Year_2 = $Now_Year_Right;}
// Check Left Digit of Year and specify first audio stream.
$Now_Year_1 = $Now_Year_Left . "0";
if($Now_Year_Left == 0){$Year_Audio_3 = FALSE;}
// Check to see if Year ends in 0, if so turn off last digit of audio.
if($Now_Year_Right == 0){$Year_Audio_4 = FALSE;}
// Check to see if Year is between 11 and 19.
if($Now_Year >= 11 && $Now_Year <= 19)
{
$Year_Audio_3 = FALSE;
$Year_Audio_4 = TRUE;
$Now_Year_2 = $Now_Year;
}
// Check to see if Year is 00.
if($Now_Year == 00)
{
$Year_Audio_2 = FALSE;
$Year_Audio_3 = FALSE;
}
//------------------------------------------------------------------
// PROCESS AND FORMAT DAY OF THE MONTH.
// Get Left digit of day
$Now_Day_Left = substr($Now_Day, 0, 1);
// Get Right digit of day
$Now_Day_Right = substr($Now_Day, 1, 1);
// Check to see if day needs 1 or 2 audio streams
if($Now_Day >= 21 && $Now_Day <= 29 || $Now_Day == 31){$Now_Day_2 = $Now_Day_Right;}
else{$Day_Audio_1 = FALSE; $Now_Day_2 = ltrim($Now_Day, '0');}
// Check to see if Day starts with 2 or 3
if($Now_Day_Left == 2){$Now_Day_1 = "20"; $Now_Day_2 = $Now_Day_Right;}
if($Now_Day_Left == 3){$Now_Day_1 = "30"; $Now_Day_2 = $Now_Day_Right;}
if($Now_Day == 20 || $Now_Day == 30){$Now_Day_2 = ltrim($Now_Day, '0'); $Day_Audio_1 = FALSE;}
//------------------------------------------------------------------
// PROCESS AND FORMAT MINUTES OF THE HOUR.
$Now_Minute_Left = substr($Now_Minute, 0, 1);
$Now_Minute_Right = substr($Now_Minute, 1, 1);
// Check to see if Right Digit of Minute is 1 to 9 and specify second audio stream.
if($Now_Minute_Right >= 1 && $Now_Minute_Right <= 9){$Now_Minute_2 = $Now_Minute_Right;}
// Check Left Digit of Minute and specify first audio stream.
$Now_Minute_1 = "NUM_" . $Now_Minute_Left . "0";
if($Now_Minute_Left == 0){$Now_Minute_1 = "TM_OU";}
// Check to see if Minute ends in 0, if so turn off last digit of audio.
if($Now_Minute_Right == 0){$Minute_Audio_2 = FALSE;}
// Check to see if Minute is between 11 and 19.
if($Now_Minute >= 11 && $Now_Minute <= 19)
{
$Minute_Audio_1 = FALSE;
$Minute_Audio_2 = TRUE;
$Now_Minute_2 = $Now_Minute;
}
// Check to see if Minute is on the Hour 00.
if($Now_Minute == 00){$Minute_Audio_1 = FALSE;}
//------------------------------------------------------------------
// PROCESS AND FORMAT AMPM TO MIDNIGHT.
// Check to see if it's Midnight.
if($MIDNIGHT_Audio == TRUE && $Now_Minute == 00 && $Now_Hour == 12 && $Now_AMPM == AM)
{
$Minute_Audio_1 = FALSE;
$Now_AMPM = "MIDNIGHT";
}
//------------------------------------------------------------------
// SELECTION OF AUDIO STREAMS FOR DATE AND TIME.
if($DATE_Audio == FALSE)
{
$TODAY_IS_Day_Audio_1 = FALSE;
$Day_Audio_1 = FALSE;
$Day_Audio_2 = FALSE;
$Month_Audio_1 = FALSE;
$Year_Audio_1 = FALSE;
$Year_Audio_2 = FALSE;
$Year_Audio_3 = FALSE;
$Year_Audio_4 = FALSE;
}
if($TIME_Audio == FALSE)
{
$THE_TIME_IS_Audio_1 = FALSE;
$Minute_Audio_1 = FALSE;
$Minute_Audio_2 = FALSE;
$Hour_Audio_1 = FALSE;
$AMPM_Audio_1 = FALSE;
}
//------------------------------------------------------------------
// OUTPUT TIME AUDIO STREAM (FIRST).
if($THE_TIME_IS_Audio_1 && $TIME_FIRST){?>
<audio src="GetPrompt.php?id=TIME_IS" />
<?}
if($Hour_Audio_1 && $TIME_FIRST){?>
<audio src="GetPrompt.php?id=NUM_<? print "$Now_Hour" ?>" />
<?}
if($Minute_Audio_1 && $TIME_FIRST){?>
<audio src="GetPrompt.php?id=<? print "$Now_Minute_1" ?>" />
<?}
if($Minute_Audio_2 && $TIME_FIRST){?>
<audio src="GetPrompt.php?id=NUM_<? print "$Now_Minute_2" ?>" />
<?}
if($AMPM_Audio_1 && $TIME_FIRST){?>
<audio src="GetPrompt.php?id=TM_<? print "$Now_AMPM" ?>" />
<?}
//------------------------------------------------------------------
// OUTPUT DATE AUDIO STREAM.
if($TODAY_IS_Day_Audio_1){?>
<audio src="GetPrompt.php?id=TODAY" />
<audio src="GetPrompt.php?id=IS" />
<?}
if($Day_Audio_1){?>
<audio src="GetPrompt.php?id=NUM_<? print "$Now_Day_1" ?>" />
<?}
if($Day_Audio_2){?>
<audio src="GetPrompt.php?id=NUM_<? print "$Now_Day_2" ?>_O" />
<?}
if($Month_Audio_1){?>
<audio src="GetPrompt.php?id=TM_MON_<? print "$Now_Month" ?>" />
<?}
if($Year_Audio_1){?>
<audio src="GetPrompt.php?id=NUM_2" />
<audio src="GetPrompt.php?id=NUM_THSND" />
<?}
if($Year_Audio_2){?>
<audio src="GetPrompt.php?id=NUM_AND" />
<?}
if($Year_Audio_3){?>
<audio src="GetPrompt.php?id=NUM_<? print "$Now_Year_1" ?>" />
<?}
if($Year_Audio_4){?>
<audio src="GetPrompt.php?id=NUM_<? print "$Now_Year_2" ?>" />
<?}
//------------------------------------------------------------------
// OUTPUT TIME AUDIO STREAM (SECOND).
if($THE_TIME_IS_Audio_1 && $TIME_FIRST == FALSE){?>
<audio src="GetPrompt.php?id=TIME_IS" />
<?} if($Hour_Audio_1 && $TIME_FIRST == FALSE){?>
<audio src="GetPrompt.php?id=NUM_<? print "$Now_Hour" ?>" />
<?} if($Minute_Audio_1 && $TIME_FIRST == FALSE){?>
<audio src="GetPrompt.php?id=<? print "$Now_Minute_1" ?>" />
<?} if($Minute_Audio_2 && $TIME_FIRST == FALSE){?>
<audio src="GetPrompt.php?id=NUM_<? print "$Now_Minute_2" ?>" />
<?} if($AMPM_Audio_1 && $TIME_FIRST == FALSE){?>
<audio src="GetPrompt.php?id=TM_<? print "$Now_AMPM" ?>" />
<?}
//------------------------------------------------------------------
// OUTPUT BYE AUDIO STREAM.
if($BYE_Audio){?>
<audio src="GetPrompt.php?id=BYE" />
<?}?>
// END OF SCRIPT. --------------------------------------------------
STEP 3 -
Locate the file called "ivr_start.php", in the "3CX PhoneSystem\Data\Ivr\Vxml" folder
eg "C:\Program Files\3CX PhoneSystem\Data\Ivr\Vxml\ivr_start.php" or wherever it's installed in your system.
NOTE I would reccomend that you make a backup copy of this file in another folder, somewhere,
in case you make an error following the next steps.
Open the "ivr_start.php" file, which is in the Vxml folder, in windows notepad.
(Right click on the file > Open with > Choose Program > Notepad)
Scroll down to the very bottom of the text of the "ivr_start.php" file in notepad.
Scroll backup slowly until you find the last occurance of </block> in the file.
Just above this </block> insert the following lines -
// TALKING CLOCK --------------------------------------------------
<?}?>
// TALKING CLOCK --------------------------------------------------
Now go to the line above it that says -
<submit next="<?= "CallPhp.php?php_file=" . rawurlencode($menu_file) . "&" . $sessParams ?>" />
Just above this line insert the following lines -
// TALKING CLOCK --------------------------------------------------
<? if($rp_dn == "555"){include("TalkingClock.php");}
else
{?>
// TALKING CLOCK --------------------------------------------------
You may like to add some blank lines between the original code and the added code
just so the new code is easier to see.
So the bottom part of your "ivr_start.php" file, between the vxml tags should
look something like this -
<? echo '<?xml version="1.0"?>'; ?>
<vxml version="2.0" application="root.vxml">
<form id="ivr_start">
<block>
<?
if( $bError ) {
?>
<log><?= htmlspecialchars($sError) ?></log>
<disconnect />
<? } else {
?>
<goto nextitem="voicemenu" />
<? }
?>
</block>
<?
if( !$bError )
{
$reqParams->SetParam("caller", $rp_caller);
$reqParams->SetParam("ext_num", $rp_dn);
$reqParams->RemoveParam("ivm_redirect");
$sessParams = htmlspecialchars($reqParams->GetUriStr());
if( $bSpecialFuncMenu )
{
?>
<block name="voicemenu">
<submit next="<?= rawurlencode($menu_file) . "?" . $sessParams ?>" />
</block>
<? }
else
{
switch( $type )
{
case oDN::TYPE_IVR:
?>
<block name="voicemenu">
// TALKING CLOCK --------------------------------------------------
<? if($rp_dn == "555"){include("TalkingClock.php");}
else
{?>
// TALKING CLOCK --------------------------------------------------
<submit next="<?= "CallPhp.php?php_file=" . rawurlencode($menu_file) . "&" . $sessParams ?>" />
// TALKING CLOCK --------------------------------------------------
<?}?>
// TALKING CLOCK --------------------------------------------------
</block>
<? break;
case oDN::TYPE_SPECIALMENU:
session_start();
$session_id = session_id();
RegFileForAction('module:EnterMailbox.php', 'execute');
?>
<subdialog name="voicemenu" src="LoginMailbox.vxml" >
<param name="caller" expr="'<?= $rp_caller ?>'" />
<param name="extension" expr="''" />
<param name="max_attempts" expr="3" />
<param name="ext_len" expr="<?= EXT_LEN ?>" />
<param name="session_id" expr="'<?= $session_id ?>'" />
<filled>
<prompt bargein="false" timeout="1ms">
<audio src="GetPrompt.php?id=BYE" />
</prompt>
<disconnect />
</filled>
</subdialog>
<? break;
default:
?>
<subdialog name="voicemenu" src="RecordVoicemail.php?<?= $sessParams ?>" >
<filled>
<disconnect />
</filled>
</subdialog>
<? }
}
}
?>
<catch event="error.stack_overflow">
<prompt bargein="false" timeout="1ms">
<audio src="GetPrompt.php?id=STACK_OVRFLW" />
</prompt>
</catch>
</form>
</vxml>
The next thing to do is to substatute the "555" in the above code that has been added, for
whatever the number is that you setup to be the Virtual Extension number in the Digital Receptionist.
Now save the file to it's original location.
eg "C:\Program Files\3CX PhoneSystem\Data\Ivr\Vxml\ivr_start.php"
That's it.
Now from a phone connected to your 3CX Phone System, dial the number you chose for the Virtual
Extension number. eg 555
You should now be listing to the 3CX lady telling you the date and time.
To change the options of reading the date and time etc
open the "TalkingClock.php" file, in the vxml folder, with windows notepad
and change the following settings to be either TRUE or FALSE (make sure they are in capitals)
They are near the top in the file and the defaults are -
$DATE_Audio = TRUE; //Read out the Date
When FALSE you won't hear the DATE being read out.
$TIME_Audio = TRUE; //Read out the Time
When FALSE you won't hear the TIME being read out.
$TIME_FIRST = FALSE; //Read the Time before the Date
When TRUE you will hear the TIME being read out before the DATE.
$MIDNIGHT_Audio = TRUE; // Say Midnight instead of AM
When FALSE you will hear the TIME being read out at midnight as "twelve AM".
$BYE_Audio = TRUE; // Say Thankyou Goodbye at the end
When FALSE you will not hear the 3CX lady say "Thankyou Goodbye" at the end.
Also the following is a extra bit of code for the "ivr_start.php" and "TalkingClock.php"
files which will enable you to set up different Digital Receptionists with different
Virtual Extension numbers. So that if you dial eg 555 you get the DATE and TIME, if
you dial eg 556 you get the TIME only and if you dial eg 557 you get the DATE only.
To use this feature you setup three Instances of Digital Receptionist as per STEP 1
each with a different number of your choosing, for each of the options.
Edit the "ivr_start.php" file as before and add the following lines of code where you
added the second lot of TalkingClock code before -
if($rp_dn == "556"){include("TalkingClock.php");}
else
if($rp_dn == "557"){include("TalkingClock.php");}
else
so it should look like this
// TALKING CLOCK --------------------------------------------------
<? if($rp_dn == "555"){include("TalkingClock.php");}
else
if($rp_dn == "556"){include("TalkingClock.php");}
else
if($rp_dn == "557"){include("TalkingClock.php");}
else
{?>
// TALKING CLOCK --------------------------------------------------
Except of course you substatute the "555", "556" and "557" for whatever
Virtual Extension numbers you are using.
Then save and close the "ivr_start.php" file.
Open the "TalkingClock.php" file in windows notepad and add the following
code near the top of the file,-
//------------------------------------------------------------------
// SET AUDIO OPTIONS DEPENDING ON DIALED NUMBER.
if($rp_dn == "556"){$DATE_Audio = FALSE;}
if($rp_dn == "557"){$TIME_Audio = FALSE;}
Insert the above code on the line above the line that says the following
//------------------------------------------------------------------
// GET DATE AND TIME FROM SYSTEM CLOCK AND EXTRACT INDIVIDUAL VALUES.
and below the line, in the "// SET AUDIO OPTIONS TO INITIAL VALUES." section that says -
$AMPM_Audio_1 = TRUE;
so that part of "TalkingClock.php" should look like the following -
//------------------------------------------------------------------
// SET AUDIO OPTIONS TO INITIAL VALUES.
$TODAY_IS_Day_Audio_1 = TRUE;
$Day_Audio_1 = TRUE; $Day_Audio_2 = TRUE;
$Month_Audio_1 = TRUE;
$Year_Audio_1 = TRUE; $Year_Audio_2 = TRUE; $Year_Audio_3 = TRUE; $Year_Audio_4 = TRUE;
$THE_TIME_IS_Audio_1 = TRUE;
$Minute_Audio_1 = TRUE; $Minute_Audio_2 = TRUE;
$Hour_Audio_1 = TRUE;
$AMPM_Audio_1 = TRUE;
//------------------------------------------------------------------
// SET AUDIO OPTIONS DEPENDING ON DIALED NUMBER.
if($rp_dn == "556"){$DATE_Audio = FALSE;}
if($rp_dn == "557"){$TIME_Audio = FALSE;}
//------------------------------------------------------------------
// GET DATE AND TIME FROM SYSTEM CLOCK AND EXTRACT INDIVIDUAL VALUES.
Now change the values in the above code you have just pasted in the "TalkingClock.php"
file "556" to the number for your TIME only DR and "557" to the number for your DATE
only DR.
Save and close the file.
If all goes to plan, you sould now be able to dial the different numbers and get
different responses as desired.
I should point out that this has only been tested with the 3CX Phone System v3.1.2434.0
Regards
Daves
New Zealand