def create_notification_records(self, invite_attendee): records = [] if invite_attendee.phone: attendee_sms_notification = InviteAttendeeNotification( unique_id=guid(), invite=self.invite.key, attendee=invite_attendee.key, channel=invite_attendee.phone, channel_type='sms', notified_on=datetime.datetime.now() ) attendee_voice_notification = InviteAttendeeNotification( unique_id=guid(), invite=self.invite.key, attendee=invite_attendee.key, channel=invite_attendee.phone, channel_type='phone', notified_on=datetime.datetime.now() ) records.append(attendee_sms_notification) records.append(attendee_voice_notification) if invite_attendee.email: attendee_email_notification = InviteAttendeeNotification( unique_id=guid(), invite=self.invite.key, attendee=invite_attendee.key, channel=invite_attendee.email, channel_type='email', notified_on=datetime.datetime.now() ) records.append(attendee_email_notification) return records
def execute(self): invite_attendee = None if self.invite_attendee_id: invite_attendee = InviteAttendee.get_by_unique_id( self.invite_attendee_id) else: invite_attendee = InviteAttendee(unique_id=guid()) invite_attendee.name = self.name invite_attendee.email = self.email invite_attendee.phone = self.phone contact = None if self.user and self.unique_id: contact = Contact.get_by_unique_id(self.unique_id) elif self.user: contact = Contact(unique_id=guid(), user=self.user) # Here we update the contact with the appropiate Data if contact: invite_attendee.contact = contact.key contact.name = self.name contact.email = self.email contact.phone = self.phone contact.put() invite = Invite.get_by_unique_id(self.invite_id) invite_attendee.invite = invite.key invite_attendee.put() return invite_attendee.unique_id
def execute(self): invite_attendee = None invite_attendee = InviteAttendee( unique_id=guid() ) invite_attendee.name = self.name invite_attendee.email = self.email if self.status: invite_attendee.attendee_status = self.status invite_attendee.phone = self.phone if self.contact_unique_id: contact = Contact.get_by_unique_id( self.contact_unique_id ) if contact: invite_attendee.contact = contact.key if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite_attendee.invite = self.invite.key invite_attendee.is_organizer = self.is_organizer if self.user: UpdateUserOnAttendeesCommand.update_user_on_attendee(self.user, invite_attendee) elif invite_attendee.email: # We can only correlate by email now user = self.user_from_email(invite_attendee.email) if user: UpdateUserOnAttendeesCommand.update_user_on_attendee(user, invite_attendee) invite_attendee.put() return invite_attendee.unique_id
def create_event_group(cls, unique_object_id): group_id = EventQueue.get_group_id(unique_object_id) if group_id: return group_id group = EventGroup(unique_id=guid(), grouper_unique_id=unique_object_id) group.put_async() return group.unique_id
def create_event_group(cls, unique_object_id): group_id = EventQueue.get_group_id(unique_object_id) if group_id: return group_id group = EventGroup( unique_id=guid(), grouper_unique_id=unique_object_id ) group.put_async() return group.unique_id
def execute(self): invite_attendee = None if self.invite_attendee_id: invite_attendee = InviteAttendee.get_by_unique_id(self.invite_attendee_id) else: invite_attendee = InviteAttendee( unique_id=guid() ) invite_attendee.name = self.name invite_attendee.email = self.email invite_attendee.phone = self.phone contact = None if self.user and self.unique_id: contact = Contact.get_by_unique_id( self.unique_id ) elif self.user: contact = Contact( unique_id=guid(), user=self.user ) # Here we update the contact with the appropiate Data if contact: invite_attendee.contact = contact.key contact.name = self.name contact.email = self.email contact.phone = self.phone contact.put() invite = Invite.get_by_unique_id(self.invite_id) invite_attendee.invite = invite.key invite_attendee.put() return invite_attendee.unique_id
def __init__(self, *args, **kwargs): unique_id = None if 'unique_id' in kwargs: unique_id = kwargs.pop('unique_id') if 'id' in kwargs: unique_id = kwargs.pop('id') if not unique_id: unique_id = guid() kwargs['id'] = unique_id super(UniqueIDModel, self).__init__(*args, **kwargs)
def execute(self): """Push the invite send to the async queue""" invite_query = ReducedInviteQuery(invite=self.invite) invite_query_dict = invite_query.query() #Normalizing the context invite_query_dict['invite_unique_id'] = self.invite.unique_id invite_query_dict['uniquecall_id'] = guid() group_id = EventQueue.create_event_group(self.invite.unique_id) EventQueue.push_event(endpoint=config.get('api_url'), headers=get_voiceflows_headers(), payload=invite_query_dict, group_id=group_id, priority=0)
def execute(self): contact = None if self.unique_id: contact = Contact.get_by_unique_id(self.unique_id) else: contact = Contact(unique_id=guid()) contact.user = self.user contact.name = self.name contact.phone = self.phone contact.email = self.email contact.put() return contact.unique_id
def execute(self): """Push the invite send to the async queue""" invite_query = ReducedInviteQuery(invite=self.invite) invite_query_dict = invite_query.query() #Normalizing the context invite_query_dict['invite_unique_id'] = self.invite.unique_id invite_query_dict['uniquecall_id'] = guid() group_id = EventQueue.create_event_group(self.invite.unique_id) EventQueue.push_event( endpoint=config.get('api_url'), headers=get_voiceflows_headers(), payload=invite_query_dict, group_id=group_id, priority=0 )
def execute(self): contact = None if self.unique_id: contact = Contact.get_by_unique_id(self.unique_id) else: contact = Contact( unique_id=guid() ) contact.user = self.user contact.name = self.name contact.phone = self.phone contact.email = self.email contact.put() return contact.unique_id
def push_event(cls, endpoint, payload=None, method='POST', headers=None, priority=0, group_id=None): """ Will push an event to the event queue. endpoint: URL to call while executing the event payload: Dictionary of GET params or body JSON method: GET|POST headers: Headers while executing the request priority: Will be used to block events while lower priorities events have failed. An event will only execute if it' the next top priority on that group group_id: Grouping of events, if None, an event will have it's own unique group """ if not payload: payload = {} if not group_id: group_id = guid() event = Event() event.created = datetime.datetime.now() event.headers = json.dumps(headers) or '' event.method = method event.payload = json.dumps(payload) event.endpoint = endpoint event.status = EventStatus.CREATED event.priority = priority event.group_id = group_id event.put() q = taskqueue.Queue(QUEUE_NAME) q.add([taskqueue.Task( name=cls._get_cutie_task_name(event.unique_id), payload=event.unique_id, method='PULL' )])
def push_event(cls, endpoint, payload=None, method='POST', headers=None, priority=0, group_id=None): """ Will push an event to the event queue. endpoint: URL to call while executing the event payload: Dictionary of GET params or body JSON method: GET|POST headers: Headers while executing the request priority: Will be used to block events while lower priorities events have failed. An event will only execute if it' the next top priority on that group group_id: Grouping of events, if None, an event will have it's own unique group """ if not payload: payload = {} if not group_id: group_id = guid() event = Event() event.created = datetime.datetime.now() event.headers = json.dumps(headers) or '' event.method = method event.payload = json.dumps(payload) event.endpoint = endpoint event.status = EventStatus.CREATED event.priority = priority event.group_id = group_id event.put() q = taskqueue.Queue(QUEUE_NAME) q.add([ taskqueue.Task(name=cls._get_cutie_task_name(event.unique_id), payload=event.unique_id, method='PULL') ])
def execute(self): if not self.invite: self.invite = Invite.get_by_unique_id(self.invite_unique_id) invite_attendees = InviteAttendee.query( InviteAttendee.unique_id.IN(self.attendees_unique_ids) ).fetch() body = { 'invite_unique_id': self.invite.unique_id, 'uniquecall_id': guid(), 'attendees': [] } bulk_notifications = [] for invite_attendee in invite_attendees: if self._check_if_skip_attendee(invite_attendee): continue bulk_notifications += self.create_notification_records(invite_attendee) body['attendees'].append(NotifyAttendeeQuery( invite_attendee ).query()) group_id = EventQueue.get_group_id(self.invite.unique_id) EventQueue.push_event( endpoint=config.get('api_url') + "/attendees", headers=get_voiceflows_headers(), payload=body, group_id=group_id, #Same Group as Invite Creation priority=1 #Lower priority than Invite Creation ) ndb.put_multi(bulk_notifications)
def create_new_with_id(cls): return cls(unique_id=guid())