Skip to content

Commit

Permalink
Refactor platform-specific bot test links
Browse files Browse the repository at this point in the history
- Remove message quicklink not available for Twilio
- Replace `twilio_phone_number_sid` condition with `twilio_phone_number` in `get_bot_test_link` to fix /chat links
- Use `furl` for constructing URLs, improving readability and maintainability.
  • Loading branch information
devxpy committed Jul 25, 2024
1 parent d296fdb commit 94cdb47
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
4 changes: 2 additions & 2 deletions daras_ai_v2/bot_integration_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ def get_bot_test_link(bi: BotIntegration) -> str | None:
integration_name=slugify(bi.name) or "untitled",
),
)
elif bi.twilio_phone_number_sid:
return f"https://console.twilio.com/us1/develop/phone-numbers/manage/incoming/{bi.twilio_phone_number_sid}/calls"
elif bi.twilio_phone_number:
return str(furl("tel:") / bi.twilio_phone_number.as_e164)
else:
return None

Expand Down
3 changes: 2 additions & 1 deletion payments/plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

import stripe
from furl import furl

from daras_ai_v2 import paypal, settings
from .utils import make_stripe_recurring_plan, make_paypal_recurring_plan
Expand Down Expand Up @@ -192,7 +193,7 @@ class PricingPlan(PricingPlanData, Enum):
</ul>
"""
),
contact_us_link=f"mailto:{settings.SALES_EMAIL}",
contact_us_link=str(furl("mailto:") / settings.SALES_EMAIL),
title_override="Let's talk",
caption_override="",
)
Expand Down
87 changes: 48 additions & 39 deletions recipes/VideoBots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,25 +1246,33 @@ def render_integrations_settings(
st.write("###### Connected To")
st.write(f"{icon} {bi}", unsafe_allow_html=True)
with col2:
if test_link:
if not test_link:
st.write("Message quicklink not available.")
elif bi.platform == Platform.TWILIO:
copy_to_clipboard_button(
'<i class="fa-regular fa-link"></i> Copy Phone Number',
value=bi.twilio_phone_number.as_e164,
type="secondary",
)
else:
copy_to_clipboard_button(
f'<i class="fa-regular fa-link"></i> Copy {Platform(bi.platform).label} Link',
value=test_link,
type="secondary",
)
else:
st.write("Message quicklink not available.")

if bi.platform == Platform.FACEBOOK:
st.anchor(
'<i class="fa-regular fa-inbox"></i> Open Inbox',
f"https://www.facebook.com/latest/inbox",
"https://www.facebook.com/latest/inbox",
unsafe_allow_html=True,
new_tab=True,
)
if bi.twilio_phone_number:
elif bi.platform == Platform.WEB:
embed_code = get_web_widget_embed_code(bi)
copy_to_clipboard_button(
f'<i class="fa-regular fa-link"></i> Copy Phone Number',
value=bi.twilio_phone_number.as_e164,
f"{icons.code} Copy Embed Code",
value=embed_code,
type="secondary",
)

Expand All @@ -1273,56 +1281,41 @@ def render_integrations_settings(
st.write("###### Test")
st.caption(f"Send a test message via {Platform(bi.platform).label}.")
with col2:
if bi.platform == Platform.FACEBOOK and test_link:
if not test_link:
st.write("Message quicklink not available.")
elif bi.platform == Platform.FACEBOOK:
st.anchor(
f"{icon} Open Profile",
test_link,
unsafe_allow_html=True,
new_tab=True,
)
st.anchor(
'<img src="https://upload.wikimedia.org/wikipedia/commons/b/be/Facebook_Messenger_logo_2020.svg" width="20" height="20" /> Open Messenger',
f"https://www.messenger.com/t/{bi.fb_page_id}",
f'<i class="fa-brands facebook-messenger"></i> Open Messenger',
str(furl("https://www.messenger.com/t/") / bi.fb_page_id),
unsafe_allow_html=True,
new_tab=True,
)
elif bi.platform == Platform.TWILIO and test_link:
pass
elif test_link:
elif bi.platform == Platform.TWILIO:
st.anchor(
f"{icon} Message {bi.get_display_name()}",
'<i class="fa-regular fa-phone"></i> Start Voice Call',
test_link,
unsafe_allow_html=True,
new_tab=True,
)
else:
st.write("Message quicklink not available.")

if bi.twilio_phone_number:
st.anchor(
'<i class="fa-regular fa-phone"></i> Start Voice Call',
f"tel:{bi.twilio_phone_number.as_e164}",
'<i class="fa-regular fa-sms"></i> Send SMS',
str(furl("sms:") / bi.twilio_phone_number.as_e164),
unsafe_allow_html=True,
new_tab=True,
)
else:
st.anchor(
'<i class="fa-regular fa-sms"></i> Send SMS',
f"sms:{bi.twilio_phone_number.as_e164}",
f"{icon} Message {bi.get_display_name()}",
test_link,
unsafe_allow_html=True,
new_tab=True,
)
elif bi.platform == Platform.TWILIO:
st.write(
"Phone number incorrectly configured. Please re-add the integration and double check spelling. [Contact Us]([email protected]) if you need help."
)

if bi.platform == Platform.WEB:
embed_code = get_web_widget_embed_code(bi)
copy_to_clipboard_button(
f"{icons.code} Copy Embed Code",
value=embed_code,
type="secondary",
)

col1, col2 = st.columns(2, style={"alignItems": "center"})
with col1:
Expand All @@ -1344,10 +1337,16 @@ def render_integrations_settings(
),
new_tab=True,
)
if bi.platform == Platform.TWILIO and test_link:
if bi.platform == Platform.TWILIO and bi.twilio_phone_number_sid:
st.anchor(
f"{icon} View Calls/Messages",
test_link,
f"{icon} Open Twilio Console",
str(
furl(
"https://console.twilio.com/us1/develop/phone-numbers/manage/incoming/"
)
/ bi.twilio_phone_number_sid
/ "calls"
),
unsafe_allow_html=True,
new_tab=True,
)
Expand All @@ -1362,12 +1361,22 @@ def render_integrations_settings(
with col2:
st.anchor(
"Business Settings",
f"https://business.facebook.com/settings/whatsapp-business-accounts/{bi.wa_business_waba_id}",
str(
furl(
"https://business.facebook.com/settings/whatsapp-business-accounts/"
)
/ bi.wa_business_waba_id
),
new_tab=True,
)
st.anchor(
"WhatsApp Manager",
f"https://business.facebook.com/wa/manage/home/?waba_id={bi.wa_business_waba_id}",
str(
furl(
"https://business.facebook.com/wa/manage/home/",
query_params=dict(waba_id=bi.wa_business_waba_id),
)
),
new_tab=True,
)

Expand Down

0 comments on commit 94cdb47

Please sign in to comment.