FON Script Interface

Table of contents
  1. 1. Fon Script Interface Overview
  2. 2. Example Application
  3. 3. Prerequisite
  4. 4. How To Configure Run Script
  5. 5. Calling Your Script
  6. 6. Example Script
  7. 7. Compatibility
  8. 8. Languages
  9. 9. Programming Tips
  10. 10. Environment Variables
  11. 11. FON Interface API Reference
    1. 11.1. ANSWER
    2. 11.2. AUTOHANGUP <time>
    3. 11.3. CHANNEL STATUS [<channelname>]
    4. 11.4. EXEC <application> <options>
      1. 11.4.1. AbsoluteTimeout: Set absolute maximum time of call
      2. 11.4.2. AddQueueMember: Dynamically adds queue members
      3. 11.4.3. ADSIProg: Load Asterisk ADSI Scripts into phone
      4. 11.4.4. AGI: Executes an AGI compliant application
      5. 11.4.5. AlarmReceiver: Provide support for receving alarm reports from a burglar or fire alarm panel
      6. 11.4.6. Answer: Answer a channel if ringing
      7. 11.4.7. AppendCDRUserField: Append to the CDR user field
      8. 11.4.8. Authenticate: Authenticate a user
      9. 11.4.9. BackGround: Play a file while awaiting extension
      10. 11.4.10. BackgroundDetect: Background a file with talk detect
      11. 11.4.11. Busy: Indicate the Busy condition
      12. 11.4.12. ChangeMonitor: Change monitoring filename of a channel
      13. 11.4.13. ChanInUse: Checks to see if channel is in use
      14. 11.4.14. ChanIsAvail: Check channel availability
      15. 11.4.15. ChanSpy: Listen to the audio of an active channel
      16. 11.4.16. CheckGroup: Check the channel count of a group against a limit
      17. 11.4.17. Congestion: Indicate the Congestion condition
      18. 11.4.18. ControlPlayback: Play a file with fast forward and rewind
      19. 11.4.19. Curl: Load an external URL
      20. 11.4.20. Cut: Splits a variable's contents using the specified delimiter
      21. 11.4.21. DateTime: Says a specified time in a custom format
      22. 11.4.22. DBdel: Delete a key from the database
      23. 11.4.23. DBdeltree: Delete a family or keytree from the database
      24. 11.4.24. DBget: Retrieve a value from the database
      25. 11.4.25. DBput: Store a value in the database
      26. 11.4.26. DeadAGI: Executes AGI on a hungup channel
      27. 11.4.27. Dial: Place a call and connect to the current channel
      28. 11.4.28. Dictate: Virtual Dictation Machine
      29. 11.4.29. DigitTimeout: Set maximum timeout between digits
      30. 11.4.30. Directory: Provide directory of voicemail extensions
      31. 11.4.31. DISA: DISA (Direct Inward System Access)
      32. 11.4.32. DumpChan: Dump Info About The Calling Channel
      33. 11.4.33. DUNDiLookup: Look up a number with DUNDi
      34. 11.4.34. EAGI: Executes an EAGI compliant application
      35. 11.4.35. Echo: Echo audio read back to the user
      36. 11.4.36. EndWhile: End A While Loop
      37. 11.4.37. EnumLookup: Lookup number in ENUM
      38. 11.4.38. Eval: Evaluates a string
      39. 11.4.39. Exec: Executes internal application
      40. 11.4.40. ExecIf: Conditional exec
      41. 11.4.41. ExecIfTime: Conditional application execution based on the current time
      42. 11.4.42. ExternalIVR: Interfaces with an external IVR application
      43. 11.4.43. Festival: Say text to the user
      44. 11.4.44. Flash: Flashes a Zap Trunk
      45. 11.4.45. FlushQueueStats: Flushes stats for specified queue
      46. 11.4.46. ForkCDR: Forks the Call Data Record
      47. 11.4.47. GetCPEID: Get ADSI CPE ID
      48. 11.4.48. GetGroupCount: Get the channel count of a group
      49. 11.4.49. GetGroupMatchCount: Get the channel count of all groups that match a pattern
      50. 11.4.50. Gosub: Jump to label, saving return address
      51. 11.4.51. GosubIf: Jump to label, saving return address
      52. 11.4.52. Goto: Jump to a particular priority, extension, or context
      53. 11.4.53. GotoIf: Conditional goto
      54. 11.4.54. GotoIfTime: Conditional Goto based on the current time
      55. 11.4.55. Hangup: Hang up the calling channel
      56. 11.4.56. HasNewVoicemail: Conditionally branches to priority + 101 with the right options set
      57. 11.4.57. HasVoicemail: Conditionally branches to priority + 101 with the right options set
      58. 11.4.58. IAX2Provision: Provision a calling IAXy with a given template
      59. 11.4.59. ICES: Encode and stream using 'ices'
      60. 11.4.60. ImportVar: Import a variable from a channel into a new variable
      61. 11.4.61. LookupBlacklist: Look up Caller*ID name/number from blacklist database
      62. 11.4.62. LookupCIDName: Look up CallerID Name from local database
      63. 11.4.63. Macro: Macro Implementation
      64. 11.4.64. MacroExit: Exit From Macro
      65. 11.4.65. MacroIf: Conditional Macro Implementation
      66. 11.4.66. MailboxExists: Check to see if Voicemail mailbox exists
      67. 11.4.67. Math: Performs Mathematical Functions
      68. 11.4.68. MD5: Calculate MD5 checksum
      69. 11.4.69. MD5Check: Check MD5 checksum
      70. 11.4.70. MeetMe: MeetMe conference bridge
      71. 11.4.71. MeetMeAdmin: MeetMe conference Administration
      72. 11.4.72. MeetMeCount: MeetMe participant count
      73. 11.4.73. Milliwatt: Generate a Constant 1000Hz tone at 0dbm (mu-law)
      74. 11.4.74. MixMonitor: Record a call and mix the audio during the recording
      75. 11.4.75. Monitor: Monitor a channel
      76. 11.4.76. MP3Player: Play an MP3 file or stream
      77. 11.4.77. MusicOnHold: Play Music On Hold indefinitely
      78. 11.4.78. NBScat: Play an NBS local stream
      79. 11.4.79. NoCDR: Tell Asterisk to not maintain a CDR for the current call
      80. 11.4.80. NoOp: Do Nothing
      81. 11.4.81. Page: Pages phones
      82. 11.4.82. Park: Park yourself
      83. 11.4.83. ParkAndAnnounce: Park and Announce
      84. 11.4.84. ParkedCall: Answer a parked call
      85. 11.4.85. PauseQueueMember: Pauses a queue member
      86. 11.4.86. Pickup: Directed Call Pickup
      87. 11.4.87. Playback: Play a file
      88. 11.4.88. PlayTones: Play a tone list
      89. 11.4.89. PrivacyManager: Require phone number to be entered, if no CallerID sent
      90. 11.4.90. Progress: Indicate progress
      91. 11.4.91. Queue: Queue a call for a call queue
      92. 11.4.92. Random: Conditionally branches, based upon a probability
      93. 11.4.93. Read: Read a variable
      94. 11.4.94. ReadFile: ReadFile(varname=file,length)
      95. 11.4.95. RealTime: Realtime Data Lookup
      96. 11.4.96. RealTimeUpdate: Realtime Data Rewrite
      97. 11.4.97. Record: Record to a file
      98. 11.4.98. RemoveQueueMember: Dynamically removes queue members
      99. 11.4.99. ResetCDR: Resets the Call Data Record
      100. 11.4.100. ResponseTimeout: Set maximum timeout awaiting response
      101. 11.4.101. Return: Return from gosub routine
      102. 11.4.102. Ringing: Indicate ringing tone
      103. 11.4.103. SayAlpha: Say Alpha
      104. 11.4.104. SayDigits: Say Digits
      105. 11.4.105. SayNumber: Say Number
      106. 11.4.106. SayPhonetic: Say Phonetic
      107. 11.4.107. SayUnixTime: Says a specified time in a custom format
      108. 11.4.108. SendDTMF: Sends arbitrary DTMF digits
      109. 11.4.109. SendImage: Send an image file
      110. 11.4.110. SendText: Send a Text Message
      111. 11.4.111. SendURL: Send a URL
      112. 11.4.112. Set: Set channel variable(s) or function value(s)
      113. 11.4.113. SetAccount: Set the CDR Account Code
      114. 11.4.114. SetAMAFlags: Set the AMA Flags
      115. 11.4.115. SetCallerID: Set CallerID
      116. 11.4.116. SetCallerPres: Set CallerID Presentation
      117. 11.4.117. SetCDRUserField: Set the CDR user field
      118. 11.4.118. SetCIDName: Set CallerID Name
      119. 11.4.119. SetCIDNum: Set CallerID Number
      120. 11.4.120. SetGlobalVar: Set a global variable to a given value
      121. 11.4.121. SetGroup: Set the channel's group
      122. 11.4.122. SetLanguage: Set the channel's preferred language
      123. 11.4.123. SetMusicOnHold: Set default Music On Hold class
      124. 11.4.124. SetRDNIS: Set RDNIS Number
      125. 11.4.125. SetTransferCapability: Set ISDN Transfer Capability
      126. 11.4.126. SetVar: Set channel variable(s)
      127. 11.4.127. SIPAddHeader: Add a SIP header to the outbound call
      128. 11.4.128. SIPDtmfMode: Change the dtmfmode for a SIP call
      129. 11.4.129. SIPGetHeader: Get a SIP header from an incoming call
      130. 11.4.130. SMS: Communicates with SMS service centres and SMS capable analogue phones
      131. 11.4.131. SoftHangup: Soft Hangup Application
      132. 11.4.132. Sort: Sorts a list of keywords and values
      133. 11.4.133. StackPop: Remove one address from gosub stack
      134. 11.4.134. StartMusicOnHold: Play Music On Hold
      135. 11.4.135. StopMonitor: Stop monitoring a channel
      136. 11.4.136. StopMusicOnHold: Stop Playing Music On Hold
      137. 11.4.137. StopPlayTones: Stop playing a tone list
      138. 11.4.138. System: Execute a system command
      139. 11.4.139. TestClient: Execute Interface Test Client
      140. 11.4.140. TestServer: Execute Interface Test Server
      141. 11.4.141. Transfer: Transfer caller to remote extension
      142. 11.4.142. TrySystem: Try executing a system command
      143. 11.4.143. TXTCIDName: Lookup caller name from TXT record
      144. 11.4.144. UnpauseQueueMember: Unpauses a queue member
      145. 11.4.145. UserEvent: Send an arbitrary event to the manager interface
      146. 11.4.146. Verbose: Send arbitrary text to verbose output
      147. 11.4.147. VMAuthenticate: Authenticate with Voicemail passwords
      148. 11.4.148. VoiceMail: Leave a Voicemail message
      149. 11.4.149. VoiceMailMain: Check Voicemail messages
      150. 11.4.150. Wait: Waits for some time
      151. 11.4.151. WaitExten: Waits for an extension to be entered
      152. 11.4.152. WaitForRing: Wait for Ring Application
      153. 11.4.153. WaitForSilence: Waits for a specified amount of silence
      154. 11.4.154. WaitMusicOnHold: Wait, playing Music On Hold
      155. 11.4.155. While: Start A While Loop
      156. 11.4.156. Zapateller: Block telemarketers with SIT
      157. 11.4.157. ZapBarge: Barge in (monitor) Zap channel
      158. 11.4.158. ZapRAS: Executes Zaptel ISDN RAS application
      159. 11.4.159. ZapScan: Scan Zap channels to monitor calls
    5. 11.5. GET DATA <filename> [<timeout> [<max digits>]]
    6. 11.6. GET VARIABLE <variablename>
    7. 11.7. HANGUP [<channelname>]
    8. 11.8. RECEIVE CHAR <timeout>
    9. 11.9. RECORD FILE <filename> <format> <escape digits> <timeout> [BEEP]
    10. 11.10. SAY DIGITS <digit string> <escape digits>
    11. 11.11. SAY NUMBER <number> <escape digits>
    12. 11.12. SEND IMAGE <image>
    13. 11.13. SEND TEXT "<text to send>"
    14. 11.14. SET CALLERID <caller ID specification>
    15. 11.15. SET CONTEXT <new context>
    16. 11.16. SET EXTENSION <new extension>
    17. 11.17. SET PRIORITY <new priority number>
    18. 11.18. SET VARIABLE <variablename> <value>
    19. 11.19. STREAM FILE <filename> <escape digits>
    20. 11.20. TDD MODE <setting>
    21. 11.21. VERBOSE <message> [<level>]
    22. 11.22. WAIT FOR DIGIT <timeout>

