Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feedback] Send Slack when feedback is sent #88

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading