Skip to content

Commit

Permalink
changing from twilio to email notification for message sent fail
Browse files Browse the repository at this point in the history
  • Loading branch information
biagiodistefano committed Apr 30, 2024
1 parent 4f9ea9e commit 24680c3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/api/twilio_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from django.shortcuts import get_object_or_404
from ninja_extra import api_controller, route
import requests
from django.core.mail import send_mail


from . import messages, models, settings, tasks
from . import messages, models
from django.conf import settings
from .auth import TwilioAuth

logger = logging.getLogger("twilio_whatsapp")
Expand All @@ -28,7 +29,13 @@ def receive_status(self, request: HttpRequest):
message.save()
if message.status in ("undelivered", "failed", "queued"):
logger.error(f"{message}")
tasks.send_whatsapp_message.delay(settings.MY_PHONE_NUMBER, f"{message}")
send_mail(
f"Error sending message {message}",
message,
settings.DEFAULT_FROM_EMAIL,
[admin[1] for admin in settings.ADMINS],
fail_silently=True,
)
return HttpResponse("OK", status=200)

@route.post("/inbound", url_name="twilio_inbound")
Expand Down

0 comments on commit 24680c3

Please sign in to comment.