Пример #1
0
 def get_project_info(self):
     '''获取业务信息
     '''
     info = _backends.service_get_project(self.project_id)
     self.max_calling = int(info.get('max_calling', 0))
     self.ratio = int(info.get('ratio', 0))
     self.status = info.get('status', None)
Пример #2
0
    def generate_inbound(self):
        username = self.get_variables('user_name')
        domain_name = self.get_variables('domain_name')
        self.user_name = '{0}@{1}'.format(username, domain_name)
        self.user = _backends.service_get_userid(self.user_name)
        print(self.user_name, self.user)

        if self.answer_time:
            self.status = 1
            self.recording = self.get_unquote('recording')
            diff = (self.end_time - self.answer_time).seconds
            self.callsec = diff if diff else 1
Пример #3
0
 def get_datum_result(self):
     '''获取项目资料
     '''
     mobile_id, mobile = _backends.service_extract_datum(self.project_id)
     if mobile_id and mobile:
         datum = DatumResult.objects.create(company_id=self.company_id,
                                            project_id=self.project_id,
                                            datum_id=mobile_id,
                                            phone=mobile)
         self.diff_project_datum()
         return datum
     return None
Пример #4
0
 def get_extract_mobile(self, nums):
     '''提取号码
     '''
     res = set()
     for ind in range(nums):
         mobile_id, mobile = _backends.service_extract_datum(
             self.project_id)
         if mobile_id and mobile:
             res.add((mobile_id, mobile))
         else:
             print('无号码')
             break
     return res
Пример #5
0
 def update(self, request, pk, *args, **kwargs):
     mobile = request.data.get('mobile', None)
     phoneId = request.data.get('phoneId', None)
     if not mobile or not phoneId:
         raise exceptions.NotAcceptable(detail='请求不被允许')
     ins = _backends.service_get_project(pk)
     handle = utils.Utils()
     if not ins:
         return Response({'msg': '项目不存在', 'ok': False})
     queue_name = '{0}_{1}'.format(ins.get('domain'), ins.get('id'))
     res, result = handle.originate_queue_test(mobile,
                                               queue_name,
                                               domain=ins.get('domain'),
                                               phoneId=phoneId)
     return Response({'data': res, 'ok': result})
Пример #6
0
 def generate_outbound(self):
     self.queue_name = self.get_variables('cc_queue')
     if self.queue_name:
         self.status = 3
         self.user_name = self.get_unquote('cc_agent')
         if self.user_name:
             self.sign_out(self.user_name)
             self.user = _backends.service_get_userid(self.user_name)
             self.recording = self.get_unquote('cc_record_filename')
             self.status = 1
             self.callsec = 1
             if self.bridge_time:
                 diff = (self.end_time - self.bridge_time).seconds
                 self.callsec = diff if diff else 1
         if self.check_end():
             self.unload_queue(self.queue_name)
Пример #7
0
 def get_xml_data(self):
     name = self.request.data.get('CC-Queue', None)
     if name:
         if _backends.service_get_queue(name):
             return name
     return None
Пример #8
0
 def get_xml_data(self):
     return _backends.service_get_directory(self.username)
Пример #9
0
 def compute_out_nums(self):
     '''计算外呼数量
     '''
     return _backends.service_compute_nums(self.project_id,
                                           callmax=self.max_calling,
                                           ratio=self.ratio)
Пример #10
0
 def get_sys_gateway(self):
     '''获取网关信息
     '''
     gw = _backends.service_get_gateway_name(self.domain)
     self.gateway = gw or fs_settings.DEFAULT_GATEWAY_NAME
Пример #11
0
    def get_xml_data(self):
        '''
        context: 企业域名
        direction: 呼叫方向
            inbound. 呼出
            outbound: 呼入
        dest: 被叫号码

        header
        '''
        context = self.request.data.get('Caller-Context', None)
        if context == 'default':
            return self.hangup(context)
        direction = self.request.data.get('Call-Direction', None)
        dest = self.request.data.get('Caller-Destination-Number', None)

        proId = self.request.data.get('variable_sip_h_X-Proid', None)
        # mobile_id = self.request.data.get('variable_sip_h_X-Phoneid', None)

        caller = context
        if direction == 'inbound':
            domain = self.request.data.get('variable_domain_name', None)
            if domain != context:
                return self.hangup(context)
            gateway = _backends.service_get_gateway_name(context)  # 获取企业配置网关
            if not gateway:
                gateway = fs_settings.DEFAULT_GATEWAY_NAME
            if proId:
                # mobile_id, mobile = _backends.service_extract_datum(proId)  # 获取真实被叫
                caller = '{0}_{1}'.format(context, proId)  # 设置主叫为 域名 + 业务id
            # if not mobile_id or not mobile:
            #     return self.hangup(context)
            return [
                ('sys_inbound', False,
                 [('destination_number', '^(.*)$', False, [
                     ('set', 'RECORD_STEREO=true', False),
                     ('set', 'RECORD_ANSWER_REQ=true', False),
                     ('set', 'media_bug_answer_req=true', False),
                     ('set', 'recording={0}'.format(self.record_path), False),
                     ('set', 'execute_on_answer1=record_session ${recording}',
                      False),
                     ('set', 'effective_caller_id_number={0}'.format(caller),
                      False),
                     ('bridge', 'sofia/gateway/{0}/{1}'.format(gateway,
                                                               dest), False),
                 ])]),
            ]
        elif direction == 'outbound':
            if self.request.data.get('Channel-Call-State', 'EARLY') != 'EARLY':
                return [('sys_callcenter', False,
                         [('destination_number', '^(.*)$', False, [
                             ('callcenter', '${destination_number}', False),
                         ])])]
            if not _backends.get_service_queue(dest):
                return self.hangup(context)
            return [('sys_callcenter', False, [
                ('destination_number', '^(.*)$', False, [
                    ('set',
                     'execute_on_answer1=Transfer ${destination_number} XML %s'
                     % context, False),
                    ('set', 'park_timeout=30', False),
                    ('park', '', False),
                ]),
            ])]
        return self.hangup()
Пример #12
0
 def update(self, request, pk, *args, **kwargs):
     ins = _backends.service_get_project(pk)
     if not ins:
         return Response({'msg': '项目不存在', 'ok': False})
     fs_thread.stop_queue_thread(ins.get('domain'), ins.get('id'))
     return Response({'data': None, 'ok': True})
Пример #13
0
 def get_xml_data(self):
     return _backends.service_get_gateway()