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

Add httplog after sync catalog and template #269

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
40 changes: 40 additions & 0 deletions temba/request_logs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,46 @@ def create_from_response(
contact=contact,
)

@classmethod
def create_from_integrations_response(
cls,
log_type,
url,
response,
status_code,
request,
classifier=None,
channel=None,
ticketer=None,
contact=None,
request_time=None,
):
org = (classifier or channel or ticketer or contact).org

is_error = status_code >= 400
# data = dump.dump_response(
# response,
# request_prefix=cls.REQUEST_DELIM.encode("utf-8"),
# response_prefix=cls.RESPONSE_DELIM.encode("utf-8"),
# ).decode("utf-8")

# first build our array of request lines, our last item will also contain our response lines

return cls.objects.create(
org=org,
log_type=log_type,
url=url,
request=request,
response=response,
is_error=is_error,
created_on=timezone.now(),
request_time=request_time,
classifier=classifier,
channel=channel,
ticketer=ticketer,
contact=contact,
)

@classmethod
def create_from_exception(
cls, log_type, url, exception, start, classifier=None, channel=None, ticketer=None, contact=None
Expand Down
12 changes: 11 additions & 1 deletion temba/templates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
from django.shortcuts import get_object_or_404

from temba.channels.models import Channel
from temba.request_logs.models import HTTPLog
from temba.utils.whatsapp.tasks import update_local_templates


class TemplateViewSet(viewsets.ModelViewSet, InternalGenericViewSet):
def partial_update(self, request, pk):
channel = get_object_or_404(Channel, uuid=pk)
waba_id = channel.config.get("wa_waba_id", None)
if waba_id:
HTTPLog.create_from_integrations_response(
HTTPLog.WHATSAPP_TEMPLATES_SYNCED,
request.data.get("url"),
request.data.get("request"),
200,
request.data.get("response"),
channel=channel,
)
update_local_templates(channel, request.data.get("data"))

return Response(status=status.HTTP_200_OK)
11 changes: 10 additions & 1 deletion temba/wpp_products/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from weni.internal.views import InternalGenericViewSet

from temba.channels.models import Channel
from temba.request_logs.models import HTTPLog
from temba.utils.whatsapp.tasks import update_channel_catalogs_status, update_local_catalogs
from temba.wpp_products.serializers import UpdateCatalogSerializer

Expand Down Expand Up @@ -32,7 +33,15 @@ def update_catalog(
**kwargs,
):
channel = get_object_or_404(Channel, uuid=pk, is_active=True)

if request.data:
HTTPLog.create_from_integrations_response(
HTTPLog.WHATSAPP_CATALOGS_SYNCED,
request.data.get("urls"),
request.data.get("responses"),
200,
request.data.get("requests"),
channel=channel,
)

update_local_catalogs(channel, request.data.get("data"))
return Response(status=status.HTTP_200_OK)
Loading