def encode(self, incoming_msg, **kwargs): answer, cmd = incoming_msg.process() if answer and cmd: if cmd.command.account.customer.user_ptr == incoming_msg.access.account_set.all()[0].customer.user_ptr: id = Message.create_one(answer, incoming_msg.mobile, datetime.datetime.now(), cmd.command.account) if id < 0: log.error("Error while trying to create a msg response: info = %s", kwargs) else: log.debug("Response mesage %s to %s: %s", id, incoming_msg.mobile[1:], answer) else: log.error("% user cannot receive msgs from %s access", cmd.command.account.customer.user_ptr, incoming_msg.access) else: log.error(cmd)
def send_sms(username, password, account, phoneNumber, text, activationDate = None): """ Send a text msg to a phone over an account given """ try: account = Customer.check_customer_and_credit(username, password, account) except OutOfCredit: return ACCOUNT_NO_CREDIT if account < 0: return account if not activationDate: activationDate = datetime.datetime.now() phoneNumber = check_mobile(phoneNumber) if phoneNumber < 0: return phoneNumber return Message.create_one(text, phoneNumber, activationDate, account)
def send_sms_many(username, password, account, phoneList, text, activationDate = None): """ Send a text msg to a many phones over an account given """ try: account = Customer.check_customer_and_credit (username, password, account, len(phoneList)) except OutOfCredit: return [ACCOUNT_NO_CREDIT] if account < 0: return [account] activationDate = datetime.datetime.now () idlist = [] for phone in phoneList: if check_mobile(phone) < 0: return [-50] # FIXME: cambiar esto por MobileErrorException cuando se implemente for phone in phoneList: phone = phone.strip() idlist.append(Message.create_one (text, phone, activationDate, account)) return idlist
def doInfo(self, mobile, *args): body_id = self.command.defaultAnswer.id # Channel means body_id. Would be wise to change it. Message.create_one('', mobile, datetime.datetime.now(), self.command.account, body_id=body_id) # create_one doesnt return any values. return _("INFO %s") % self.channel.name
def test_put_in_the_queue (self): self.assertEqual(0, SMSQueue.objects.all().count()) id = Message.create_one (self.text, self.phoneNumber, self.now, self.OKaccount) m = Message.objects.get (id = id) m.put_in_the_queue () self.assertEqual (1, SMSQueue.objects.all().count())
def test_create_one_ok (self): Message.create_one (self.text, self.phoneNumber, self.now, self.OKaccount) self.assertEqual (3, Message.objects.all().count())