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