net.sf.asterisk.fastagi
Class BaseAGIScript

java.lang.Object
  extended by net.sf.asterisk.fastagi.BaseAGIScript
All Implemented Interfaces:
AGIScript

public abstract class BaseAGIScript
extends java.lang.Object
implements AGIScript

The BaseAGIScript provides some convinience methods to make it easier to write custom AGIScripts.
Just extend it by your own AGIScripts.

Since:
0.2
Version:
$Id: BaseAGIScript.java,v 1.7 2005/11/27 17:31:05 srt Exp $
Author:
srt

Constructor Summary
BaseAGIScript()
           
 
Method Summary
protected  void answer()
          Answers the channel.
protected  int exec(java.lang.String application)
          Executes the given command.
protected  int exec(java.lang.String application, java.lang.String options)
          Executes the given command.
protected  int getChannelStatus()
          Returns the status of the channel.
Return values: 0 Channel is down and available 1 Channel is down, but reserved 2 Channel is off hook 3 Digits (or equivalent) have been dialed 4 Line is ringing 5 Remote end is ringing 6 Line is up 7 Line is busy
protected  java.lang.String getData(java.lang.String file)
          Plays the given file and waits for the user to enter DTMF digits until he presses '#'.
protected  java.lang.String getData(java.lang.String file, int timeout)
          Plays the given file and waits for the user to enter DTMF digits until he presses '#' or the timeout occurs.
protected  java.lang.String getData(java.lang.String file, int timeout, int maxDigits)
          Plays the given file and waits for the user to enter DTMF digits until he presses '#' or the timeout occurs or the maximum number of digits has been entered.
protected  java.lang.String getFullVariable(java.lang.String name)
          Returns the value of the current channel variable, unlike getVariable() this method understands complex variable names and builtin variables.
Available since Asterisk 1.2.
protected  java.lang.String getFullVariable(java.lang.String name, java.lang.String channel)
          Returns the value of the given channel variable.
Available since Asterisk 1.2.
protected  char getOption(java.lang.String file, java.lang.String escapeDigits)
          Plays the given file, and waits for the user to press one of the given digits.
protected  char getOption(java.lang.String file, java.lang.String escapeDigits, int timeout)
          Plays the given file, and waits for the user to press one of the given digits.
protected  java.lang.String getVariable(java.lang.String name)
          Returns the value of the given channel variable.
protected  void hangup()
          Hangs the channel up.
protected  void playMusicOnHold()
          Plays music on hold from the default music on hold class.
protected  void playMusicOnHold(java.lang.String musicOnHoldClass)
          Plays music on hold from the given music on hold class.
protected  void sayAlpha(java.lang.String text)
          Says the given character string.
protected  char sayAlpha(java.lang.String text, java.lang.String escapeDigits)
          Says the given character string, returning early if any of the given DTMF number are received on the channel.
protected  void sayDateTime(long time)
          Says the given time.
Available since Asterisk 1.2.
protected  char sayDateTime(long time, java.lang.String escapeDigits)
          Says the given time and allows interruption by one of the given escape digits.
Available since Asterisk 1.2.
protected  char sayDateTime(long time, java.lang.String escapeDigits, java.lang.String format)
          Says the given time in the given format and allows interruption by one of the given escape digits.
Available since Asterisk 1.2.
protected  char sayDateTime(long time, java.lang.String escapeDigits, java.lang.String format, java.lang.String timezone)
          Says the given time in the given format and timezone and allows interruption by one of the given escape digits.
Available since Asterisk 1.2.
protected  void sayDigits(java.lang.String digits)
          Says the given digit string.
protected  char sayDigits(java.lang.String digits, java.lang.String escapeDigits)
          Says the given number, returning early if any of the given DTMF number are received on the channel.
protected  void sayNumber(java.lang.String number)
          Says the given number.
protected  char sayNumber(java.lang.String number, java.lang.String escapeDigits)
          Says the given number, returning early if any of the given DTMF number are received on the channel.
protected  void sayPhonetic(java.lang.String text)
          Says the given character string with phonetics.
protected  char sayPhonetic(java.lang.String text, java.lang.String escapeDigits)
          Says the given character string with phonetics, returning early if any of the given DTMF number are received on the channel.
