Programming fastAGI for Asterisk using Python?

I want to write fastAGI scripts in Python. I looked over the net to find very minimal documentation on this. So far I have found that there are pyst , pyst2 , starpy , which are quite popular. But the problem is that they lack even the most important documentation (or at least I did not find it). I want to know if there are good resources to start fastAGI programming in python using any of the existing libraries instead of rewriting everything from scratch.

I also want to know if there are other good libraries like the ones I mentioned.

If nothing is available, what are my options?

+4
source share
2 answers

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://host:port/testcall) exten => s,n,Hangup() 

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): # Do something here def kill(self): self._fagi_server.shutdown() def run(self): self._fagi_server.serve_forever() if __name__ == '__main__': fastagi_core = FastAGIServer() fastagi_core.start() while fastagi_core.is_alive(): time.sleep(1) fastagi_core.kill() 

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.

+5
source

You can read the general document here.

http://www.voip-info.org/wiki/view/Asterisk+FastAGI

http://www.voip-info.org/wiki/view/Asterisk+AGI

It is very simple, I am sure you can understand the lib calls based on this. Also on the second page there is a list of libs for python.

To start with an asterisk: Asterisk The Future of the Phone Book http://shop.oreilly.com/product/9780596009625.do

+1
source

All Articles