我很陌生,因为阿里(Ari)的脚本以供星号(Asterisk)撰写,我一直在尝试制作一些脚本来处理Python中与Ari-py的1比1交流。我一直在遵循星号Wiki中提供的示例,到目前为止还不错。但是,当我尝试创建一个呼叫时,即使我已经回答了接收者,也总是会继续响起。我如何处理电话有什么问题吗?这是我的脚本
def stasis_start_cb(self, channel, ev):
"""Handler for StasisStart event"""
chan = channel.get('channel')
chan.answer()
print "Channel %s has entered the application" % chan.json.get('name')
outgoing = client.channels.originate(endpoint="SIP/1002", extension='1002', callerId='Tes', app='channel-dump', appArgs='dialed')
我尝试使用OOP简化函数用法,该脚本有什么问题吗?这是另一个试图使用桥梁打电话的脚本:
def outgoing_call(self,channel):
try:
outgoing = client.channels.originate(endpoint="SIP/1002", app='channel-dump', appArgs='dialed')
except requests.HTTPError:
channel.hangup()
return
def outgoing_start(self, bri, channel):
channel.answer()
self.addChan(channel, bridge)
def stasis_start(self, channel, ev):
chan = channel.get('channel')
name = chan.json.get('name')
"""ars = ev.get('args')
if not ars:
print "Error: {} didn't provide any arguments!".format(name)
return
if ars and ars[0] != 'inbound':
return
if len(ars) != 2:
print "Error: {} didn't tell us who to dial".format(name)
chan.hangup()"""
print "Channel {} entered the application".format(name)
chan.ring()
self.outgoing_call(chan)
self.outgoing_start(bridge, chan)
两个客户都可以在桥中添加,我可以打电话,但是问题仍然存在,收件人仍然说他们正在响起,尽管我已经接了电话
结果,问题在这里
def outgoing_call(self,channel):
try:
outgoing = client.channels.originate(endpoint="SIP/1002", app='channel-dump', appArgs='dialed')
except requests.HTTPError:
channel.hangup()
return
当拨号号码接听电话时,他们使用了相同的脚本,因此他们最终再次呼唤自己。一个简单的条件使拨号号码不再次呼叫自身,就是所需的一切