@@ -169,31 +169,31 @@ def send_sms_with_callback_token(user, mobile_token, **kwargs):
169
169
if api_settings .PASSWORDLESS_MOBILE_NOREPLY_NUMBER :
170
170
# We need a sending number to send properly
171
171
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
174
176
175
177
to_number = getattr (user , api_settings .PASSWORDLESS_USER_MOBILE_FIELD_NAME )
176
178
if to_number .__class__ .__name__ == 'PhoneNumber' :
177
179
to_number = to_number .__str__ ()
178
180
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
183
183
)
184
184
return True
185
185
else :
186
186
logger .debug ("Failed to send token sms. Missing PASSWORDLESS_MOBILE_NOREPLY_NUMBER." )
187
187
return False
188
188
except ImportError :
189
- logger .debug ("Couldn't import Twilio client. Is twilio installed?" )
189
+ logger .debug ("Couldn't import Africastalking client. Is twilio installed?" )
190
190
return False
191
191
except KeyError :
192
192
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?" )
194
194
except Exception as e :
195
195
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. "
197
197
"Number entered was {}" .format (user .id , getattr (user , api_settings .PASSWORDLESS_USER_MOBILE_FIELD_NAME )))
198
198
logger .debug (e )
199
199
return False
0 commit comments