-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReceiveOneDigit.py
66 lines (60 loc) · 1.85 KB
/
ReceiveOneDigit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# !/usr/bin/env python
from twisted.internet import reactor
from starpy import fastagi
import logging,time
log = logging.getLogger( 'answer')
log.setLevel(logging.DEBUG)
class Answer(object):
'''Answer Class for only answer call'''
def __init__(self):
print "Answer Constructor Initialized"
def __call__(self, agi):
self.agi = agi
return self.agi.answer().addCallbacks(self.Answered,self.AnswerFailed)
def Answered(self,resultline):
print "Answered Successful"
self.agi.getData('test',10,1).addCallbacks(self.GetDtmfString,self.FailDtmfString)
return Hangup()
def GetDtmfString(self,(dtmfstr,timeoutflag)):
if timeoutflag:
print "DTMF Timeout"
else:
print "DTMF %s RECEIVED"%[dtmfstr]
def FailDtmfString(self,reason):
print "Answer Failed"
def AnswerFailed(self,reason):
print "Answer Object Failed"
class Hangup(object):
def __init__(self):
print "Rejecting Call Object"
def __call__(self, agi):
self.agi = agi
return self.agi.hangup().addCallbacks(self.OnHangupSuccess,self.OnHangupFail)
def OnHangupSuccess(self, resultLine):
print "Channel Hangup Success"
return self.agi.wait(1.0)
def OnHangupFail(self,reason):
print "Channel Hangup Fail"
class Callflow(object):
'''Callflow Class for Manage Callflow'''
def __init__(self):
print "Callflow Initialized"
def __call__(self, agi):
self.agi=agi
self.current=Answer()
def __call__(self, agi):
self.agi= agi
print "Agi Call Started"
self.current=Answer()
return self.current(self.agi).addBoth(self.whatNext)
def whatNext(self, reason):
print "Successfully Answered"
def CallClearing(self,reason):
print "Call Clearing"
return self.agi.finish()
if __name__ == '__main__':
logging.basicConfig()
fastagi.log.setLevel(logging.DEBUG)
fun = fastagi.FastAGIFactory(Callflow())
reactor.listenTCP(4573, fun, 50, '127.0.0.1')
reactor.run()