To receive an external message asynchronously, an application defines an "externalmessage" event handler. If the payload of an external message includes an event name, the name is appended to the name of the event that is thrown to the application separated by a dot, or example, "externalmessage.ready". This allows applications to handle external messages using different event handlers.
Asynchronous external messages are processed in the same manner that a disconnect event is handled in VXML2.
Events are dispatched to the application serially. Because the interpreter only reflects the data associated with a single external message at a time, the application handles the data associated with each external message after that message is delivered. If multiple events arrive, VB deals with them one at a time, until all events are processed, or when execution goes to an element where externalevents. enable turns to false, whichever happens first.
The following example demonstrates asynchronous receipt of an external message. The catch handler copies the reflected external message into an array at the application level.
<vxml version="2.1"
xmlns="http://www.w3.org/2001/vxml">
<property name="externalevents.enable" value="true"/>
<var name="myMessages" expr="new Array()"/>
<catch event="externalmessage">
<var name="lm" expr="application.lastmessage$"/>
<if cond="typeof lm.content == 'string'"/>
<log>received <value expr="lm.content"/></log>
<else/>
<log>received unknown external message type
<value expr="typeof lm.content"/>
</log>
</if>
<script>
myMessages.push({'content' : lm.content, 'ctype' : lm.contenttype});
</script>
</catch>
<form>
<field name="num" type="digits">
<prompt>pick a number any number</prompt>
<catch event="noinput nomatch">
sorry. didn't get that.
<reprompt/>
</catch>
<filled>
you said <value expr="num"/>
<clear/>
</filled>
</field>
</form>
</vxml>