import os
import requests
from django.core.mail import send_mail
from clowder_account.models import ClowderUser


ADMIN_EMAIL = 'admin@clowder.io'

def send_alert(company, name):
    for user in ClowderUser.objects.filter(company=company, allow_email_notifications=True):
        subject = 'FAILURE: %s' % (name)
        body = subject
        if user.company_id == 86:
            slack_token = os.getenv('PARKME_SLACK_TOKEN')
            url = 'https://hooks.slack.com/services/%s' % (slack_token)
            payload = {"username": "devopsbot", "text": body, "icon_emoji": ":robot_face:"}
            requests.post(url, json=payload)
        send_mail(subject, body, ADMIN_EMAIL, [user.email], fail_silently=True)

@@ -168,24 +168,47 @@
 any, name):%0A
+    slack_sent = False%0A
     for user
@@ -284,24 +284,24 @@
 ions=True):%0A
-
         subj
@@ -384,16 +384,35 @@
 id == 86
+ and not slack_sent
 :%0A      
@@ -575,17 +575,15 @@
 %22: %22
-devopsbot
+clowder
 %22, %22
@@ -615,18 +615,15 @@
 : %22:
-robot_face
+clowder
 :%22%7D%0A
@@ -667,16 +667,46 @@
 ayload)%0A
+            slack_sent = True%0A
         

Rename bot and prevent channel spamming