Skip to content

Commit 9742f7f

Browse files
Tumushimire YvesTumushimire Yves
Tumushimire Yves
authored and
Tumushimire Yves
committed
change twilio into Africastalking
1 parent 7fe00df commit 9742f7f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drfpasswordless/utils.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -169,31 +169,31 @@ def send_sms_with_callback_token(user, mobile_token, **kwargs):
169169
if api_settings.PASSWORDLESS_MOBILE_NOREPLY_NUMBER:
170170
# We need a sending number to send properly
171171

172-
from twilio.rest import Client
173-
twilio_client = Client(os.environ['TWILIO_ACCOUNT_SID'], os.environ['TWILIO_AUTH_TOKEN'])
172+
import africastalking
173+
174+
africastalking.initialize(os.environ['AFRICASTALKING_USERNAME'], os.environ['AFRICASTALKING_API'])
175+
sms = africastalking.SMS
174176

175177
to_number = getattr(user, api_settings.PASSWORDLESS_USER_MOBILE_FIELD_NAME)
176178
if to_number.__class__.__name__ == 'PhoneNumber':
177179
to_number = to_number.__str__()
178180

179-
twilio_client.messages.create(
180-
body=base_string % mobile_token.key,
181-
to=to_number,
182-
from_=api_settings.PASSWORDLESS_MOBILE_NOREPLY_NUMBER
181+
sms.send(base_string % mobile_token.key,[to_number],
182+
api_settings.PASSWORDLESS_MOBILE_NOREPLY_NUMBER
183183
)
184184
return True
185185
else:
186186
logger.debug("Failed to send token sms. Missing PASSWORDLESS_MOBILE_NOREPLY_NUMBER.")
187187
return False
188188
except ImportError:
189-
logger.debug("Couldn't import Twilio client. Is twilio installed?")
189+
logger.debug("Couldn't import Africastalking client. Is twilio installed?")
190190
return False
191191
except KeyError:
192192
logger.debug("Couldn't send SMS."
193-
"Did you set your Twilio account tokens and specify a PASSWORDLESS_MOBILE_NOREPLY_NUMBER?")
193+
"Did you set your Africastalking account tokens and specify a PASSWORDLESS_MOBILE_NOREPLY_NUMBER?")
194194
except Exception as e:
195195
logger.debug("Failed to send token SMS to user: {}. "
196-
"Possibly no mobile number on user object or the twilio package isn't set up yet. "
196+
"Possibly no mobile number on user object or the africastalking package isn't set up yet. "
197197
"Number entered was {}".format(user.id, getattr(user, api_settings.PASSWORDLESS_USER_MOBILE_FIELD_NAME)))
198198
logger.debug(e)
199199
return False

0 commit comments

Comments
 (0)