-
Notifications
You must be signed in to change notification settings - Fork 156
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
Integration with AWS SNS #140
Comments
You could just replace callback function. Here is an example: def send_sms_with_callback_token(user, mobile_token, **kwargs):
"""
Sends a SMS to user.mobile via Amazon SNS.
Passes silently without sending in test environment.
"""
if (
settings.PASSWORDLESS_AUTH.get(
"PASSWORDLESS_TEST_SUPPRESSION",
passwordless_settings.PASSWORDLESS_TEST_SUPPRESSION,
)
is True
):
return True
base_string = kwargs.get(
"mobile_message",
settings.PASSWORDLESS_AUTH.get(
"PASSWORDLESS_MOBILE_MESSAGE",
passwordless_settings.PASSWORDLESS_MOBILE_MESSAGE,
),
)
try:
to_number = getattr(
user,
settings.PASSWORDLESS_AUTH.get(
"PASSWORDLESS_USER_MOBILE_FIELD_NAME",
passwordless_settings.PASSWORDLESS_USER_MOBILE_FIELD_NAME,
),
)
if to_number.__class__.__name__ == "PhoneNumber":
to_number = to_number.__str__()
client = boto3.client(
"sns",
region_name=settings.AWS_SNS_REGION,
aws_access_key_id=settings.AWS_SNS_ACCESS_KEY_ID,
aws_secret_access_key=settings.AWS_SNS_SECRET_ACCESS_KEY,
)
client.publish(
Message=base_string % mobile_token.key,
PhoneNumber=to_number,
)
return True
except KeyError:
logger.debug("Couldn't send SMS. Did you set your AWS tokens?")
return False
except Exception as e:
number = getattr(
user,
settings.PASSWORDLESS_AUTH.get(
"PASSWORDLESS_USER_MOBILE_FIELD_NAME",
passwordless_settings.PASSWORDLESS_USER_MOBILE_FIELD_NAME,
),
)
logger.debug(
f"Failed to send token SMS to user: {user.id} with number {number}.\n{e}"
)
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to integrate this with AWS instead of Twilio? Willl love to contribute
The text was updated successfully, but these errors were encountered: