Ejemplo n.º 1
0
def send_push_to_checked_in_user(checkedInUser, checkedInByUser, beacon_id):
    checkedInByName = get_user_full_name(checkedInByUser)
    pushText = "{0} checked you in".format(checkedInByName)
    send_hotspot_message.delay(users=[checkedInUser],
                               push_text=pushText,
                               message_type=MESSAGE_TYPE.HOTSPOT_UPDATE,
                               beacon_id=beacon_id)
Ejemplo n.º 2
0
def send_message_notification(beacon, message, name):
    message_text = smart_format("{0}: {1}", name, message.message)
    users = users_to_notify(beacon, message.user)
    send_hotspot_message.delay(users=users,
                               push_text=message_text,
                               message_type=MESSAGE_TYPE.MESSAGE,
                               beacon_id=beacon.id)
Ejemplo n.º 3
0
def send_deal_invites(deal_statuses, custom_message=None, invited_by=None):
    beacon = deal_statuses[0].beacon
    deal = deal_statuses[0].deal
    if deal_statuses[0].image_url != '':
        image_url = deal_statuses[0].image_url
    else:
        image_url = None
    if invited_by is None:
        creator = beacon.creator
    else:
        creator = invited_by
    time_string = DateFormatter().friendly_string_for_timestamp(
        beacon.beacon_time, beacon.latitude, beacon.longitude)
    time_string = time_string[0].lower() + time_string[1:]
    time_string = time_string.replace(',', ' at')
    # sms_message = deal_invite_message(deal, beacon, time_string, is_sms=True, custom_message=custom_message)
    push_message = deal_invite_message(deal,
                                       beacon,
                                       time_string,
                                       is_sms=False,
                                       custom_message=custom_message,
                                       invited_by=creator)
    sms_message = sms_deal_invitation_message(deal,
                                              beacon,
                                              False,
                                              custom_message=custom_message,
                                              invited_by=creator)
    # user_sms_message = sms_deal_invitation_message(deal, beacon, True, custom_message=custom_message)
    # push_message = deal_invite_message(deal, beacon, time_string, is_sms=False, custom_message=custom_message)

    users = []
    contacts = []
    for status in deal_statuses:
        if status.user:
            if status.user.pk != creator.pk:
                users.append(status.user)
        else:
            contacts.append(status.contact)

    # send_hotspot_deal_invitations(users=users, contacts=contacts, sms_text=sms_message)
    # send_hotspot_deal_invitations(users=users, contacts=contacts, user_sms_text=user_sms_message, contact_sms_text=contact_sms_message)
    # send_intro_message_to_relevant_contacts(beacon.creator, contacts)
    send_hotspot_message.delay(users=users,
                               push_text=push_message,
                               contacts=contacts,
                               sms_text=sms_message,
                               beacon_id=beacon.id,
                               message_type=MESSAGE_TYPE.MESSAGE,
                               image_url=image_url)
Ejemplo n.º 4
0
def change_hotspot_message(beacon, sms_message, push_message):
    bf_objects = BeaconFollow.objects.filter(beacon=beacon).select_related(
        'user', 'contact')
    users = []
    contacts = []
    print
    for bf in bf_objects:
        if bf.user:
            users.append(bf.user)
        elif bf.contact:
            contacts.append(bf.contact)

    users.remove(beacon.creator)
    send_hotspot_message.delay(users, push_message, contacts, sms_message,
                               MESSAGE_TYPE.HOTSPOT_UPDATE, beacon.id)
Ejemplo n.º 5
0
def check_or_update_saw_invite(beacon_follow):
    print beacon_follow.saw_invite
    if beacon_follow.saw_invite is False:
        print "Was false, will now be made true"
        beacon_follow.saw_invite = True
        beacon_follow.save()
        if beacon_follow.contact:
            name = beacon_follow.contact.name
        else:
            name = beacon_follow.user.first_name
        message = smart_format("{0} read your invitation", name)
        if beacon_follow.invited_by is not None:
            send_hotspot_message.delay(
                users=[beacon_follow.invited_by],
                push_text=message,
                message_type=MESSAGE_TYPE.HOTSPOT_UPDATE,
                beacon_id=beacon_follow.beacon.id)
    else:
        print "Was already true, no change"
Ejemplo n.º 6
0
def send_sms_invites(user, beacon, user_list, contact_list):
    # get your number so you dont get texts about your own hotspot
    if Profile.objects.filter(user=user).exists():
        profile = Profile.objects.get(user=user)
        normalized_phone = profile.normalized_phone

    first_time_body = smart_format(
        "{0} {1} uses the app Hotspot (GetHotspotApp.com) to simplify meeting up with friends.",
        user.first_name, user.last_name)

    if user.last_name:
        notification_text = smart_format("{0} {1}: {2}", user.first_name,
                                         user.last_name, beacon.description)
    else:
        notification_text = smart_format("{0}: {1}", user.first_name,
                                         beacon.description)

    #add time and location info
    try:
        time_string = DateFormatter().friendly_string_for_timestamp(
            beacon.beacon_time, beacon.latitude, beacon.longitude)
        address_string = beacon.address
        notification_text += smart_format("\n{0} @ {1}", time_string,
                                          address_string)
    except:
        client.captureException()

    first_time_contacts = get_first_time_contacts(contact_list)

    # Add profiles and contacts to Beacon Follow (formerly Beacon Invites)
    beacon_invites = []
    profiles = Profile.objects.filter(user__in=user_list).exclude(
        normalized_phone=normalized_phone).select_related('user')

    for profile in profiles:
        beacon_invites.append(
            BeaconFollow(beacon=beacon,
                         user=profile.user,
                         invited_by=user,
                         state=BEACON_FOLLOW_STATUS.INVITED))
    for contact in contact_list:
        beacon_invites.append(
            BeaconFollow(beacon=beacon,
                         contact=contact,
                         invited_by=user,
                         state=BEACON_FOLLOW_STATUS.INVITED))

    BeaconFollow.objects.bulk_create(beacon_invites)

    beacon_invitations = BeaconFollow.objects.filter(
        beacon=beacon,
        contact__in=contact_list,
        invited_by=user,
        state=BEACON_FOLLOW_STATUS.INVITED).select_related('user')

    # Create individualized messages for each Hotspot SMS
    contacts_sms_list = []
    sms_response_text = smart_format(
        'Reply with "Yes" to let {0} know you can come or with "More" if you want more info',
        user.first_name)
    sms_message = smart_format("{0}\n\n{1}", notification_text,
                               sms_response_text)
    for contact in contact_list:
        current_dict = {
            'contact_phone': contact.normalized_phone,
            'message': sms_message
        }
        contacts_sms_list.append(current_dict)

    sms_users = User.objects.filter(pk__in=[o.pk for o in user_list],
                                    android_devices=None,
                                    ios_devices=None).select_related('profile')
    sms_profiles = [o.profile for o in sms_users]
    profile_sms_list = []
    for profile in sms_profiles:
        message = notification_text + "\nEvent details: Hotspot://Go-to-App"
        current_dict = {
            'profile_phone': profile.normalized_phone,
            'message': message
        }
        profile_sms_list.append(current_dict)

    send_hotspot_message.delay(contacts=first_time_contacts,
                               sms_text=first_time_body,
                               message_type=MESSAGE_TYPE.HOTSPOT_UPDATE,
                               beacon_id=beacon.id)
    send_hotspot_message.delay(users=user_list,
                               push_text=notification_text,
                               message_type=MESSAGE_TYPE.HOTSPOT_UPDATE,
                               beacon_id=beacon.id)
    send_individualized_sms.delay(contacts_sms_list, profile_sms_list)
    return True