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

PE-23: add alt callback domain #285

Merged
merged 2 commits into from
Dec 21, 2022
Merged
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
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.16
4.0.16.1
11 changes: 11 additions & 0 deletions engage/channels/types/twilio/__init__.py
Original file line number Diff line number Diff line change
@@ -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"
46 changes: 46 additions & 0 deletions engage/channels/types/twilio/type.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions engage/orgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions temba/settings_engage.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,5 @@
DEFAULT_PLAN = ORG_PLAN_ENGAGE

MIDDLEWARE += ("engage.utils.middleware.RedirectMiddleware",)

ALT_CALLBACK_DOMAIN = env('ALT_CALLBACK_DOMAIN', None)