<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2171/18/9/_/styles/combined.css?spaceKey=AST&forWysiwyg=true" type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://wiki.asterisk.org/wiki/display/AST/External+IVR+Interface">External IVR Interface</a></h2>
<h4>Page <b>edited</b> by <a href="https://wiki.asterisk.org/wiki/display/~seanbright">Sean Bright</a>
</h4>
<br/>
<h4>Changes (2)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" >* E,message <br>* O,option <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">* V,name=value[,name=value[,name=value]] <br>* G,name[,name[,name]] <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">* V,name=value\[,name=value\[,name=value\]\] <br>* G,name\[,name\[,name\]\] <br></td></tr>
<tr><td class="diff-unchanged" >* L,log_message <br>* P,TIMESTAMP <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<h1><a name="ExternalIVRInterface-AsteriskExternalIVRInterface"></a>Asterisk External IVR Interface</h1>
<p>If you load app_externalivr.so in your Asterisk instance, you will have an ExternalIVR() application available in your dialplan. This application implements a simple protocol for bidirectional communication with an external process, while simultaneous playing audio files to the connected channel (without interruption or blocking).</p>
<p>There are two ways to use ExternalIVR(); you can execute an application on the local system or you can establish a socket<br/>
connection to a TCP/IP socket server.</p>
<p>To execute a local application use the form:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">ExternalIVR(/full/path/to/applcation[(arguments)],options)</pre>
</div></div>
<p>The arguments are optional, however if they exist they must be enclosed in parentheses. The external application will be executed in a child process, with its standard file handles connected to the Asterisk process as follows:</p>
<ul>
        <li>stdin (0) - Events will be received on this handle</li>
        <li>stdout (1) - Commands can be sent on this handle</li>
        <li>stderr (2) - Messages can be sent on this handle</li>
</ul>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>Use of stderr for message communication is discouraged because it is not supported by a socket connection.</td></tr></table></div>
<p>To create a socket connection use the form:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">ExternalIVR(ivr://host[:port][(arguments)],options)</pre>
</div></div>
<p>The host can be a fqdn or an ip address. The port is optional, if not specified the default of 2949 will be used. The arguments are optional however if they exist they must be enclosed in parentheses. TheExternalIVR application will connect to the specified socket server and establish a bi-directional socket connection, where events will be sent to the TCP/IP server and commands received from it.</p>
<p>The specific ExternalIVR options, events and commands are detailed below.</p>
<p>Upon execution, if not specifically prevented by an option, the ExternalIVR application will answer the channel (if it's not already answered), create an audio generator, and start playing silence. When your application wants to send audio to the channel, it can send a command (see below) to add a file to the generator's playlist. The generator will then work its way through the list, playing each file in turn until it either runs out of files to play, the channel is hung up, or a command is received to clear the list and start with a new file. At any time, more files can be added to the list and the generator will play them in sequence.</p>
<p>While the generator is playing audio (or silence), any DTMF events received on the channel will be sent to the child process (see below). Note that this can happen at any time, since the generator, the child process and the channel thread are all executing independently. It is very important that your external application be ready to receive events from Asterisk at all times (without blocking), or you could cause the channel to become non-responsive.</p>
<p>If the child process dies, or the remote server disconnects, ExternalIVR() will notice this and hang up the channel<br/>
immediately (and also send a message to the log). </p>
<h5><a name="ExternalIVRInterface-ExternalIVR%28%29Options"></a>ExternalIVR() Options</h5>
<ul>
        <li>n - 'n'oanswer, don't answer an otherwise unanswered channel.</li>
        <li>i - 'i'gnore_hangup, instead of sending an 'H' event and exiting ExternalIVR() upon channel hangup, it instead sends an 'I'event and expects the external application to exit the process.</li>
        <li>d - 'd'ead, allows the operation of ExternalIVR() on channels that have already been hung up.</li>
</ul>
<h5><a name="ExternalIVRInterface-Events"></a>Events</h5>
<p>All events are be newline-terminated strings and are sent in the following format:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">tag,timestamp[,data]</pre>
</div></div>
<p>The tag can be one of the following characters:</p>
<ul>
        <li>0-9 - DTMF event for keys 0 through 9</li>
        <li>A-D - DTMF event for keys A through D</li>
        <li>* - DTMF event for key *</li>
        <li># - DTMF event for key #</li>
        <li>H - The channel was hung up by the connected party</li>
        <li>E - The script requested an exit</li>
        <li>Z - The previous command was unable to be executed. There may be a data element if appropriate, see specific commands below for details</li>
        <li>T - The play list was interrupted (see S command below)</li>
        <li>D - A file was dropped from the play list due to interruption (the data element will be the dropped file name) NOTE: this tag conflicts with the D DTMF event tag. The existence of the data element is used to differentiate between the two cases</li>
        <li>F - A file has finished playing (the data element will be the file name)</li>
        <li>P - A response to the 'P' command (see below)</li>
        <li>G - A response to the 'G' command (see below)</li>
        <li>I - A Inform message, meant to "inform" the client that something has occurred. (see Inform Messages below)</li>
</ul>
<p>The timestamp will be 10 digits long, and will be a decimal representation of a standard Unix epoch-based timestamp.</p>
<h5><a name="ExternalIVRInterface-Commands"></a>Commands</h5>
<p>All commands are newline-terminated strings.</p>
<p>The child process can send one of the following commands:</p>
<ul>
        <li>S,filename</li>
        <li>A,filename</li>
        <li>H,message</li>
        <li>E,message</li>
        <li>O,option</li>
        <li>V,name=value[,name=value[,name=value]]</li>
        <li>G,name[,name[,name]]</li>
        <li>L,log_message</li>
        <li>P,TIMESTAMP</li>
        <li>T,TIMESTAMP</li>
</ul>
<p>The 'S' command checks to see if there is a playable audio file with the specified name, and if so, clear's the generator's playlist and places the file onto the list. Note that the playability check does not take into account transcoding requirements, so it is possible for the file to not be played even though it was found. If the file does not exist it sends a Z response with the data element set to the file requested. If the generator is not currently playing silence, then T<br/>
and D events will be sent to signal the playlist interruption and notify it of the files that will not be played.</p>
<p>The 'A' command checks to see if there is a playable audio file with the specified name, and if so, appends it to the generator's playlist. The same playability and exception rules apply as for the 'S' command.</p>
<p>The 'E' command logs the supplied message to the Asterisk log, stops the generator and terminates the ExternalIVR application, but continues execution in the dialplan.</p>
<p>The 'H' command logs the supplied message to the Asterisk log, stops the generator, hangs up the channel and terminates the ExternalIVR application.</p>
<p>The 'O' command allows the child to set/clear options in the ExternalIVR() application. The supported options are:<br/>
(no)autoclear: Automatically interrupt and clear the playlist upon reception of DTMF input.</p>
<p>The 'T' command will answer an unanswered channel. If it fails either answering the channel or starting the generator it sends a Z response of "Z,TIMESTAMP,ANSWER_FAILED" or "Z,TIMESTAMP,GENERATOR_FAILED" respectively.</p>
<p>The 'V' command sets the specified channel variable(s) to the specified value(s).</p>
<p>The 'G' command gets the specified channel variable(s). Multiple variables are separated by commas. Response is in name=value format.</p>
<p>The 'P' command gets the parameters passed into ExternalIVR() minus the options to ExternalIVR() itself:</p>
<p>If ExternalIVR() is executed as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">ExternalIVR(/usr/bin/foo(arg1,arg2),n)</pre>
</div></div>
<p>The response to the 'P' command would be:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">P,TIMESTAMP,/usr/bin/foo,arg1,arg2</pre>
</div></div>
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>This is the only way for a TCP/IP server to be able to get retrieve the arguments.</td></tr></table></div>
<p>The 'L' command puts a message into the Asterisk log.</p>
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>This is preferred to using stderr and is the only way for a TCP/IP server to log a message.</td></tr></table></div>
<h5><a name="ExternalIVRInterface-InformMessages"></a>Inform Messages</h5>
<p>The only inform message that currently exists is a HANGUP message, in the form I,TIMESTAMP,HANGUP and is used to inform of a hangup when the i option is specified.</p>
<h5><a name="ExternalIVRInterface-Errors"></a>Errors</h5>
<p>Any newline-terminated output generated by the child process on its stderr handle will be copied into the Asterisk log.</p>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;" class="grey">
<a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
<span style="padding: 0px 5px;">|</span>
<a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/display/AST/External+IVR+Interface">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=4260001&revisedVersion=2&originalVersion=1">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/AST/External+IVR+Interface?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>