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 +
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.
+ +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