protected  void sayTime(long time)
          Says the given time.
protected  char sayTime(long time, java.lang.String escapeDigits)
          Says the given time, returning early if any of the given DTMF number are received on the channel.
protected  void setAutoHangup(int time)
          Cause the channel to automatically hangup at the given number of seconds in the future.
protected  void setCallerId(java.lang.String callerId)
          Sets the caller id on the current channel.
protected  void setContext(java.lang.String context)
          Sets the context for continuation upon exiting the application.
protected  void setExtension(java.lang.String extension)
          Sets the extension for continuation upon exiting the application.
protected  void setPriority(java.lang.String priority)
          Sets the priority or label for continuation upon exiting the application.
protected  void setVariable(java.lang.String name, java.lang.String value)
          Sets the value of the given channel variable to a new value.
protected  void stopMusicOnHold()
          Stops playing music on hold.
protected  void streamFile(java.lang.String file)
          Plays the given file.
protected  char streamFile(java.lang.String file, java.lang.String escapeDigits)
          Plays the given file and allows the user to escape by pressing one of the given digit.
protected  char waitForDigit(int timeout)
          Waits up to 'timeout' milliseconds to receive a DTMF digit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.asterisk.fastagi.AGIScript
service
 

Constructor Detail

BaseAGIScript

public BaseAGIScript()
Method Detail

answer

protected void answer()
               throws AGIException
Answers the channel.

Throws:
AGIException

hangup

protected void hangup()
               throws AGIException
Hangs the channel up.

Throws:
AGIException

setAutoHangup

protected void setAutoHangup(int time)
                      throws AGIException
Cause the channel to automatically hangup at the given number of seconds in the future.

Parameters:
time - the number of seconds before this channel is automatically hung up.
0 disables the autohangup feature.
Throws:
AGIException

setCallerId

protected void setCallerId(java.lang.String callerId)
                    throws AGIException
Sets the caller id on the current channel.

Parameters:
callerId - the raw caller id to set, for example "John Doe<1234>".
Throws:
AGIException

playMusicOnHold

protected void playMusicOnHold()
                        throws AGIException
Plays music on hold from the default music on hold class.

Throws:
AGIException

playMusicOnHold

protected void playMusicOnHold(java.lang.String musicOnHoldClass)
                        throws AGIException
Plays music on hold from the given music on hold class.

Parameters:
musicOnHoldClass - the music on hold class to play music from as configures in Asterisk's .
Throws:
AGIException

stopMusicOnHold

protected void stopMusicOnHold()
                        throws AGIException
Stops playing music on hold.

Throws:
AGIException

getChannelStatus

protected int getChannelStatus()
                        throws AGIException
Returns the status of the channel.
Return values:
  • 0 Channel is down and available
  • 1 Channel is down, but reserved
  • 2 Channel is off hook
  • 3 Digits (or equivalent) have been dialed
  • 4 Line is ringing
  • 5 Remote end is ringing
  • 6 Line is up
  • 7 Line is busy

Returns:
the status of the channel.
Throws:
AGIException

getData

protected java.lang.String getData(java.lang.String file)
                            throws AGIException
Plays the given file and waits for the user to enter DTMF digits until he presses '#'. The user may interrupt the streaming by starting to enter digits.

Parameters:
file - the name of the file to play
Returns:
a String containing the DTMF the user entered
Throws:
AGIException

getData

protected java.lang.String getData(java.lang.String file,
                                   int timeout)
                            throws AGIException
Plays the given file and waits for the user to enter DTMF digits until he presses '#' or the timeout occurs. The user may interrupt the streaming by starting to enter digits.

Parameters:
file - the name of the file to play
timeout - the timeout in milliseconds to wait for user input.
0 means standard timeout value, -1 means "ludicrous time" (essentially never times out).
Returns:
a String containing the DTMF the user entered
Throws:
AGIException

getData

protected java.lang.String getData(java.lang.String file,
                                   int timeout,
                                   int maxDigits)
                            throws AGIException
Plays the given file and waits for the user to enter DTMF digits until he presses '#' or the timeout occurs or the maximum number of digits has been entered. The user may interrupt the streaming by starting to enter digits.

