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

Notifies flows for template creation and deletion #524

Open
wants to merge 1 commit 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
12 changes: 12 additions & 0 deletions marketplace/services/flows/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,15 @@
return self.client.create_wac_channel(
user, project_uuid, phone_number_id, config
)

# TODO: need implement methods on client
def create_facebook_template(self, flow_object_uuid, template_data, template_name):
return self.client.create_facebook_template(
flow_object_uuid, template_data, template_name
)

# TODO: need implement methods on client
def delete_facebook_template(self, flow_object_uuid, template_data, template_name):
return self.client.delete_facebook_template(

Check warning on line 74 in marketplace/services/flows/service.py

View check run for this annotation

Codecov / codecov/patch

marketplace/services/flows/service.py#L74

Added line #L74 was not covered by tests
flow_object_uuid, template_data, template_name
)
25 changes: 25 additions & 0 deletions marketplace/wpp_templates/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import base64
import logging

from typing import List, Any

Expand All @@ -12,16 +13,21 @@
from rest_framework import serializers

from marketplace.applications.models import App
from marketplace.services.flows.service import FlowsService
from marketplace.wpp_templates.models import (
TemplateMessage,
TemplateTranslation,
TemplateButton,
TemplateHeader,
)
from marketplace.clients.flows.client import FlowsClient
from marketplace.clients.facebook.client import FacebookClient
from marketplace.services.facebook.service import TemplateService, PhotoAPIService
from marketplace.wpp_templates.utils import extract_template_data


logger = logging.getLogger(__name__)

WHATSAPP_VERSION = settings.WHATSAPP_VERSION

User = get_user_model()
Expand Down Expand Up @@ -172,6 +178,25 @@
hh.pop("example")
TemplateHeader.objects.create(translation=translation, **hh)

if translation:
try:
# Send template to flows
flows_service = FlowsService(FlowsClient())
template_data = extract_template_data(translation)
flows_service.create_facebook_template(
flow_object_uuid=str(translation.template.app.flow_object_uuid),
template_data=template_data,
template_name=translation.template.name,
)
logger.info(f"A new template {template.name} has sent to flows.")

Check warning on line 191 in marketplace/wpp_templates/serializers.py

View check run for this annotation

Codecov / codecov/patch

marketplace/wpp_templates/serializers.py#L191

Added line #L191 was not covered by tests
except Exception as e:
logger.error(
f"Fail to sends a new template to flows: {template.name}, translation: {translation.language},"
f"translation ID: {translation.message_template_id}. Error: {e}",
exc_info=True,
stack_info=True,
)

return translation


Expand Down
Loading