YAYPM:Simple IVR: Difference between revisions
Jump to navigation
Jump to search
Created page with "Here is a toy ivr. It routes calls to number 'ivr' to DumbChannel, answers them, then listens for dtms and plays back digit announcement for every dtmf. You need to provide yo..." |
No edit summary |
||
| (3 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
Here is a toy ivr. It routes calls to number 'ivr' to DumbChannel, answers them, then listens for | Here is a toy ivr. It routes calls to number 'ivr' to DumbChannel, answers them, then listens for DTMFs and plays back digit announcement for every dtmf. You need to provide your own digit recordings. | ||
#!/usr/bin/python | #!/usr/bin/python | ||
| Line 6: | Line 6: | ||
logger = logging.getLogger('yaypm.examples') | logger = logging.getLogger('yaypm.examples') | ||
def route(yate): | def route(yate): | ||
def on_route(route): | def on_route(route): | ||
callid = route["id"] | callid = route["id"] | ||
route.ret(True, "dumb/") | route.ret(True, "dumb/") | ||
def on_execute(execute): | def on_execute(execute): | ||
yate.msg("call.answered", | yate.msg("call.answered", | ||
| Line 31: | Line 31: | ||
lambda m : m["id"] == execute["id"]) | lambda m : m["id"] == execute["id"]) | ||
dtmf.addCallback(on_dtmf) | dtmf.addCallback(on_dtmf) | ||
execute = yate.onwatch("call.execute", | execute = yate.onwatch("call.execute", | ||
lambda m : m["id"] == callid) | lambda m : m["id"] == callid) | ||
execute.addCallback(on_execute) | execute.addCallback(on_execute) | ||
yate.onmsg("call.route").addCallback(on_route) | yate.onmsg("call.route").addCallback(on_route) | ||
yate.onmsg("call.route", | yate.onmsg("call.route", | ||
lambda m : m["called"] == "ivr").addCallback(on_route) | lambda m : m["called"] == "ivr").addCallback(on_route) | ||
if __name__ in ["__main__"]: | if __name__ in ["__main__"]: | ||
logger.setLevel(logging.DEBUG) | logger.setLevel(logging.DEBUG) | ||
yaypm.utils.setup(route) | yaypm.utils.setup(route) | ||
'''See also''' | |||
* [[YAYPM:Simple IVR with Inline Callbacks]] | |||
* [[YAYPM:Bridge and then unbridge]] | |||
* [[YAYPM:Bridge and then redirect after a hangup]] | |||
[[Category:Extmodule]] [[Category:YAYPM]] [[Category:Programmers]] [[Category:Scripting]] [[Category:IVR]] | |||
Latest revision as of 11:54, 4 November 2013
Here is a toy ivr. It routes calls to number 'ivr' to DumbChannel, answers them, then listens for DTMFs and plays back digit announcement for every dtmf. You need to provide your own digit recordings.
#!/usr/bin/python
import logging, yaypm.utils
logger = logging.getLogger('yaypm.examples')
def route(yate):
def on_route(route):
callid = route["id"]
route.ret(True, "dumb/")
def on_execute(execute):
yate.msg("call.answered",
{"id": execute["targetid"],
"targetid": execute["id"]}).enqueue()
logger.debug("Call %s answered." % callid)
def on_dtmf(dtmf):
logger.debug("Dtmf %s received." % dtmf["text"])
yate.msg("chan.masquerade",
{"message" : "chan.attach",
"id": dtmf["targetid"],
"source": "wave/play/./sounds/digits/pl/%s.gsm" % \
dtmf["text"]}).enqueue()
dtmfid = dtmf["id"]
yate.onwatch("chan.dtmf",
lambda m : m["id"] == dtmfid).addCallback(on_dtmf)
dtmf.ret(True)
dtmf = yate.onmsg("chan.dtmf",
lambda m : m["id"] == execute["id"])
dtmf.addCallback(on_dtmf)
execute = yate.onwatch("call.execute",
lambda m : m["id"] == callid)
execute.addCallback(on_execute)
yate.onmsg("call.route").addCallback(on_route)
yate.onmsg("call.route",
lambda m : m["called"] == "ivr").addCallback(on_route)
if __name__ in ["__main__"]:
logger.setLevel(logging.DEBUG)
yaypm.utils.setup(route)
See also