Python框架starpy点击调用,一切都配置正确,但没有调用,不得不提到我正在使用voip.ms。
来自网址的我通过此http://localhost:8000/?number=00593968196867&ext=101
来取消它一切都成功并连接,但它不会调用
from starpy import manager
from starpy.manager import AMIFactory
from twisted.internet import reactor
from twisted.web import server,resource
import logging
logging.basicConfig()
log = logging.getLogger("Click2Call")
log.setLevel(logging.DEBUG)
manager.log.setLevel(logging.DEBUG)
class Click2CallProtocol(object):
def __init__(self):
pass
def onConnect(self,ami):
log.info("Logged in successfully")
self.ami = ami
def dial(self,number,ext):
try:
# here goes the SIP configuretion details and the number you call
self.ami.originate(channel='Local/101@mycontext',context='mycontext',priority='1',exten=ext,async=True)
return True
except:
return False
class Click2CallFactory(AMIFactory):
def __init__(self):
# the user and password from manager.conf
AMIFactory.__init__(self,"admin","Admin")
def connect(self):
df = self.login("127.0.0.1")
df.addCallback(c2cp.onConnect)
def clientConnectionLost(self,connector,reason):
log.info("We lost connection trying reconnect")
reactor.callLater(1,self.connect)
def clientConnectionFailed(self,connector,reason):
log.info(reason)
reactor.callLater(1,self.connect)
class Click2CallResource(resource.Resource):
def render(self,request):
try:
number = request.args['number'][0]
agent = request.args['ext'][0]
except:
return "Required arguments not found"
if c2cp.dial(agent,number):
return "OK"
else:
return "NOTOK"
c2cp = Click2CallProtocol()
c2cf = Click2CallFactory()
c2cf.connect()
root = Click2CallResource()
root.putChild("",root)
site = server.Site(root)
reactor.listenTCP(8000,site,)
reactor.run()
答案 0 :(得分:0)
Local / 101 @ mycontext 应该是有效的dialstraing。即你需要mycontext和ext 101。
为什么你使用扭曲,工厂等来完成如此简单的单线程任务?