Skip to content

Commit

Permalink
Merge pull request #88 from opportunity-hack/develop
Browse files Browse the repository at this point in the history
[Feedback] Send Slack when feedback is sent
  • Loading branch information
gregv authored Sep 19, 2024
2 parents a946398 + d0f8b76 commit 047a86f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions api/messages/messages_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,8 +2011,8 @@ def save_feedback(propel_user_id, json):
})

logger.info(f"Insert Result: {insert_res}")

# Notify the feedback receiver

notify_feedback_receiver(feedback_receiver_id)

# Clear cache
Expand All @@ -2021,9 +2021,24 @@ def save_feedback(propel_user_id, json):
return Message("Feedback saved successfully")

def notify_feedback_receiver(feedback_receiver_id):
# Implement notification logic here
# This could be sending an email, a Slack message, or updating a notification field in the user's document
pass
db = get_db()
user_doc = db.collection('users').document(feedback_receiver_id).get()
if user_doc.exists:
user_data = user_doc.to_dict()
slack_user_id = user_data.get('user_id', '').split('-')[-1] # Extract Slack user ID
logger.info(f"User with ID {feedback_receiver_id} found")
logger.info(f"Sending notification to user {slack_user_id}")

message = (
f"Hello <@{slack_user_id}>! You've received new feedback. "
"Visit https://www.ohack.dev/myfeedback to view it."
)

# Send Slack message
send_slack(message=message, channel=slack_user_id)
logger.info(f"Notification sent to user {slack_user_id}")
else:
logger.warning(f"User with ID {feedback_receiver_id} not found")

@cached(cache=TTLCache(maxsize=100, ttl=600))
@limits(calls=100, period=ONE_MINUTE)
Expand Down

0 comments on commit 047a86f

Please sign in to comment.