diff --git a/api/messages/messages_service.py b/api/messages/messages_service.py index 58096e3..66a9100 100644 --- a/api/messages/messages_service.py +++ b/api/messages/messages_service.py @@ -24,6 +24,8 @@ import os from db.db import fetch_user_by_user_id, get_user_doc_reference +import resend +import random @@ -575,6 +577,74 @@ def unjoin_team(propel_user_id, json): return Message( "Removed from Team") +@limits(calls=100, period=ONE_MINUTE) +def save_npo_application(json): + send_slack_audit(action="save_npo_application", message="Saving", payload=json) + db = get_db() # this connects to our Firestore database + logger.debug("NPO Application Save") + + # Check Google Captcha + token = json["token"] + recaptcha_response = requests.post( + f"https://www.google.com/recaptcha/api/siteverify?secret={google_recaptcha_key}&response={token}") + recaptcha_response_json = recaptcha_response.json() + logger.info(f"Recaptcha Response: {recaptcha_response_json}") + + if recaptcha_response_json["success"] == False: + return Message( + "Recaptcha failed" + ) + + + ''' + Save this data into the Firestore database in the project_applications collection + name: '', + email: '', + organization: '', + idea: '', + isNonProfit: false, + ''' + doc_id = uuid.uuid1().hex + + name = json["name"] + email = json["email"] + organization = json["organization"] + idea = json["idea"] + isNonProfit = json["isNonProfit"] + + collection = db.collection('project_applications') + + insert_res = collection.document(doc_id).set({ + "name": name, + "email": email, + "organization": organization, + "idea": idea, + "isNonProfit": isNonProfit, + "timestamp": datetime.now().isoformat() + }) + + logger.info(f"Insert Result: {insert_res}") + + send_nonprofit_welcome_email(name, email) + + # Send a Slack message to nonprofit-form-submissions with all content + slack_message = f''' +:rocket: New NPO Application :rocket: +Name: `{name}` +Email: `{email}` +Organization: `{organization}` +Idea: `{idea}` +Is Nonprofit: `{isNonProfit}` +''' + send_slack(slack_message, "nonprofit-form-submissions") + + + + return Message( + "Saved NPO Application" + ) + + @limits(calls=100, period=ONE_MINUTE) def save_npo(json): @@ -904,11 +974,91 @@ def send_welcome_emails(): }) emails.add(email) +def send_nonprofit_welcome_email(organization_name, contact_name, email): + resend.api_key = os.getenv("RESEND_WELCOME_EMAIL_KEY") + + subject = "Welcome to Opportunity Hack: Tech Solutions for Your Nonprofit!" + + images = [ + "https://cdn.ohack.dev/ohack.dev/2023_hackathon_1.webp", + "https://cdn.ohack.dev/ohack.dev/2023_hackathon_2.webp", + "https://cdn.ohack.dev/ohack.dev/2023_hackathon_3.webp" + ] + chosen_image = random.choice(images) + image_number = images.index(chosen_image) + 1 + image_utm_content = f"nonprofit_header_image_{image_number}" + + ''' + TODO: Add these pages and then move these down into the email we send -def send_welcome_email(name, email): - import resend - import random +
  • Access Your Nonprofit Dashboard - Track your project's progress
  • +
  • Understanding Our Process - Learn how we match you with volunteers
  • +
  • Nonprofit Resources - Helpful guides for working with tech teams
  • +
  • Success Stories - See how other nonprofits have benefited
  • + +
  • Submit or Update Your Project
  • +
  • Tips for Communicating with Volunteers
  • + ''' + + html_content = f""" + + + + + + Welcome to Opportunity Hack + + + Opportunity Hack Event + +

    Welcome {organization_name} to Opportunity Hack!

    + +

    Dear {contact_name},

    + +

    We're excited to welcome {organization_name} to the Opportunity Hack community! We're here to connect your nonprofit with skilled tech volunteers to bring your ideas to life.

    + +

    What's Next?

    + + +

    Important Links:

    + + +

    Questions or need assistance? Reach out on our Slack channel or email us at support@ohack.dev.

    + +

    We're excited to work with you to create tech solutions that amplify your impact!

    + +

    Best regards,
    The Opportunity Hack Team

    + + + + + + """ + + if organization_name is None or organization_name == "" or organization_name == "Unassigned" or organization_name.isspace(): + organization_name = "Nonprofit Partner" + + if contact_name is None or contact_name == "" or contact_name == "Unassigned" or contact_name.isspace(): + contact_name = "Nonprofit Friend" + + params = { + "from": "Opportunity Hack ", + "to": f"{contact_name} <{email}>", + "subject": subject, + "html": html_content, + } + + email = resend.Emails.SendParams(params) + resend.Emails.send(email) + return True +def send_welcome_email(name, email): resend.api_key = os.getenv("RESEND_WELCOME_EMAIL_KEY") subject = "Welcome to Opportunity Hack: Code for Good!" diff --git a/api/messages/messages_views.py b/api/messages/messages_views.py index 386a03e..ced6ab9 100644 --- a/api/messages/messages_views.py +++ b/api/messages/messages_views.py @@ -36,7 +36,8 @@ save_news, save_lead_async, get_news, - get_all_profiles + get_all_profiles, + save_npo_application ) @@ -96,6 +97,10 @@ def get_npos(): def get_npo(npo_id): return (get_single_npo(npo_id)) +# This isn't authenticated, but we're using Google reCAPTCHA to prevent abuse +@bp.route("/npo/submit-application", methods=["POST"]) +def submit_npo_application(): + return vars(save_npo_application(request.get_json())) #