[asterisk-app-dev] Mapping ARI events to imperative call flows
Alistair Cunningham
acunningham at integrics.com
Mon Oct 14 22:27:13 CDT 2013
ARI is inherently different to AGI in that it's event oriented rather
than imperative oriented. I'm wondering, as an AGI developer, what the
best way to handle this is. For example, consider the following
pseudocode for a simple AGI voicemail application:
while ( ! hungup() ) {
key = menu( 'main_menu' );
if ( key == 1 ) {
foreach message ( get_messages() ) {
key2 = menu( message );
if ( key2 == 3 ) {
delete( message );
}
}
} else if ( key == 2 ) {
password = data( 'enter_new_password' );
set_password( password );
} else {
menu( 'invalid_key' );
}
}
If implementing this using ARI, we're going to get events such as
PlaybackFinished, ChannelDtmfReceived, and Hangup. When this happens,
how do we know where we are in the call flow and what to do next?
Several options spring to mind:
1. Implement a pure state engine. Keep a data structure for each active
call. When we receive relevant events we update the data structure, and
figure where we are in the call flow using lots of if statements. This
seems inelegant and hard to maintain for large call flows.
2. Implement a separate thread or forked subprocess for each call, that
implements the imperative pseudocode above. Have the helper functions
menu() and data() block when called. Have the master thread/process pass
a message to the call thread/process when an event is received, and have
the helper function return if appropriate. I'm leaning towards this
model as it makes maintaining large complex flows easier, though I'm
worried that it means losing some of the flexibility of event driven
programming.
3. Something clever with closures. This is somewhat outside my personal
experience, and I don't know how this would work.
--
Alistair Cunningham
+1 888 468 3111
+44 20 799 39 799
http://integrics.com/
More information about the asterisk-app-dev
mailing list