YAYPM:Simple IVR with Inline Callbacks
From Yate Documentation
(Difference between revisions)
(Created page with " Same example as above, this time with Inline Callbacks. Notice how readablity has improved over bare deferreds version: #!/usr/bin/python from twisted.internet import de...") |
|||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
Same example as above, this time with Inline Callbacks. Notice how readablity has improved over bare deferreds version: | Same example as above, this time with Inline Callbacks. Notice how readablity has improved over bare deferreds version: | ||
− | |||
#!/usr/bin/python | #!/usr/bin/python | ||
Line 54: | Line 53: | ||
logger.setLevel(logging.DEBUG) | logger.setLevel(logging.DEBUG) | ||
yaypm.utils.setup(lambda yate: route(yate)) | yaypm.utils.setup(lambda yate: route(yate)) | ||
+ | |||
+ | '''See also''' | ||
+ | |||
+ | * [[YAYPM:Bridge and then unbridge]] | ||
+ | * [[YAYPM:Bridge and then redirect after a hangup]] | ||
+ | |||
+ | [[Category:IVR]] [[Category:YAYPM]] [[Category:Programmers]] [[Category:Scripting]] |
Latest revision as of 13:58, 4 November 2013
Same example as above, this time with Inline Callbacks. Notice how readablity has improved over bare deferreds version:
#!/usr/bin/python from twisted.internet import defer from yaypm import AbandonedException import logging, yaypm.utils logger = logging.getLogger('yaypm.examples') @defer.inlineCallbacks def ivr(yate, callid): try: end = yate.onwatch("chan.hangup", lambda m : m["id"] == callid) execute = yield yate.onwatch("call.execute", lambda m : m["id"] == callid, until = end) targetid = execute["targetid"] yate.msg("call.answered", {"id": targetid, "targetid": callid}).enqueue() logger.debug("Call %s answered." % callid) while True: dtmf = yield yate.onmsg("chan.dtmf", lambda m : m["id"] == callid, end) logger.debug("Dtmf %s received." % dtmf["text"]) yate.msg("chan.masquerade", {"message" : "chan.attach", "id": targetid, "source": "wave/play/./sounds/digits/pl/%s.gsm" % \ dtmf["text"]}).enqueue() dtmf.ret(True) except AbandonedException, e: logger.debug("Call %s abandoned." % callid) @defer.inlineCallbacks def route(yate): while True: route = yield yate.onmsg("call.route", lambda m : m["called"] == "ivr") ivr(yate, route["id"]) route.ret(True, "dumb/") if __name__ in ["__main__", "__embedded_yaypm_module__"]: logger.setLevel(logging.DEBUG) yaypm.utils.setup(lambda yate: route(yate))
See also