Beispiel #1
0
def create_subscription(real_number, log_number):
    '''
    crea las suscripciones necesarias para el phone roaming:
    - Both: para el numero real
    - Terminante: para el numero logueado
    - Crea las entradas en la tabla ActiveSubscriptions
    '''
    log.debug('create_subscription')
    try:
        #suscripcion en originante y terminante para el numero real
    
        endpoint = "http://212.179.159.77/nesphase2" 
        reference = ReferenceType(endpoint)
        
    
        interface = "ParlayX"
        
        reference.endpoint = endpoint
        reference.interfaceName = interface
        
    
        criteriaList = []
        criteria = CallEventsType()
        criteriaList.append(criteria.CalledNumber);
        
        monitoredParty = UserIdType()
        #phoneNumber
        monitoredParty.phoneNumber = real_number
        startCallNotificationRequest = StartCallNotificationRequest(reference, monitoredParty)
        startCallNotificationRequest.criteria = criteriaList
        startCallNotificationRequest.addressDirection = "Both"
        startCallNotificationRequest.directionMode = True
        subscription = StartCallNotification(startCallNotificationRequest)
        manager = NESManager()
            
        correlator = manager.save_subscription(subscription)   
      
        # guardar el correlator en la BD
            
        active_subscription = ActiveSubscription(phone_number   = subscription.startCallNotification.monitoredParty.phoneNumber, 
                                                 urlcallback    = subscription.startCallNotification.reference.endpoint,
                                                 subscriptionId = correlator,
                                                 direction      = subscription.startCallNotification.addressDirection)
        active_subscription.save();
        
      
        criteriaList = []
        criteria = CallEventsType()
        criteriaList.append(criteria.CalledNumber);
        
        monitoredParty = UserIdType()
        #phoneNumber
        monitoredParty.phoneNumber = log_number
        startCallNotificationRequest = StartCallNotificationRequest(reference, monitoredParty)
        startCallNotificationRequest.criteria = criteriaList
        startCallNotificationRequest.addressDirection = "Called"
        startCallNotificationRequest.directionMode = True
        subscription = StartCallNotification(startCallNotificationRequest)
        correlator = manager.save_subscription(subscription)
        # guardar el correlator en la BD
        
        active_subscription = ActiveSubscription(phone_number   = subscription.startCallNotification.monitoredParty.phoneNumber, 
                                                 urlcallback    = subscription.startCallNotification.reference.endpoint,
                                                 subscriptionId = correlator,
                                                 direction      = subscription.startCallNotification.addressDirection)
        active_subscription.save();
    except NESException as inst:
        print inst.message
        raise inst
    except Exception as inst:
        print inst.message
        raise inst
Beispiel #2
0
 def handle(self, request):
     '''
     procesa los handlesCallEvent para el phoneRoaming. Actua como servidor
     
         real_number = A
         log_number = B
         if real_number = calledParticipant
             incoming call to real_number
         if real_number = calledParticipant
             incoming call to log_number
         if real_mubner = callingParticipant
             outgoing from real_number
     '''
     log.debug("Inicio handle")
             
     json_data = json.loads(request.raw_post_data)
     log.debug("json_data: " + str(json_data) )
     called =  json_data['callEvent']['calledParticipant']['phoneNumber']
     calling = json_data['callEvent']['callingParticipant']['phoneNumber']
     callSessionID = json_data['callEvent']['callSessionID']
     
     PREFIX = getattr(settings, 'PREFIX')
     #quitamos el prefijo
     calledParticipant= called[called.find(PREFIX)+len(PREFIX):]
     callingParticipant = calling[calling.find(PREFIX)+len(PREFIX):]
     
     
     log.debug('called: ' + called)
     log.debug('calling: ' +  calling)
     log.debug('calledParticipant: ' +  calledParticipant)
     log.debug('callingParticipant: ' +  callingParticipant)
     log.debug('callSessionID: ' +  callSessionID)
     
     
     routingAddress =""
     callingPartyAddress = ""
     
     #Consultar la bd para ver las subscripciones
     try:
         subscription = Subscription.objects.get(real_number=calledParticipant)
         routingAddress = UserIdType()
         routingAddress.phoneNumber = calledParticipant
         callingPartyAddress = UserIdType()
         callingPartyAddress.phoneNumber = u'#'+callingParticipant
     except ObjectDoesNotExist: 
         try:
             subscription = Subscription.objects.get(log_number=calledParticipant)
             routingAddress = UserIdType()
             routingAddress.phoneNumber = subscription.real_number
             callingPartyAddress = UserIdType()
             callingPartyAddress.phoneNumber = callingParticipant
         except ObjectDoesNotExist: 
             try:
                 subscription = Subscription.objects.get(real_number=callingParticipant)
                 routingAddress = UserIdType(calledParticipant)
                 callingPartyAddress = UserIdType(subscription.log_number)
             except ObjectDoesNotExist: 
                 #TODO: tiene que dar una excepcion porque no funciona el handle RAISE NESException
                 print ObjectDoesNotExist
                 nesException = NESException('400', 'Error', 'El numero no existe en la BD')
                 jsonException = JSONException(nesException)
                 return 400,jsonException
             
     '''
     {"action": 
         {"announcementId": "3", 
          "callingPartyAddress": 
                 {"phoneNumber": "0034600222200"}, 
          "errorHandling": true, 
          "legId":"1", 
          "actionToPerform": "OnHold"
         }, 
      "callSessionID":"129916513689383"}
     '''
     log.debug("routingAddress.phoneNumber "+ routingAddress.phoneNumber)
     log.debug("callingPartyAddress.phoneNumber "+ callingPartyAddress.phoneNumber)
     
     transactionId = "0123456789" #TODO cambiar por algo que no sea fijo
     action_type = ActionType("Route", transactionId)
     action_type.legId="2"
     action_type.routingAddress = routingAddress
     action_type.callingPartyAddress = callingPartyAddress
     action = HandleCallEventResponse(action_type)
     action.callSessionID = callSessionID
     return 200, action