示例#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 _sendXMPPMessage(self, message, fromContact=None, fromNumber=None):
        if not fromContact:
            fromContact = Contact.getDefaultSender()

        # Add the fromNumber to the message if this is from the default sender.
        if fromContact.isDefaultSender() and fromNumber:
            message = toPrettyNumber(fromNumber) + ": " + message

        logging.debug("Sending XMPP message to " + self._owner.jid + ": " + message)

        fromJid = fromContact.name + "@" + self._APP_ID + ".appspotchat.com"
        return self._communications.sendXmppMessage(fromJid, self._owner.jid, message)
示例#4
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)