Commit 8acb208f authored by okhin's avatar okhin 🚴

Fixing some stupid syntaxes

parent 191b11fc
......@@ -15,7 +15,7 @@ def ari_call(config, verbs, method, payload):
if method.lower() == 'del':
call = requests.delete
else:
call = getattrs(requests, method.lower())
call = getattr(requests, method.lower())
payload['app'] = config['app']
payload['api_key'] = config['key'] + ':' + config['password']
result = call(full_url, data=payload)
......@@ -68,7 +68,6 @@ class Bridge(object):
return ari_call(self.config, ['bridges', self.name, 'addChannel'], 'POST', {'channel': channel})
except:
raise
class Channel(object):
'''
This class is used to regroup all the method to manage a Channel
......
[webservice]
base_url = ws://185.34.33.12:8088/ari/events
base_url = ws://pi3.lqdn.fr:8088/ari/events
[asterisk]
protocol = http
......
......@@ -151,14 +151,14 @@ async def hold_bridge():
It will play a song in a loop.
'''
try:
bridge = ari.Bridge(self.config['asterisk'], self.config['moh']['name'], 'holding')
bridge = ari.Bridge(config['asterisk'], config['moh']['name'], 'holding')
except Exception as e:
phone_logger.critical("No Music On Hold (moh) section in config file. Exiting")
phone_logger.Exception(e)
phone_logger.exception(e)
raise e
try:
result = bridge.create()
result = bridge.startMoh(self.config['moh']['class'])
result = bridge.startMoh(config['moh']['class'])
except Exception as e:
phone_logger.error("Cannot start 'on hold' bridge")
phone_logger.exception(e)
......@@ -174,7 +174,7 @@ async def listen():
ws = await websockets.connect(config['webservice']['base_url'] + '?app={}&api_key={}:{}'.format(
config['asterisk']['app'], config['asterisk']['key'], config['asterisk']['password']))
ws_logger.debug('Websocket connected: {}'.format(type(ws)))
await hold_bridges()
await hold_bridge()
while running == True:
try:
event = await ws.recv()
......@@ -279,16 +279,16 @@ class Call(object):
# But first we should stop the playback
phone_logger.debug('Stopping the playback currently running')
# We're stoping the playback, with the same ID as the channel, to keep track of it
playback = ari.Playback(self.config['asterisk'], event['channel']['id'], 'sound:mario')
playback = ari.Playback(config['asterisk'], event['channel']['id'], 'sound:mario')
playback.stop()
# Now we're moving the channel to the MOH Bridge
phone_logger.debug('Moving call {} to the garage'.format(event['channel']['id']))
moh_bridge = ari.Bridge(self.config['asterisk'], self.config['moh']['name'])
moh_bridge = ari.Bridge(config['asterisk'], config['moh']['name'])
moh_bridge.addChannel(event['channel']['id'])
# Next we need to originate a call to the other side
phone_logger.info('Will now connect {} to {}'.format(self.caller, self.callee,))
endpoint = 'SIP/' + sanitize_phonenumber(self.callee) + '@' + config['asterisk']['sip-context']
channel = ari.Channel(self.config['asterisk'], self.id + '-' + sanitize_phonenumber(self.callee))
channel = ari.Channel(config['asterisk'], self.id + '-' + sanitize_phonenumber(self.callee))
channel.originate(endpoint)
except AssertionError as e:
logging.error("Received a DTMF sequence out le being in a '{}' state, ignoring: {}".format(self.state(), event['digit']))
......@@ -304,7 +304,7 @@ class Call(object):
# Are we the caller orthe callee?
if event['channel']['id'].endswith(self.callee):
# Step 1 create a bridge
bridge = ari.Bridge(self.config['asterisk'], self.id, 'mixing')
bridge = ari.Bridge(config['asterisk'], self.id, 'mixing')
phone_logger.debug("Creating a bridges to connect {} to {}".format(self.caller, self.callee,))
bridge.create()
# Step 2, moving channels
......@@ -315,10 +315,10 @@ class Call(object):
return
# Call is being picked up, we want to play a song
try:
channel = ari.Channel(self.config['asterisk'], event['channel']['id'])
channel = ari.Channel(config['asterisk'], event['channel']['id'])
logging.debug('Preparing to create a playback')
# We're starting a playback, with the same ID as the channel, to keep track of it
channel.playback(channel.name, self.config['asterisk']['playback'])
channel.playback(channel.name, config['asterisk']['playback'])
except Exception as e:
logging.exception(e)
raise e
......@@ -332,7 +332,7 @@ class Call(object):
'''
self.update((':'.join([event['type'], event['channel']['id'].split('-')[-1]]), event['timestamp'],))
# We want to check if the moh bridge is opened
moh_bridge = ari.Bridge(self.config['asterisk'], self.config['moh']['name'], 'holding')
moh_bridge = ari.Bridge(config['asterisk'], config['moh']['name'], 'holding')
try:
moh_bridge.status()
except HTTPError as e:
......@@ -342,8 +342,8 @@ class Call(object):
# Now, let's create the channel
try:
endpoint = 'SIP/' + sanitize_phonenumber(self.caller) + '@' + self.config['asterisk']['sip-context']
channel = ari.Channel(self.config['asterisk'], self.id + '-' + sanitize_phonenumber(self.caller))
endpoint = 'SIP/' + sanitize_phonenumber(self.caller) + '@' + config['asterisk']['sip-context']
channel = ari.Channel(config['asterisk'], self.id + '-' + sanitize_phonenumber(self.caller))
channel.originate()
except Exception as e:
logging.exception(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment