oncall-engine/engine/apps/twilioapp/models/twilio_sms.py
Innokentii Konstantinov 306f842963
TwilioPhoneProvider optimizations (#2034)
# What this PR does
This PR does three improvements in twilio_phone_provider:
1.
[Speed-up](https://github.com/grafana/oncall/pull/2034/files#diff-7a311767169c024e60e2b4e35fd531dd6e2f1ea785cfc84263e11e7932d622af)
query which calculates amount of phone_calls/sms left.
2. Remove code which was needed only for backward compatibility during
the release of PhoneProvider refactoring and improves logging for
handling status/gather updates.
3. Add db_index to twilio_sid. We are doing lot of lookups by sid and
with increasing amount of data it became resource consuming.
2023-06-08 05:13:54 +00:00

64 lines
1.6 KiB
Python

from django.db import models
from apps.phone_notifications.models import ProviderSMS
class TwilioSMSstatuses:
"""
https://www.twilio.com/docs/sms/tutorials/how-to-confirm-delivery-python?code-sample=code-handle-a-sms-statuscallback&code-language=Python&code-sdk-version=5.x#receive-status-events-in-your-web-application
https://www.twilio.com/docs/sms/api/message-resource#message-status-values
"""
ACCEPTED = 10
QUEUED = 20
SENDING = 30
SENT = 40
FAILED = 50
DELIVERED = 60
UNDELIVERED = 70
RECEIVING = 80
RECEIVED = 90
READ = 100
CHOICES = (
(ACCEPTED, "accepted"),
(QUEUED, "queued"),
(SENDING, "sending"),
(SENT, "sent"),
(FAILED, "failed"),
(DELIVERED, "delivered"),
(UNDELIVERED, "undelivered"),
(RECEIVING, "receiving"),
(RECEIVED, "received"),
(READ, "read"),
)
DETERMINANT = {
"accepted": ACCEPTED,
"queued": QUEUED,
"sending": SENDING,
"sent": SENT,
"failed": FAILED,
"delivered": DELIVERED,
"undelivered": UNDELIVERED,
"receiving": RECEIVING,
"received": RECEIVED,
"read": READ,
}
class TwilioSMS(ProviderSMS, models.Model):
status = models.PositiveSmallIntegerField(
blank=True,
null=True,
choices=TwilioSMSstatuses.CHOICES,
)
# https://www.twilio.com/docs/sms/api/message-resource#message-properties
sid = models.CharField(
blank=True,
max_length=50,
db_index=True,
)
created_at = models.DateTimeField(auto_now_add=True)