The FON Script API is provided free of charge, but not covered by Fonality Support. Fonality Support Engineers will not assist you with writing, modifying, or troubleshooting custom AGIs that you write or commission a 3rd party to write for you. Please do not contact us for any reason relating to the information on this page (even questions) or AGIs in general.

  1. 1. Fon Script Interface Overview
  2. 2. Example Application
  3. 3. Prerequisite
  4. 4. How To Configure Run Script
  5. 5. Calling Your Script
  6. 6. Example Script
  7. 7. Compatibility
  8. 8. Languages
  9. 9. Programming Tips
  10. 10. Environment Variables
  11. 11. FON Interface API Reference
    1. 11.1. ANSWER
    2. 11.2. AUTOHANGUP <time>
    3. 11.3. CHANNEL STATUS [<channelname>]
    4. 11.4. EXEC <application> <options>
      1. 11.4.1. AbsoluteTimeout: Set absolute maximum time of call
      2. 11.4.2. AddQueueMember: Dynamically adds queue members
      3. 11.4.3. ADSIProg: Load Asterisk ADSI Scripts into phone
      4. 11.4.4. AGI: Executes an AGI compliant application
      5. 11.4.5. AlarmReceiver: Provide support for receving alarm reports from a burglar or fire alarm panel
      6. 11.4.6. Answer: Answer a channel if ringing
      7. 11.4.7. AppendCDRUserField: Append to the CDR user field
      8. 11.4.8. Authenticate: Authenticate a user
      9. 11.4.9. BackGround: Play a file while awaiting extension
      10. 11.4.10. BackgroundDetect: Background a file with talk detect
      11. 11.4.11. Busy: Indicate the Busy condition
      12. 11.4.12. ChangeMonitor: Change monitoring filename of a channel
      13. 11.4.13. ChanInUse: Checks to see if channel is in use
      14. 11.4.14. ChanIsAvail: Check channel availability
      15. 11.4.15. ChanSpy: Listen to the audio of an active channel
      16. 11.4.16. CheckGroup: Check the channel count of a group against a limit
      17. 11.4.17. Congestion: Indicate the Congestion condition
      18. 11.4.18. ControlPlayback: Play a file with fast forward and rewind
      19. 11.4.19. Curl: Load an external URL
      20. 11.4.20. Cut: Splits a variable's contents using the specified delimiter
      21. 11.4.21. DateTime: Says a specified time in a custom format
      22. 11.4.22. DBdel: Delete a key from the database
      23. 11.4.23. DBdeltree: Delete a family or keytree from the database
      24. 11.4.24. DBget: Retrieve a value from the database
      25. 11.4.25. DBput: Store a value in the database
      26. 11.4.26. DeadAGI: Executes AGI on a hungup channel
      27. 11.4.27. Dial: Place a call and connect to the current channel
      28. 11.4.28. Dictate: Virtual Dictation Machine
      29. 11.4.29. DigitTimeout: Set maximum timeout between digits
      30. 11.4.30. Directory: Provide directory of voicemail extensions
      31. 11.4.31. DISA: DISA (Direct Inward System Access)
      32. 11.4.32. DumpChan: Dump Info About The Calling Channel
      33. 11.4.33. DUNDiLookup: Look up a number with DUNDi
      34. 11.4.34. EAGI: Executes an EAGI compliant application
      35. 11.4.35. Echo: Echo audio read back to the user
      36. 11.4.36. EndWhile: End A While Loop
      37. 11.4.37. EnumLookup: Lookup number in ENUM
      38. 11.4.38. Eval: Evaluates a string
      39. 11.4.39. Exec: Executes internal application
      40. 11.4.40. ExecIf: Conditional exec
      41. 11.4.41. ExecIfTime: Conditional application execution based on the current time
      42. 11.4.42. ExternalIVR: Interfaces with an external IVR application
      43. 11.4.43. Festival: Say text to the user
      44. 11.4.44. Flash: Flashes a Zap Trunk
      45. 11.4.45. FlushQueueStats: Flushes stats for specified queue
      46. 11.4.46. ForkCDR: Forks the Call Data Record
      47. 11.4.47. GetCPEID: Get ADSI CPE ID
      48. 11.4.48. GetGroupCount: Get the channel count of a group
      49. 11.4.49. GetGroupMatchCount: Get the channel count of all groups that match a pattern
      50. 11.4.50. Gosub: Jump to label, saving return address
      51. 11.4.51. GosubIf: Jump to label, saving return address
      52. 11.4.52. Goto: Jump to a particular priority, extension, or context
      53. 11.4.53. GotoIf: Conditional goto
      54. 11.4.54. GotoIfTime: Conditional Goto based on the current time
      55. 11.4.55. Hangup: Hang up the calling channel
      56. 11.4.56. HasNewVoicemail: Conditionally branches to priority + 101 with the right options set
      57. 11.4.57. HasVoicemail: Conditionally branches to priority + 101 with the right options set
      58. 11.4.58. IAX2Provision: Provision a calling IAXy with a given template
      59. 11.4.59. ICES: Encode and stream using 'ices'
      60. 11.4.60. ImportVar: Import a variable from a channel into a new variable
      61. 11.4.61. LookupBlacklist: Look up Caller*ID name/number from blacklist database
      62. 11.4.62. LookupCIDName: Look up CallerID Name from local database
      63. 11.4.63. Macro: Macro Implementation
      64. 11.4.64. MacroExit: Exit From Macro
      65. 11.4.65. MacroIf: Conditional Macro Implementation
      66. 11.4.66. MailboxExists: Check to see if Voicemail mailbox exists
      67. 11.4.67. Math: Performs Mathematical Functions
      68. 11.4.68. MD5: Calculate MD5 checksum
      69. 11.4.69. MD5Check: Check MD5 checksum
      70. 11.4.70. MeetMe: MeetMe conference bridge
      71. 11.4.71. MeetMeAdmin: MeetMe conference Administration
      72. 11.4.72. MeetMeCount: MeetMe participant count
      73. 11.4.73. Milliwatt: Generate a Constant 1000Hz tone at 0dbm (mu-law)
      74. 11.4.74. MixMonitor: Record a call and mix the audio during the recording
      75. 11.4.75. Monitor: Monitor a channel
      76. 11.4.76. MP3Player: Play an MP3 file or stream
      77. 11.4.77. MusicOnHold: Play Music On Hold indefinitely
      78. 11.4.78. NBScat: Play an NBS local stream
      79. 11.4.79. NoCDR: Tell Asterisk to not maintain a CDR for the current call
      80. 11.4.80. NoOp: Do Nothing
      81. 11.4.81. Page: Pages phones
      82. 11.4.82. Park: Park yourself
      83. 11.4.83. ParkAndAnnounce: Park and Announce
      84. 11.4.84. ParkedCall: Answer a parked call
      85. 11.4.85. PauseQueueMember: Pauses a queue member
      86. 11.4.86. Pickup: Directed Call Pickup
      87. 11.4.87. Playback: Play a file
      88. 11.4.88. PlayTones: Play a tone list
      89. 11.4.89. PrivacyManager: Require phone number to be entered, if no CallerID sent
      90. 11.4.90. Progress: Indicate progress
      91. 11.4.91. Queue: Queue a call for a call queue
      92. 11.4.92. Random: Conditionally branches, based upon a probability
      93. 11.4.93. Read: Read a variable
      94. 11.4.94. ReadFile: ReadFile(varname=file,length)
      95. 11.4.95. RealTime: Realtime Data Lookup
      96. 11.4.96. RealTimeUpdate: Realtime Data Rewrite
      97. 11.4.97. Record: Record to a file
      98. 11.4.98. RemoveQueueMember: Dynamically removes queue members
      99. 11.4.99. ResetCDR: Resets the Call Data Record
      100. 11.4.100. ResponseTimeout: Set maximum timeout awaiting response
      101. 11.4.101. Return: Return from gosub routine
      102. 11.4.102. Ringing: Indicate ringing tone
      103. 11.4.103. SayAlpha: Say Alpha
      104. 11.4.104. SayDigits: Say Digits
      105. 11.4.105. SayNumber: Say Number
      106. 11.4.106. SayPhonetic: Say Phonetic
      107. 11.4.107. SayUnixTime: Says a specified time in a custom format
      108. 11.4.108. SendDTMF: Sends arbitrary DTMF digits
      109. 11.4.109. SendImage: Send an image file
      110. 11.4.110. SendText: Send a Text Message
      111. 11.4.111. SendURL: Send a URL
      112. 11.4.112. Set: Set channel variable(s) or function value(s)
      113. 11.4.113. SetAccount: Set the CDR Account Code
      114. 11.4.114. SetAMAFlags: Set the AMA Flags
      115. 11.4.115. SetCallerID: Set CallerID
      116. 11.4.116. SetCallerPres: Set CallerID Presentation
      117. 11.4.117. SetCDRUserField: Set the CDR user field
      118. 11.4.118. SetCIDName: Set CallerID Name
      119. 11.4.119. SetCIDNum: Set CallerID Number
      120. 11.4.120. SetGlobalVar: Set a global variable to a given value
      121. 11.4.121. SetGroup: Set the channel's group
      122. 11.4.122. SetLanguage: Set the channel's preferred language
      123. 11.4.123. SetMusicOnHold: Set default Music On Hold class
      124. 11.4.124. SetRDNIS: Set RDNIS Number
      125. 11.4.125. SetTransferCapability: Set ISDN Transfer Capability
      126. 11.4.126. SetVar: Set channel variable(s)
      127. 11.4.127. SIPAddHeader: Add a SIP header to the outbound call
      128. 11.4.128. SIPDtmfMode: Change the dtmfmode for a SIP call
      129. 11.4.129. SIPGetHeader: Get a SIP header from an incoming call
      130. 11.4.130. SMS: Communicates with SMS service centres and SMS capable analogue phones
      131. 11.4.131. SoftHangup: Soft Hangup Application
      132. 11.4.132. Sort: Sorts a list of keywords and values
      133. 11.4.133. StackPop: Remove one address from gosub stack
      134. 11.4.134. StartMusicOnHold: Play Music On Hold
      135. 11.4.135. StopMonitor: Stop monitoring a channel
      136. 11.4.136. StopMusicOnHold: Stop Playing Music On Hold
      137. 11.4.137. StopPlayTones: Stop playing a tone list
      138. 11.4.138. System: Execute a system command
      139. 11.4.139. TestClient: Execute Interface Test Client
      140. 11.4.140. TestServer: Execute Interface Test Server
      141. 11.4.141. Transfer: Transfer caller to remote extension
      142. 11.4.142. TrySystem: Try executing a system command
      143. 11.4.143. TXTCIDName: Lookup caller name from TXT record
      144. 11.4.144. UnpauseQueueMember: Unpauses a queue member
      145. 11.4.145. UserEvent: Send an arbitrary event to the manager interface
      146. 11.4.146. Verbose: Send arbitrary text to verbose output
      147. 11.4.147. VMAuthenticate: Authenticate with Voicemail passwords
      148. 11.4.148. VoiceMail: Leave a Voicemail message
      149. 11.4.149. VoiceMailMain: Check Voicemail messages
      150. 11.4.150. Wait: Waits for some time
      151. 11.4.151. WaitExten: Waits for an extension to be entered
      152. 11.4.152. WaitForRing: Wait for Ring Application
      153. 11.4.153. WaitForSilence: Waits for a specified amount of silence
      154. 11.4.154. WaitMusicOnHold: Wait, playing Music On Hold
      155. 11.4.155. While: Start A While Loop
      156. 11.4.156. Zapateller: Block telemarketers with SIT
      157. 11.4.157. ZapBarge: Barge in (monitor) Zap channel
      158. 11.4.158. ZapRAS: Executes Zaptel ISDN RAS application
      159. 11.4.159. ZapScan: Scan Zap channels to monitor calls
    5. 11.5. GET DATA <filename> [<timeout> [<max digits>]]
    6. 11.6. GET VARIABLE <variablename>
    7. 11.7. HANGUP [<channelname>]
    8. 11.8. RECEIVE CHAR <timeout>
    9. 11.9. RECORD FILE <filename> <format> <escape digits> <timeout> [BEEP]
    10. 11.10. SAY DIGITS <digit string> <escape digits>
    11. 11.11. SAY NUMBER <number> <escape digits>
    12. 11.12. SEND IMAGE <image>
    13. 11.13. SEND TEXT "<text to send>"
    14. 11.14. SET CALLERID <caller ID specification>
    15. 11.15. SET CONTEXT <new context>
    16. 11.16. SET EXTENSION <new extension>
    17. 11.17. SET PRIORITY <new priority number>
    18. 11.18. SET VARIABLE <variablename> <value>
    19. 11.19. STREAM FILE <filename> <escape digits>
    20. 11.20. TDD MODE <setting>
    21. 11.21. VERBOSE <message> [<level>]
    22. 11.22. WAIT FOR DIGIT <timeout>


