def check_in_guest(self,guest,partySize=None,waitEstimate=None): cur_user = current_user() if not waitEstimate: # Wait estimate isn't defined (likely coming from guest sign-in), use default waitEstimate=cur_user.default_wait if waitEstimate == 0: # Currently no wait, don't put them in the queue inQueue = False else: inQueue = True # See if guest is already in queue, if so overwrite checkin = CheckIn.query(CheckIn.guest_key==guest.key, CheckIn.restaurant_key==cur_user.key, CheckIn.in_queue==inQueue).get() if checkin: # Guest is in queue already, update checkin.last_name=guest.last_name checkin.first_name=guest.first_name checkin.signin_time=datetime.now() checkin.wait_estimate=waitEstimate if partySize: checkin.party_size=partySize else: # Guest is not in queue, create checkin if not partySize: partySize = 2 checkin = CheckIn(guest_key=guest.key, restaurant_key=cur_user.key, first_name=guest.first_name, last_name=guest.last_name, in_queue=inQueue, party_size=partySize, signin_time=datetime.now(), wait_estimate=waitEstimate) checkin.put() return checkin
def add_guest(self,firstName,lastName,smsNumber,email,preferredContact,optIn,signup_method,user=None): if not user: user = current_user() # Check to see if guest is already in datastore if not smsNumber and not email: # If both are blank there's no way to know the name matches any other instance of the name, so create a new guest. guest = None elif preferredContact == 'sms': guest = Guest.query(Guest.sms_number==smsNumber,Guest.restaurant_key==user.key).get() elif preferredContact == 'email': guest = Guest.query(Guest.email==email,Guest.restaurant_key==user.key).get() else: guest = None if guest: # Guest is in datastore, update in case info has changed guest.first_name = firstName guest.last_name = lastName guest.preferred_contact = preferredContact if not optIn: # If they've opted in previously and they didn't check now, leave opted in guest.opt_in = optIn else: # Guest is not in datastore, create new Guest guest = Guest(first_name=firstName, last_name=lastName, sms_number = smsNumber, email=email, preferred_contact=preferredContact, opt_in=optIn, signup_method=signup_method, restaurant_key=user.key) guest.put() return guest
def send_promo(cls,guest_ID,msgTemplate): cur_user = current_user() guest = Guest.get_by_id(int(guest_ID)) # Create Message Object msg = Message(restaurant_key = cur_user.key, recipient_key = guest.key, contact_method = guest.preferred_contact, time_initiated = datetime.now(), message_template_key=msgTemplate.key) # Create msg_text from msgTemplate.message_text msg_text = msgTemplate.message_text if guest.first_name: msg_text = msg_text.replace('{firstName}',guest.first_name) if guest.last_name: msg_text = msg_text.replace('{lastName}',guest.last_name) # Send Message logging.info("Attempting to send promo to %s..." % str(guest.first_name) + ' ' + str(guest.last_name)) if msg.send_message(guest,msg_text): msg.send_success = True else: msg.send_success = False # Store Message msg.put() # Return success return msg.send_success
def send_notification(cls,guest_ID,msg_text=False): cur_user = current_user() guest = Guest.get_by_id(int(guest_ID)) # Create Message Object msg = Message(restaurant_key = cur_user.key, recipient_key = guest.key, contact_method = guest.preferred_contact, time_initiated = datetime.now()) # If a default notification, populate msg_text and store MessageTemplate Key if not msg_text: msgTemplate = MessageTemplate.query(MessageTemplate.restaurant_key==cur_user.key,MessageTemplate.message_type==1,MessageTemplate.is_active==True).get() if not msgTemplate: # No template exists (new user), create one msgTemplate = MessageTemplate(restaurant_key=cur_user.key,message_type=1,is_active=True,message_text="{firstName}, your table is almost ready. Need more time? Reply ""bump"" and the # of minutes you'd like.") msgTemplate.put() msg.message_template_key = msgTemplate.key msg_text = msgTemplate.message_text if guest.first_name: msg_text = msg_text.replace('{firstName}',guest.first_name) if guest.last_name: msg_text = msg_text.replace('{lastName}',guest.last_name) # Send Message logging.info("Attempting to send notification to %s..." % str(guest.first_name) + ' ' + str(guest.last_name)) if msg.send_message(guest,msg_text): msg.send_success = True else: msg.send_success = False # Store Message msg.put() # Return success return msg.send_success
def update(self,message_text): cur_user = current_user() if self.message_text != message_text: # User has update message text, archive old and create new self.is_active = False self.put() msgTemplate = MessageTemplate(restaurant_key=cur_user.key,message_type=int(self.message_type),is_active=True,message_text=message_text) msgTemplate.put() return True
def send_message(self,guest,msg_text): cur_user = current_user() if cur_user.is_demo: msg = msg_text + " -- SENT BY BUMP DEMO: http://bumpapp.co" else: msg = msg_text if self.contact_method == 'sms': if cur_user.gv_email and cur_user.gv_password: gv_email = cur_user.gv_email else: gv_email = '*****@*****.**' if cur_user.gv_email and cur_user.gv_password: gv_password = cur_user.gv_password else: gv_password = '******' voice = Voice() voice.login(gv_email,gv_password) phoneNumber = guest.sms_number text = msg logging.info("Sending SMS to %s using %s" % (str(phoneNumber), str(gv_email))) voice.send_sms(phoneNumber, text) elif self.contact_method == 'email': if cur_user.reply_to_email: # User provided a reply-to email different from their account email. Emails must be sent out by the account, so a reply-to email is used. reply_to = cur_user.reply_to_email sender_email = cur_user.email else: if cur_user.is_demo: # Demo mode is not a real account, so it must be sent from [email protected] reply_to = cur_user.reply_to_email sender_email = "*****@*****.**" else: sender_email = cur_user.email reply_to = cur_user.email logging.info("Sending email to %s from %s" % (str(guest.email), str(sender_email))) mail.send_mail( sender=cur_user.name + " <" + sender_email + ">", reply_to=reply_to, to=guest.email, subject="Message from %s" % cur_user.name, body=msg_text) return True #def check_in_guest(self,guest,partySize=None,waitEstimate=None): # cur_user = current_user() # if not waitEstimate: # # Wait estimate isn't defined (likely coming from guest sign-in), use default # waitEstimate=cur_user.default_wait # if waitEstimate == 0: # # Currently no wait, don't put them in the queue # inQueue = False # else: # inQueue = True # # See if guest is already in queue, if so overwrite # checkin = CheckIn.query(CheckIn.guest_key==guest.key, CheckIn.restaurant_key==cur_user.key, CheckIn.in_queue==inQueue).get() # if checkin: # # Guest is in queue already, update # checkin.last_name=guest.last_name # checkin.first_name=guest.first_name # checkin.signin_time=datetime.now() # checkin.wait_estimate=waitEstimate # if partySize: # checkin.party_size=partySize # else: # # Guest is not in queue, create checkin # if not partySize: # partySize = 2 # checkin = CheckIn(guest_key=guest.key, restaurant_key=cur_user.key, first_name=guest.first_name, last_name=guest.last_name, in_queue=inQueue, party_size=partySize, signin_time=datetime.now(), wait_estimate=waitEstimate) # checkin.put() # return checkin