forked from GithubBackups/healthchecks
Send email notification when monthly SMS sending limit is reached. Fixes #292
This commit is contained in:
parent
488ab2cce7
commit
66a6de70c0
@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Add support for OpsGenie EU region (#294)
|
- Add support for OpsGenie EU region (#294)
|
||||||
- Update OpsGenie logo and setup illustrations
|
- Update OpsGenie logo and setup illustrations
|
||||||
- Add a "Create a Copy" function for cloning checks (#288)
|
- Add a "Create a Copy" function for cloning checks (#288)
|
||||||
|
- Send email notification when monthly SMS sending limit is reached (#292)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
- Prevent double-clicking the submit button in signup form
|
- Prevent double-clicking the submit button in signup form
|
||||||
|
@ -109,6 +109,13 @@ class Profile(models.Model):
|
|||||||
ctx = {"button_text": "Change Email", "button_url": settings.SITE_ROOT + path}
|
ctx = {"button_text": "Change Email", "button_url": settings.SITE_ROOT + path}
|
||||||
emails.change_email(self.user.email, ctx)
|
emails.change_email(self.user.email, ctx)
|
||||||
|
|
||||||
|
def send_sms_limit_notice(self, transport):
|
||||||
|
ctx = {"transport": transport, "limit": self.sms_limit}
|
||||||
|
if self.sms_limit != 500 and settings.USE_PAYMENTS:
|
||||||
|
ctx["url"] = settings.SITE_ROOT + reverse("hc-billing")
|
||||||
|
|
||||||
|
emails.sms_limit(self.user.email, ctx)
|
||||||
|
|
||||||
def projects(self):
|
def projects(self):
|
||||||
""" Return a queryset of all projects we have access to. """
|
""" Return a queryset of all projects we have access to. """
|
||||||
|
|
||||||
|
@ -591,6 +591,13 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
n = Notification.objects.get()
|
n = Notification.objects.get()
|
||||||
self.assertTrue("Monthly SMS limit exceeded" in n.error)
|
self.assertTrue("Monthly SMS limit exceeded" in n.error)
|
||||||
|
|
||||||
|
# And email should have been sent
|
||||||
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
|
||||||
|
email = mail.outbox[0]
|
||||||
|
self.assertEqual(email.to[0], "alice@example.org")
|
||||||
|
self.assertEqual(email.subject, "Monthly SMS Limit Reached")
|
||||||
|
|
||||||
@patch("hc.api.transports.requests.request")
|
@patch("hc.api.transports.requests.request")
|
||||||
def test_sms_limit_reset(self, mock_post):
|
def test_sms_limit_reset(self, mock_post):
|
||||||
# At limit, but also into a new month
|
# At limit, but also into a new month
|
||||||
@ -652,6 +659,13 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
n = Notification.objects.get()
|
n = Notification.objects.get()
|
||||||
self.assertTrue("Monthly message limit exceeded" in n.error)
|
self.assertTrue("Monthly message limit exceeded" in n.error)
|
||||||
|
|
||||||
|
# And email should have been sent
|
||||||
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
|
||||||
|
email = mail.outbox[0]
|
||||||
|
self.assertEqual(email.to[0], "alice@example.org")
|
||||||
|
self.assertEqual(email.subject, "Monthly WhatsApp Limit Reached")
|
||||||
|
|
||||||
@patch("apprise.Apprise")
|
@patch("apprise.Apprise")
|
||||||
@override_settings(APPRISE_ENABLED=True)
|
@override_settings(APPRISE_ENABLED=True)
|
||||||
def test_apprise_enabled(self, mock_apprise):
|
def test_apprise_enabled(self, mock_apprise):
|
||||||
|
@ -412,6 +412,7 @@ class Sms(HttpTransport):
|
|||||||
def notify(self, check):
|
def notify(self, check):
|
||||||
profile = Profile.objects.for_user(self.channel.project.owner)
|
profile = Profile.objects.for_user(self.channel.project.owner)
|
||||||
if not profile.authorize_sms():
|
if not profile.authorize_sms():
|
||||||
|
profile.send_sms_limit_notice("SMS")
|
||||||
return "Monthly SMS limit exceeded"
|
return "Monthly SMS limit exceeded"
|
||||||
|
|
||||||
url = self.URL % settings.TWILIO_ACCOUNT
|
url = self.URL % settings.TWILIO_ACCOUNT
|
||||||
@ -439,6 +440,7 @@ class WhatsApp(HttpTransport):
|
|||||||
def notify(self, check):
|
def notify(self, check):
|
||||||
profile = Profile.objects.for_user(self.channel.project.owner)
|
profile = Profile.objects.for_user(self.channel.project.owner)
|
||||||
if not profile.authorize_sms():
|
if not profile.authorize_sms():
|
||||||
|
profile.send_sms_limit_notice("WhatsApp")
|
||||||
return "Monthly message limit exceeded"
|
return "Monthly message limit exceeded"
|
||||||
|
|
||||||
url = self.URL % settings.TWILIO_ACCOUNT
|
url = self.URL % settings.TWILIO_ACCOUNT
|
||||||
|
@ -75,3 +75,7 @@ def invoice(to, ctx, filename, pdf_data):
|
|||||||
|
|
||||||
def deletion_notice(to, ctx, headers={}):
|
def deletion_notice(to, ctx, headers={}):
|
||||||
send("deletion-notice", to, ctx, headers)
|
send("deletion-notice", to, ctx, headers)
|
||||||
|
|
||||||
|
|
||||||
|
def sms_limit(to, ctx):
|
||||||
|
send("sms-limit", to, ctx)
|
||||||
|
22
templates/emails/sms-limit-body-html.html
Normal file
22
templates/emails/sms-limit-body-html.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{% extends "emails/base.html" %}
|
||||||
|
{% load hc_extras %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
Hello,<br />
|
||||||
|
<p>
|
||||||
|
We could not deliver a {{ transport }} notification because your {% site_name %}
|
||||||
|
account has reached its monthly sending limit of
|
||||||
|
<strong>{{ limit }} sends per month</strong>. The limit resets at the start of
|
||||||
|
each month.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{% if url %}
|
||||||
|
<p>You can increase the monthly sending limit by <a href="{{ url }}">upgrading your billing plan</a>.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content_more %}
|
||||||
|
Regards,<br />
|
||||||
|
The {% site_name %} Team
|
||||||
|
{% endblock %}
|
10
templates/emails/sms-limit-body-text.html
Normal file
10
templates/emails/sms-limit-body-text.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{% load hc_extras %}Hello,
|
||||||
|
|
||||||
|
We could not deliver a {{ transport }} notification because your {% site_name %} account has reached its monthly sending limit of {{ limit }} sends per month. The limit resets at the start of each month.
|
||||||
|
{% if url %}You can increase the monthly sending limit by upgrading your billing plan:
|
||||||
|
|
||||||
|
{{ url }}{% endif %}
|
||||||
|
|
||||||
|
--
|
||||||
|
Regards,
|
||||||
|
The {% site_name %} Team
|
1
templates/emails/sms-limit-subject.html
Normal file
1
templates/emails/sms-limit-subject.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
Monthly {{ transport }} Limit Reached
|
Loading…
x
Reference in New Issue
Block a user