Fon Script Interface Overview

The FON Script Interface allows software developers and system integrators to extend the functionality of their PBXtra CCE systems by allowing them to create customized extensions to the PBXtra system using a standardized API. This facility allows the creation of custom IVR applications that will impress your friends, and probably get you promoted ;-).


Example Application

One example of a FON Script application is a store locater. This program would prompt the caller to key in his zip code, and look up a list of stores in a cross reference table of a database. Once the correct store is identified the caller is then automatically connected with the correct store.


Prerequisite

You must have the PBXtra Call Center Edition of the Fonality software in order to use this feature. In CCE it will be shown in your call menu as "Run Script".


How To Configure Run Script

  1. Log into your PBXtra Admin Web Interface using your administrative username and password.
  2. Click on the AutoAnswer tab.
  3. Click on the call menu tab.
  4. Add a new Call Sequence named Run Script.
  5. Specify the path to the script in your /var/lib/asterisk/agi-bin/ directory.

Exmaple:

my_script.agi

Example for a script listening on a port:

fon://ip.add.re.ss:port

Note: If you are running PBXtra Core version 1.2.14-fon-o or newer, you can also pass HTTP style arguments to the script like this:

my_script.agi?extension=${EXTEN}

You can look for them in your script using the environment variables.


Calling Your Script

If you have connected your FON Interface Script to your call menu, you can dial "0" from any of your extensions to reach your main menu, and subsequently reach the AGI for testing. You may also dial in from an external line.



Example Script

This example Perl script is available under the GNU License. It demonstrates basic interaction with the PBXtra Core software from your server using the STDOUT file handle. It also shows how to get digit input from your callers.

#!/usr/bin/perl
use strict;      # Load the strict pragma to enforce good program form
use Socket;      # Load the socket library to let us speak TCP/IP
use Carp;        # Load an error handling library
use IO::Handle;  # Overload the I/O functions with more appropriate ones

my $port = 4573; # TCP Port number to listen on

$|=1; # Activate auto-flush to disable text buffering in perl

# Setup Variables
my %AGI;       # Init a hash structure to be used for AGI environment
my $tests = 0; # A counter for the number of tests that have been run
my $fail = 0;  # A counter for failure conditions
my $pass = 0;  # A counter for success conditions

##############################################################################
# checkresult: A function to check the return status of a command to 
#              detect any errors.
#
#   Arguments: $res = A result from an AGI command
#     Returns: none, sets $pass and $fail counters
##############################################################################
sub checkresult {
        my ($res) = @_;
        my $retval;
        $tests++;
        chomp $res;
        if ($res =~ /^200/) {
                $res =~ /result=(-?\d+)/;
                if (!length($1)) {
                        print STDERR "FAIL ($res)\n";
                        $fail++;
                } else {
                        print STDERR "PASS ($1)\n";
                        $pass++;
                }
        } else {
                print STDERR "FAIL (unexpected result '$res')\n";
                $fail++;
        }
}

# Set up a TCP/IP socket, and bind/listen to it for new connections
# from the PXBtra Core software (the client)
socket(SERVER, PF_INET, SOCK_STREAM, 0);
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, pack("l", 1));
bind(SERVER, sockaddr_in($port, INADDR_ANY)) || die("can't bind\n");
listen(SERVER, SOMAXCONN);

# Start the FastAGI/FON request loop
for(;;) {
        # We will wait for a connection. The accept() call will block until
        # a connection arrives. While processing, connections line up.
        my $raddr = accept(CLIENT, SERVER); # Get the next connection
        my ($s, $p) = sockaddr_in($raddr);  # 
        CLIENT->autoflush(1); # Disable text buffering client connection
        while(<CLIENT>) { # Read all the text sent from the client to the server
                chomp;    # Eliminate any newlines on the end of the text
                last unless length($_); # If the line is empty, stop reading
                if (/^agi_(\w+)\:\s+(.*)$/) { # Look for variables starting with agi_
                        # Set AGI hash keyed by variable