diff --git a/marketplace/connect/client.py b/marketplace/connect/client.py index ac38459c..b430ea70 100644 --- a/marketplace/connect/client.py +++ b/marketplace/connect/client.py @@ -28,6 +28,11 @@ class ConnectProjectClient(ConnectAuth): base_url = settings.CONNECT_ENGINE_BASE_URL use_connect_v2 = settings.USE_CONNECT_V2 + def _get_url(self, endpoint: str) -> str: + # TODO: refactor all clients to use this method + assert endpoint.startswith("/"), "the endpoint needs to start with: /" + return self.base_url + endpoint + def list_channels(self, channeltype_code: str) -> list: params = { "channel_type": channeltype_code @@ -145,6 +150,13 @@ def detail_channel_type(self, channel_code: str): ) return response + def create_external_service(self, user: str, project_uuid: str, type_fields: dict, type_code: str): + payload = {"user": user, "project_uuid": str(project_uuid), "type_fields": type_fields, "type_code": type_code} + response = requests.post( + self._get_url("/v1/organization/project/create_external/"), json=payload, headers=self.auth_header() + ) + return response + class WPPRouterChannelClient(ConnectAuth): base_url = settings.ROUTER_BASE_URL diff --git a/marketplace/core/types/base.py b/marketplace/core/types/base.py index 9b9ef136..d0e8ecd2 100644 --- a/marketplace/core/types/base.py +++ b/marketplace/core/types/base.py @@ -15,11 +15,13 @@ class AbstractAppType(ABC): CATEGORY_CHANNEL = "CN" CATEGORY_CLASSIFIER = "CF" CATEGORY_TICKETER = "TK" + CATEGORY_EXTERNAL = "EXT" CATEGORY_CHOICES = ( (CATEGORY_CHANNEL, "channel"), (CATEGORY_CLASSIFIER, "classifier"), (CATEGORY_TICKETER, "ticketer"), + (CATEGORY_EXTERNAL, "external"), ) @abstractproperty @@ -30,13 +32,6 @@ def view_class(self) -> APIView: def code(self) -> str: ... # pragma: no cover - @abstractproperty - def channeltype_code(self) -> str: - """ - code referring to `ChannelType.code` in Weni Flows - """ - ... - @abstractproperty def name(self) -> str: ... # pragma: no cover diff --git a/marketplace/core/types/externals/base.py b/marketplace/core/types/externals/base.py new file mode 100644 index 00000000..7c555abc --- /dev/null +++ b/marketplace/core/types/externals/base.py @@ -0,0 +1,14 @@ +from abc import abstractproperty + +from marketplace.core.types.base import AppType +from marketplace.applications.models import App + + +class ExternalAppType(AppType): + + platform = App.PLATFORM_WENI_FLOWS + category = AppType.CATEGORY_EXTERNAL + + @abstractproperty + def flows_type_code(self) -> str: + pass diff --git a/marketplace/core/types/externals/omie/type.py b/marketplace/core/types/externals/omie/type.py new file mode 100644 index 00000000..5328624b --- /dev/null +++ b/marketplace/core/types/externals/omie/type.py @@ -0,0 +1,13 @@ +from ..base import ExternalAppType + + +class OmieType(ExternalAppType): + view_class = None + + code = "omie" + flows_type_code = "omie" + name = "Omie" + description = "omie.data.description" + summary = "omie.data.summary" + bg_color = None + developer = "Weni" diff --git a/marketplace/settings.py b/marketplace/settings.py index 04424597..085437eb 100644 --- a/marketplace/settings.py +++ b/marketplace/settings.py @@ -267,6 +267,7 @@ APPTYPE_INSTAGRAM_CHANNEL_PATH = "channels.instagram.type.InstagramType" APPTYPE_FACEBOOK_CHANNEL_PATH = "channels.facebook.type.FacebookType" +APPTYPE_OMIE_PATH = "externals.omie.type.OmieType" APPTYPES_CLASSES = [ APPTYPE_WENI_WEB_CHAT_PATH, @@ -278,6 +279,7 @@ APPTYPE_INSTAGRAM_CHANNEL_PATH, APPTYPE_FACEBOOK_CHANNEL_PATH, + APPTYPE_OMIE_PATH, ] # These conditions avoid dependence between apptypes,