Browse Source

Further cleanups and corrections.

pull/96/head
Trever L. Adams 8 years ago
parent
commit
ca1fa44ca5
  1. 36
      freeswitch_click2dial/freeswitch_click2dial.py
  2. 2
      freeswitch_click2dial/scripts/get_caller_name.py

36
freeswitch_click2dial/freeswitch_click2dial.py

@ -98,7 +98,7 @@ class FreeSWITCHServer(models.Model):
check_str[1].encode('ascii') check_str[1].encode('ascii')
except UnicodeEncodeError: except UnicodeEncodeError:
raise ValidationError( raise ValidationError(
_("The '%s' should only have ASCII caracters for "
_("The '%s' should only have ASCII characters for "
"the FreeSWITCH server '%s'" "the FreeSWITCH server '%s'"
% (check_str[0], server.name))) % (check_str[0], server.name)))
@ -159,7 +159,8 @@ class FreeSWITCHServer(models.Model):
try: try:
if fs_manager.connected() is not 1: if fs_manager.connected() is not 1:
raise UserError( raise UserError(
_("Connection Test Failed! Check Host, Port and Password"))
_("Connection Test Failed! Check Host, Port and "
"Password"))
else: else:
fs_manager.disconnect() fs_manager.disconnect()
except Exception, e: except Exception, e:
@ -173,15 +174,21 @@ class FreeSWITCHServer(models.Model):
user, fs_server, fs_manager = self._connect_to_freeswitch() user, fs_server, fs_manager = self._connect_to_freeswitch()
calling_party_number = False calling_party_number = False
try: try:
is_fq_res = user.resource.rfind('@')
if is_fq_res:
if len(user.resource) != is_fq_res:
is_fq_res = True
else:
is_fq_res = False
request = "channels like /" + re.sub(r'/', r':', user.resource) + \ request = "channels like /" + re.sub(r'/', r':', user.resource) + \
("/" if user.freeswitch_chan_type == "FreeTDM" else "@") + \
" as json"
(("/" if user.freeswitch_chan_type == "FreeTDM" else "@")
if not is_fq_res else "") + " as json"
ret = fs_manager.api('show', str(request)) ret = fs_manager.api('show', str(request))
f = json.load(StringIO.StringIO(ret.getBody())) f = json.load(StringIO.StringIO(ret.getBody()))
if int(f['row_count']) > 0: if int(f['row_count']) > 0:
if (f['rows'][0]['initial_cid_name'] == 'Odoo Connector' or
f['rows'][0]['direction'] == 'inbound'):
calling_party_number = f['rows'][0]['dest']
if (f['rows'][0]['cid_num'] == user.internal_number or
len(f['rows'][0]['cid_num']) < 3):
calling_party_number = f['rows'][0]['dest']
else: else:
calling_party_number = f['rows'][0]['cid_num'] calling_party_number = f['rows'][0]['cid_num']
except Exception, e: except Exception, e:
@ -227,7 +234,8 @@ class ResUsers(models.Model):
"auto answer.") "auto answer.")
callerid = fields.Char( callerid = fields.Char(
string='Caller ID', copy=False, string='Caller ID', copy=False,
help="Caller ID used for the calls initiated by this user.")
help="Caller ID used for the calls initiated by this user. "
"This must be in the form of 'Name <NUMBER>'.")
cdraccount = fields.Char( cdraccount = fields.Char(
string='CDR Account', string='CDR Account',
help="Call Detail Record (CDR) account used for billing this " help="Call Detail Record (CDR) account used for billing this "
@ -362,16 +370,19 @@ class PhoneCommon(models.AbstractModel):
if len(variable): if len(variable):
variable += ',' variable += ','
caller_name = caller_name.replace(",", r"\,") caller_name = caller_name.replace(",", r"\,")
variable += 'effective_caller_id_name=' + caller_name
variable += 'effective_caller_id_name=\'' + caller_name + '\''
if caller_number: if caller_number:
if len(variable): if len(variable):
variable += ',' variable += ','
variable += 'effective_caller_id_number=' + caller_number
variable += 'effective_caller_id_number=\'' + caller_number + '\''
if fs_server.wait_time != 60: if fs_server.wait_time != 60:
if len(variable): if len(variable):
variable += ',' variable += ','
variable += 'ignore_early_media=true' + ',' variable += 'ignore_early_media=true' + ','
variable += 'originate_timeout=' + str(fs_server.wait_time) variable += 'originate_timeout=' + str(fs_server.wait_time)
if len(variable):
variable += ','
variable += 'odoo_connector=true'
channel = '%s/%s' % (user.freeswitch_chan_type, user.resource) channel = '%s/%s' % (user.freeswitch_chan_type, user.resource)
if user.dial_suffix: if user.dial_suffix:
channel += '/%s' % user.dial_suffix channel += '/%s' % user.dial_suffix
@ -381,9 +392,10 @@ class PhoneCommon(models.AbstractModel):
# 'Caller ID name showed to aleg' 90125 # 'Caller ID name showed to aleg' 90125
dial_string = (('<' + variable + '>') if variable else '') + \ dial_string = (('<' + variable + '>') if variable else '') + \
channel + ' ' + fs_number + ' ' + fs_server.context + ' ' + \ channel + ' ' + fs_number + ' ' + fs_server.context + ' ' + \
'\'Odoo Connector\' ' + fs_number
'\'' + self.get_name_from_phone_number(fs_number) + '\' ' + \
fs_number
# raise orm.except_orm(_('Error :'), dial_string) # raise orm.except_orm(_('Error :'), dial_string)
fs_manager.api('originate', dial_string.encode("ascii"))
fs_manager.api('originate', dial_string.encode('utf-8'))
except Exception, e: except Exception, e:
_logger.error( _logger.error(
"Error in the Originate request to FreeSWITCH server %s", "Error in the Originate request to FreeSWITCH server %s",

2
freeswitch_click2dial/scripts/get_caller_name.py

@ -34,6 +34,8 @@
comma (,) delimited, not :_: delimited. It is up to you to format the comma (,) delimited, not :_: delimited. It is up to you to format the
extensions list appropriately. The persons who are at extensions in the extensions list appropriately. The persons who are at extensions in the
notify list will receive a poppup if so configured and if they are logged in. notify list will receive a poppup if so configured and if they are logged in.
The notify list actually shouldn't be in the cidlookup.conf, but should be
used when doing notify (in an on answer hook for example).
From the dialplan, do something like this <action application="set" From the dialplan, do something like this <action application="set"
data="effective_caller_id_name=${cidlookup(${caller_id_number})}"/>. data="effective_caller_id_name=${cidlookup(${caller_id_number})}"/>.

Loading…
Cancel
Save