Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/84 Ignore webhook without user details #85

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignoring the JSON files to be added to the GitHub.


.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
Comment on lines +7 to +8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the query based on the changes done in the handle event service from where the query is called.



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")
)
Comment on lines +12 to +14
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the entire webhook payload was passed as a parameter in the query, and we extracted the callsid within the model. Now, I’ve optimized the process by passing only the callsid in the query, as it's the only required parameter.


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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name sounds like it will store a boolean value, which I believe is not correct.
Can we write it just user_details or something similar?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let me update it.


if user_details_exist is None:
logger.warning(
f"User details are missing in the webhook payload: {form_data}"
)
return

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are checking if the user details are present in the webhook we are getting from the KooKoo. If not then we are skipping those webhooks to be processed.

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")
Comment on lines +49 to +50
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added because every time while run the server locally we get an error that:

google.auth.exceptions.DefaultCredentialsError: File big-query-credentials.json was not found

Loading