Skip to content

Commit

Permalink
Rename function; remove dupe method
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Nov 15, 2023
1 parent 22115ab commit 356ffbb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
2 changes: 1 addition & 1 deletion funnel/transports/whatsapp/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def init() -> bool:
return bool(senders)


def send(
def send_whatsapp(
phone: str | phonenumbers.PhoneNumber | PhoneNumber,
message: WhatsappTemplate,
) -> str:
Expand Down
28 changes: 2 additions & 26 deletions funnel/views/otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,13 @@ def send_sms(
# Send whatsapp message
def send_whatsapp(
self, flash_success: bool = True, flash_failure: bool = True
) -> str | None:
) -> whatsapp.WhatsappTemplate | None:
"""Send an OTP via WhatsApp to a phone number."""
if not self.phone:
return None
message = whatsapp.OTPTemplate(self.otp)
try:
whatsapp.send_via_meta(self.phone, message)
whatsapp.send_whatsapp(self.phone, message)
except TransportRecipientError as exc:
if flash_failure:
flash(str(exc), 'error')
Expand Down Expand Up @@ -413,30 +413,6 @@ def send_sms(
return msg
return None

# Send whatsapp message
def send_whatsapp(
self, flash_success: bool = True, flash_failure: bool = True
) -> str | None:
"""Send an OTP via WhatsApp to a phone number."""
if not self.phone:
return None
message = whatsapp.OTPTemplate(self.otp)
try:
whatsapp.send_via_meta(self.phone, message)
except TransportRecipientError as exc:
if flash_failure:
flash(str(exc), 'error')
else:
raise
if flash_success:
flash(
_("An OTP has been sent to your phone number {number}").format(
number=self.display_phone
),
'success',
)
return message

def send_email(
self, flash_success: bool = True, flash_failure: bool = True
) -> str | None:
Expand Down

0 comments on commit 356ffbb

Please sign in to comment.