示例#1
0
    def post(self):
        user = json.loads(self.request.body)

        if not phonenumberutils.validateNumber(user['phoneNumber']):
            raise errors.ValidationError("Invalid phone number.")
            #return validationError(self.response, 'Invalid number ' + user['phoneNumber'])
        
        if not user['name']:
            raise errors.ValidationError("Name is required.")
        
        # Make sure we're not duplicating another contact
        existingContact = Contact.getByName(user['name'])
        if existingContact:
            raise errors.ValidationError('User already exists with name ' + user['name'])
        
        existingContact = Contact.getByPhoneNumber(user['phoneNumber'])
        if existingContact:
            raise errors.ValidationError('User ' + existingContact.name +
              ' already exists with number ' + existingContact.phoneNumber)


        logging.info("Creating contact " + user["name"])
        contact = Contact(
            name = user['name'].lower(),
            phoneNumber = phonenumberutils.toPrettyNumber(user['phoneNumber']),
            normalizedPhoneNumber = phonenumberutils.toNormalizedNumber(user['phoneNumber']))

        Contact.update(contact)

        xmppVoiceMail.sendXmppInvite(contact.name)

        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(contact.toDict()))
示例#2
0
 def getDisplayNameAndContact(self, number):
     displayName = toPrettyNumber(number)
     
     # Find the XMPP user to send this from
     contact = Contact.getByPhoneNumber(number)
     if contact:
         displayName = contact.name
     else:
         contact = Contact.getDefaultSender()
         
     return (displayName, contact)
示例#3
0
 def handleIncomingCall(self, fromNumber, callStatus):
     """Handle an incoming call.
     """
     displayFrom = toPrettyNumber(fromNumber)
     
     # Find the XMPP user to send this from
     contact = Contact.getByPhoneNumber(fromNumber)
     if contact:
         displayFrom = contact.name
     else:
         contact = Contact.getDefaultSender()
         
     self.sendMessageToOwner("Call from: " + displayFrom + " status:" + callStatus, contact, fromNumber)