Skip to content

Commit

Permalink
Merge pull request #702 from NASA-IMPACT/700-integrate-slack-notifica…
Browse files Browse the repository at this point in the history
…tions-for-feedback-and-content-curation-request-forms

slack notifications for feedbacks
  • Loading branch information
bishwaspraveen authored May 3, 2024
2 parents 5223407 + 55fce28 commit 96928c6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions feedback/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.db import models
from django.utils import timezone

from sde_collections.utils.slack_utils import send_slack_message


class Feedback(models.Model):
name = models.CharField(max_length=150)
Expand All @@ -17,8 +19,30 @@ class Meta:
def save(self, *args, **kwargs):
if not self.id:
self.created_at = timezone.now()
is_new = self._state.adding
if is_new:
message = self.format_notification_message()
try:
send_slack_message(message)
except Exception as e:
print(f"Failed to send slack message: {e}")
super().save(*args, **kwargs)

def format_notification_message(self):
"""
Returns a formatted notification message containing details from this Feedback instance.
"""
notification_message = (
f"<!here> New Feedback Received : \n"
f"Name: {self.name}\n"
f"Email: {self.email}\n"
f"Subject: {self.subject}\n"
f"Comments: {self.comments}\n"
f"Source: {self.source}\n"
f"Received on: {self.created_at.strftime('%Y-%m-%d %H:%M:%S')}"
)
return notification_message


class ContentCurationRequest(models.Model):
name = models.CharField(max_length=150)
Expand Down

0 comments on commit 96928c6

Please sign in to comment.