From 61d1dff8d74647a210905386559bce026224b5a2 Mon Sep 17 00:00:00 2001 From: Ryan Fischbach Date: Tue, 20 Dec 2022 11:17:38 -0800 Subject: [PATCH 1/2] PE-23: add alt callback domain --- engage/channels/types/twilio/__init__.py | 11 ++++++ engage/channels/types/twilio/type.py | 46 ++++++++++++++++++++++++ engage/orgs/models.py | 8 +++++ temba/settings_engage.py | 2 ++ 4 files changed, 67 insertions(+) create mode 100644 engage/channels/types/twilio/__init__.py create mode 100644 engage/channels/types/twilio/type.py diff --git a/engage/channels/types/twilio/__init__.py b/engage/channels/types/twilio/__init__.py new file mode 100644 index 0000000000..f8c5529c35 --- /dev/null +++ b/engage/channels/types/twilio/__init__.py @@ -0,0 +1,11 @@ +from django.apps import AppConfig as BaseAppConfig + +default_app_config = 'engage.channels.types.twilio.AppConfig' + +class AppConfig(BaseAppConfig): + """ + django app labels must be unique; so override AppConfig to ensure uniqueness + """ + name = "engage.channels.types.twilio" + label = "engage_channels_types_twilio" + verbose_name = "Engage Channels Types Twilio" diff --git a/engage/channels/types/twilio/type.py b/engage/channels/types/twilio/type.py new file mode 100644 index 0000000000..c5a783a66a --- /dev/null +++ b/engage/channels/types/twilio/type.py @@ -0,0 +1,46 @@ +import logging + +from django.urls import reverse + +from engage.utils.class_overrides import ClassOverrideMixinMustBeFirst + +from temba.channels.models import Channel +from temba.channels.types.twilio.type import TwilioType + + +logger = logging.getLogger(__name__) + +class TwilioTypeOverrides(ClassOverrideMixinMustBeFirst, TwilioType): + + def enable_flow_server(self, channel): + """ + Called when our organization is switched to being flow server enabled, + for Twilio we have to switch our IVR + status and incoming calls to point to mailroom URLs. + """ + # noop if we don't support ivr or are a shortcode + if not channel.supports_ivr() or len(channel.address) <= 6: + return + + org = channel.org + client = org.get_twilio_client() + config = channel.config + + base_url = "https://" + config.get(Channel.CONFIG_CALLBACK_DOMAIN, org.get_brand_domain()) + + # build our URLs + channel_uuid = str(channel.uuid) + mr_status_url = base_url + reverse("mailroom.ivr_handler", args=[channel_uuid, "status"]) + mr_incoming_url = base_url + reverse("mailroom.ivr_handler", args=[channel_uuid, "incoming"]) + + # update the voice URLs on our app + app = client.api.applications.get(sid=config["application_sid"]) + app.update( + voice_method="POST", + voice_url=mr_incoming_url, + status_callback_method="POST", + status_callback=mr_status_url, + ) + #enddef enable_flow_server + +#endclass TwilioTypeOverrides diff --git a/engage/orgs/models.py b/engage/orgs/models.py index d6b93c096e..31413c20eb 100644 --- a/engage/orgs/models.py +++ b/engage/orgs/models.py @@ -6,6 +6,7 @@ from engage.utils.class_overrides import ClassOverrideMixinMustBeFirst, ignoreDjangoModelAttrs from temba.orgs.models import Org, OrgRole +import temba.settings as siteconfig def get_user_org(user): @@ -51,6 +52,13 @@ class OrgModelOverride(ClassOverrideMixinMustBeFirst, Org): class Meta: abstract = True + def get_brand_domain(self): + if siteconfig.ALT_CALLBACK_DOMAIN: + return siteconfig.ALT_CALLBACK_DOMAIN + else: + return self.getOrigClsAttr('get_brand_domain')(self) + #enddef get_brand_domain + def release(self, user, **kwargs): with transaction.atomic(): self.getOrigClsAttr('release')(self, user, **kwargs) diff --git a/temba/settings_engage.py b/temba/settings_engage.py index 080b8165d3..709e2b27d5 100644 --- a/temba/settings_engage.py +++ b/temba/settings_engage.py @@ -433,3 +433,5 @@ DEFAULT_PLAN = ORG_PLAN_ENGAGE MIDDLEWARE += ("engage.utils.middleware.RedirectMiddleware",) + +ALT_CALLBACK_DOMAIN = env('ALT_CALLBACK_DOMAIN', None) From 2fedafd3f4d24dd60db0b0d86b2ce0cc22d94a99 Mon Sep 17 00:00:00 2001 From: Ryan Fischbach Date: Tue, 20 Dec 2022 19:31:49 -0800 Subject: [PATCH 2/2] version bump. --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 5188cc0763..5341619eac 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.16 +4.0.16.1