There are many Asterisk Libs in Python that you can use to develop FastAGI. One of them, Pystrix ( http://code.google.com/p/pystrix/ ), written by Neil Tallim. Here is an example of how you can create a FastAgi server.
In dialog mode, you sent a call to the FastAGI server:
[some-context] exten => 567567,1,NoOp() exten => s,n,AGI(agi:
Create a FastAgi server to listen on the / testcall URL:
import pystrix class FastAGIServer(threading.Thread): _fagi_server = None def __init__(self): threading.Thread.__init__(self) self.daemon = True self._fagi_server = pystrix.agi.FastAGIServer() self._fagi_server.register_script_handler(re.compile('testcall'), self._testcall_handler) self._fagi_server.register_script_handler(None, self._fallback_handler) def _testcall_handler(self, agi, args, kwargs, match, path): agi.execute(pystrix.agi.core.Answer()) response = agi.execute(pystrix.agi.core.StreamFile('demo-thanks', escape_digits=('1', '2'))) agi.execute(pystrix.agi.core.Hangup()) def _fallback_handler(self, agi, args, kwargs, match, path):
It is like CGI if you know it. The above code is copied from the Pystrix fastagi sample page . Please refer to them to read the inline comments. In addition, the documentation is still small, but the code is clean, concise, and understandable. Just jump into it and experiment.
If you are using the FreePBX / Elastix distribution, you can write a dialplan for [from-pstn] , and then check the call on 7777 to make it complete. For a large-scale application, you can get inspiration from Django's URL mapping and implement it here.