From ca1fa44ca5b1fa835056e2d671c57b82277c0209 Mon Sep 17 00:00:00 2001 From: "Trever L. Adams" Date: Fri, 19 Aug 2016 15:18:38 -0600 Subject: [PATCH] Further cleanups and corrections. --- .../freeswitch_click2dial.py | 36 ++++++++++++------- .../scripts/get_caller_name.py | 2 ++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/freeswitch_click2dial/freeswitch_click2dial.py b/freeswitch_click2dial/freeswitch_click2dial.py index d3ab48a..cebd744 100644 --- a/freeswitch_click2dial/freeswitch_click2dial.py +++ b/freeswitch_click2dial/freeswitch_click2dial.py @@ -98,7 +98,7 @@ class FreeSWITCHServer(models.Model): check_str[1].encode('ascii') except UnicodeEncodeError: raise ValidationError( - _("The '%s' should only have ASCII caracters for " + _("The '%s' should only have ASCII characters for " "the FreeSWITCH server '%s'" % (check_str[0], server.name))) @@ -159,7 +159,8 @@ class FreeSWITCHServer(models.Model): try: if fs_manager.connected() is not 1: raise UserError( - _("Connection Test Failed! Check Host, Port and Password")) + _("Connection Test Failed! Check Host, Port and " + "Password")) else: fs_manager.disconnect() except Exception, e: @@ -173,15 +174,21 @@ class FreeSWITCHServer(models.Model): user, fs_server, fs_manager = self._connect_to_freeswitch() calling_party_number = False 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) + \ - ("/" 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)) f = json.load(StringIO.StringIO(ret.getBody())) 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: calling_party_number = f['rows'][0]['cid_num'] except Exception, e: @@ -227,7 +234,8 @@ class ResUsers(models.Model): "auto answer.") callerid = fields.Char( 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 '.") cdraccount = fields.Char( string='CDR Account', help="Call Detail Record (CDR) account used for billing this " @@ -362,16 +370,19 @@ class PhoneCommon(models.AbstractModel): if len(variable): variable += ',' caller_name = caller_name.replace(",", r"\,") - variable += 'effective_caller_id_name=' + caller_name + variable += 'effective_caller_id_name=\'' + caller_name + '\'' if caller_number: if len(variable): variable += ',' - variable += 'effective_caller_id_number=' + caller_number + variable += 'effective_caller_id_number=\'' + caller_number + '\'' if fs_server.wait_time != 60: if len(variable): variable += ',' variable += 'ignore_early_media=true' + ',' 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) if user.dial_suffix: channel += '/%s' % user.dial_suffix @@ -381,9 +392,10 @@ class PhoneCommon(models.AbstractModel): # 'Caller ID name showed to aleg' 90125 dial_string = (('<' + variable + '>') if variable else '') + \ 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) - fs_manager.api('originate', dial_string.encode("ascii")) + fs_manager.api('originate', dial_string.encode('utf-8')) except Exception, e: _logger.error( "Error in the Originate request to FreeSWITCH server %s", diff --git a/freeswitch_click2dial/scripts/get_caller_name.py b/freeswitch_click2dial/scripts/get_caller_name.py index 3e86eec..aee7325 100644 --- a/freeswitch_click2dial/scripts/get_caller_name.py +++ b/freeswitch_click2dial/scripts/get_caller_name.py @@ -34,6 +34,8 @@ comma (,) delimited, not :_: delimited. It is up to you to format 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. + 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 .