Parameters:
file - the name of the file to play
timeout - the timeout in milliseconds to wait for user input.
0 means standard timeout value, -1 means "ludicrous time" (essentially never times out).
maxDigits - the maximum number of digits the user is allowed to enter
Returns:
a String containing the DTMF the user entered
Throws:
AGIException

getOption

protected char getOption(java.lang.String file,
                         java.lang.String escapeDigits)
                  throws AGIException
Plays the given file, and waits for the user to press one of the given digits. If none of the esacpe digits is pressed while streaming the file it waits for the default timeout of 5 seconds still waiting for the user to press a digit.

Parameters:
file - the name of the file to stream, must not include extension.
escapeDigits - contains the digits that the user is expected to press.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

getOption

protected char getOption(java.lang.String file,
                         java.lang.String escapeDigits,
                         int timeout)
                  throws AGIException
Plays the given file, and waits for the user to press one of the given digits. If none of the esacpe digits is pressed while streaming the file it waits for the specified timeout still waiting for the user to press a digit.

Parameters:
file - the name of the file to stream, must not include extension.
escapeDigits - contains the digits that the user is expected to press.
timeout - the timeout in seconds to wait if none of the defined esacpe digits was presses while streaming.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

exec

protected int exec(java.lang.String application)
            throws AGIException
Executes the given command.

Parameters:
application - the name of the application to execute, for example "Dial".
Returns:
the return code of the application of -2 if the application was not found.
Throws:
AGIException

exec

protected int exec(java.lang.String application,
                   java.lang.String options)
            throws AGIException
Executes the given command.

Parameters:
application - the name of the application to execute, for example "Dial".
options - the parameters to pass to the application, for example "SIP/123".
Returns:
the return code of the application of -2 if the application was not found.
Throws:
AGIException

setContext

protected void setContext(java.lang.String context)
                   throws AGIException
Sets the context for continuation upon exiting the application.

Parameters:
context - the context for continuation upon exiting the application.
Throws:
AGIException

setExtension

protected void setExtension(java.lang.String extension)
                     throws AGIException
Sets the extension for continuation upon exiting the application.

Parameters:
extension - the extension for continuation upon exiting the application.
Throws:
AGIException

setPriority

protected void setPriority(java.lang.String priority)
                    throws AGIException
Sets the priority or label for continuation upon exiting the application.

Parameters:
priority - the priority or label for continuation upon exiting the application.
Throws:
AGIException

streamFile

protected void streamFile(java.lang.String file)
                   throws AGIException
Plays the given file.

Parameters:
file - name of the file to play.
Throws:
AGIException

streamFile

protected char streamFile(java.lang.String file,
                          java.lang.String escapeDigits)
                   throws AGIException
Plays the given file and allows the user to escape by pressing one of the given digit.

Parameters:
file - name of the file to play.
escapeDigits - a String containing the DTMF digits that allow the user to escape.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

sayDigits

protected void sayDigits(java.lang.String digits)
                  throws AGIException
Says the given digit string.

Parameters:
digits - the digit string to say.
Throws:
AGIException

sayDigits

protected char sayDigits(java.lang.String digits,
                         java.lang.String escapeDigits)
                  throws AGIException
Says the given number, returning early if any of the given DTMF number are received on the channel.

Parameters:
digits - the digit string to say.
escapeDigits - a String containing the DTMF digits that allow the user to escape.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

sayNumber

protected void sayNumber(java.lang.String number)
                  throws AGIException
Says the given number.

Parameters:
number - the number to say.
Throws:
AGIException

sayNumber

protected char sayNumber(java.lang.String number,
                         java.lang.String escapeDigits)
                  throws AGIException
Says the given number, returning early if any of the given DTMF number are received on the channel.

Parameters:
number - the number to say.
escapeDigits - a String containing the DTMF digits that allow the user to escape.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

sayPhonetic

protected void sayPhonetic(java.lang.String text)
                    throws AGIException
Says the given character string with phonetics.

Parameters:
text - the text to say.
Throws:
AGIException

sayPhonetic

protected char sayPhonetic(java.lang.String text,
                           java.lang.String escapeDigits)
                    throws AGIException
Says the given character string with phonetics, returning early if any of the given DTMF number are received on the channel.

Parameters:
text - the text to say.
escapeDigits - a String containing the DTMF digits that allow the user to escape.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

sayAlpha

protected void sayAlpha(java.lang.String text)
                 throws AGIException
Says the given character string.

Parameters:
text - the text to say.
Throws:
AGIException

sayAlpha

protected char sayAlpha(java.lang.String text,
                        java.lang.String escapeDigits)
                 throws AGIException
Says the given character string, returning early if any of the given DTMF number are received on the channel.

Parameters:
text - the text to say.
escapeDigits - a String containing the DTMF digits that allow the user to escape.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

sayTime

protected void sayTime(long time)
                throws AGIException
Says the given time.

Parameters:
time - the time to say in seconds since 00:00:00 on January 1, 1970.
Throws:
AGIException

sayTime

protected char sayTime(long time,
                       java.lang.String escapeDigits)
                throws AGIException
Says the given time, returning early if any of the given DTMF number are received on the channel.

Parameters:
time - the time to say in seconds since 00:00:00 on January 1, 1970.
escapeDigits - a String containing the DTMF digits that allow the user to escape.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

getVariable

protected java.lang.String getVariable(java.lang.String name)
                                throws AGIException
Returns the value of the given channel variable.

Parameters:
name - the name of the variable to retrieve.
Returns:
the value of the given variable or null if not set.
Throws:
AGIException

setVariable

protected void setVariable(java.lang.String name,
                           java.lang.String value)
                    throws AGIException
Sets the value of the given channel variable to a new value.

Parameters:
name - the name of the variable to retrieve.
value - the new value to set.
Throws:
AGIException

waitForDigit

protected char waitForDigit(int timeout)
                     throws AGIException
Waits up to 'timeout' milliseconds to receive a DTMF digit.

Parameters:
timeout - timeout the milliseconds to wait for the channel to receive a DTMF digit, -1 will wait forever.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException

getFullVariable

protected java.lang.String getFullVariable(java.lang.String name)
                                    throws AGIException
Returns the value of the current channel variable, unlike getVariable() this method understands complex variable names and builtin variables.
Available since Asterisk 1.2.

Parameters:
name - the name of the variable to retrieve.
Returns:
the value of the given variable or null if not set.
Throws:
AGIException
Since:
0.2

getFullVariable

protected java.lang.String getFullVariable(java.lang.String name,
                                           java.lang.String channel)
                                    throws AGIException
Returns the value of the given channel variable.
Available since Asterisk 1.2.

Parameters:
name - the name of the variable to retrieve.
channel - the name of the channel.
Returns:
the value of the given variable or null if not set.
Throws:
AGIException
Since:
0.2

sayDateTime

protected void sayDateTime(long time)
                    throws AGIException
Says the given time.
Available since Asterisk 1.2.

Parameters:
time - the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)
Throws:
AGIException
Since:
0.2

sayDateTime

protected char sayDateTime(long time,
                           java.lang.String escapeDigits)
                    throws AGIException
Says the given time and allows interruption by one of the given escape digits.
Available since Asterisk 1.2.

Parameters:
time - the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)
escapeDigits - the digits that allow the user to interrupt this command or null for none.
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException
Since:
0.2

sayDateTime

protected char sayDateTime(long time,
                           java.lang.String escapeDigits,
                           java.lang.String format)
                    throws AGIException
Says the given time in the given format and allows interruption by one of the given escape digits.
Available since Asterisk 1.2.

Parameters:
time - the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)
escapeDigits - the digits that allow the user to interrupt this command or null for none.
format - the format the time should be said in
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException
Since:
0.2

sayDateTime

protected char sayDateTime(long time,
                           java.lang.String escapeDigits,
                           java.lang.String format,
                           java.lang.String timezone)
                    throws AGIException
Says the given time in the given format and timezone and allows interruption by one of the given escape digits.
Available since Asterisk 1.2.

Parameters:
time - the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)
escapeDigits - the digits that allow the user to interrupt this command or null for none.
format - the format the time should be said in
timezone - the timezone to use when saying the time, for example "UTC" or "Europe/Berlin".
Returns:
the DTMF digit pressed or 0x0 if none was pressed.
Throws:
AGIException
Since:
0.2


Copyright © 2004-2005 Stefan Reuter. All Rights Reserved.