Skip to content

Commit

Permalink
Ignore webhooks without user details
Browse files Browse the repository at this point in the history
  • Loading branch information
Sachinbisht27 committed Aug 9, 2024
1 parent 2352652 commit 1809e99
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ htmlcov/
.venv
env/
venv/
*.json

.vscode
.DS_Store
7 changes: 2 additions & 5 deletions api/models/call_log_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@


class CallLogEventQuery(BaseQuery):
def call_sid_exist(self, form_data):
return (
self.filter(CallLogEvent.call_sid == form_data["CallSid"]).first()
is not None
)
def call_sid_exist(self, call_sid):
return self.filter(CallLogEvent.call_sid == call_sid).first() is not None


class CallLogEvent(TimestampMixin, db.Model):
Expand Down
12 changes: 11 additions & 1 deletion api/services/handle_event_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

class HandleEventService:
def handle_event_service(self, form_data):
call_sid_exist = models.CallLogEvent.query.call_sid_exist(form_data)
call_sid_exist = models.CallLogEvent.query.call_sid_exist(
form_data.get("CallSid")
)

if call_sid_exist:
return
Expand All @@ -23,6 +25,14 @@ def handle_event_service(self, form_data):
if not system_phone_exists:
return

user_details_exist = form_data.get("From")

if user_details_exist is None:
logger.warning(
f"The user details are not exist in the webhook payload {form_data}"
)
return

try:
data = {}
data["call_sid"] = form_data["CallSid"]
Expand Down
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@
TELCO_CODE_ANSWERED = 16
DEFAULT_LANGUAGE_ID = 1
MAX_RETRY_ATTEMPTS_FOR_LOGS = os.environ.get("MAX_RETRY_ATTEMPTS_FOR_LOGS", 3)

GOOGLE_APPLICATION_CREDENTIALS = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS")

0 comments on commit 1809e99

Please sign in to comment.