def create_message_without_batch(self, id, backend): fake_connection = Connection(identity=str(id)) fake_connection.backend, created = Backend.objects.get_or_create(name=backend) fake_connection.save() message = Message(status='Q', direction="O") message.text = "this is an important message" message.connection = fake_connection message.batch = None message.save() return message
def create_message(self, id, backend, batch=None): fake_connection = Connection(identity=str(id)) fake_connection.backend, created = Backend.objects.get_or_create(name=backend) fake_connection.save() message = Message(status='Q', direction="O") message.connection = fake_connection message.batch = self.batch1 if batch is None else batch message.save() return message
def handle (self, message): escargot = 'mrs_autoreg' match = None matched = None for keywd in settings.KEYWORDS_AND_SLUGS: match = re.match(keywd, message.text, re.IGNORECASE) if match: escargot = settings.KEYWORDS_AND_SLUGS[keywd] matched = message.text[len(match.group(0)):] #message.text = matched break if escargot == 'mrs_opt_out': if not message.connection.contact: # Stop sending you nothing? :-p return False sps = ScriptProgress.objects.filter(connection = message.connection) sps.delete() sps = ScriptSession.objects.filter(connection = message.connection) sps.delete() message.connection.contact.interested = False message.connection.contact.save() # ScriptProgress.objects.create( # script = Script.objects.get(slug = escargot), # connection = message.connection) msg = Message(connection = message.connection, status = 'Q', direction = 'O', text = 'You will no longer receive FREE messages from Mother Reminder. If you want to join again please send JOIN to 6400.') msg.save() return False if (not message.connection.contact) or (not ScriptProgress.objects.filter(connection = message.connection)): # if match: if True: # Any word goes for registration. message.connection.contact = Contact.objects.create(name='Anonymous User') message.connection.contact.interested = True message.connection.contact.last_menses = datetime.now() - timedelta(days = 45) message.connection.contact.save() message.connection.save() ScriptProgress.objects.create( script = Script.objects.get(slug = escargot), connection = message.connection) else: msg = Message(connection = message.connection, status = 'Q', direction = 'O', text = "You just contacted Mother Reminder. Did you know that pregnant women should go to the health clinic 4 times during preganancy? Stay Healthy!") msg.save() return False else: if ScriptProgress.objects.filter(connection = message.connection): return False if match and escargot == 'mrs_autoreg': msg = Message(connection = message.connection, status = 'Q', direction = 'O', text = "You just contacted Mother Reminder. Did you know that pregnant women should go to the health clinic 4 times during preganancy? Stay Healthy!") msg.save() else: msg = Message(connection = message.connection, status = 'Q', direction = 'O', text = "You just contacted Mother Reminder. Did you know that pregnant women should go to the health clinic 4 times during preganancy? Stay Healthy!") msg.save() return False
def handle(self, **options): text = options.get('text') or 'If you want to stop receiving FREE messages from Mother Reminder please reply with STOP.' outmsgs = ReminderMessage.as_hash().keys() outmsgs.sort() try: lastweek = outmsgs[-1] query = Contact.objects.filter(interested = True).exclude(connection = None) if not options.get('all'): query.filter(last_menses__lt = (datetime.now() - timedelta(weeks=lastweek))) for mother in query: last_optout = Message.objects.filter(connection=mother.default_connection).filter(text=text).order_by('-date') message = Message(connection = mother.default_connection, direction = 'O', status = 'Q', text = text) if not last_optout: message.save() else: if last_optout[0].date + timedelta(weeks=8) <= datetime.now(): message.save() # msg.save() # application, batch, connection, date, direction, flags, id, in_response_to, poll, poll_responses, priority, responses, status, submissions, text except IndexError: pass