2020-09-17 17:36:15 +02:00
|
|
|
from twilio.rest import Client
|
|
|
|
|
|
|
|
from constants import ACCOUNT_ID, SMS_SENDER, TOKEN
|
2020-09-28 18:19:59 +02:00
|
|
|
from database.crud import fetch_user_by_key
|
2020-03-18 20:56:06 +01:00
|
|
|
|
|
|
|
|
2020-09-17 17:36:15 +02:00
|
|
|
def create_twilio_client(account_sid, auth_token):
|
2020-03-18 20:56:06 +01:00
|
|
|
client = Client(account_sid, auth_token)
|
|
|
|
return client
|
|
|
|
|
|
|
|
|
2020-09-22 13:59:29 +02:00
|
|
|
def send_otp(data, db):
|
2020-09-17 17:36:15 +02:00
|
|
|
client = create_twilio_client(account_sid=ACCOUNT_ID, auth_token=TOKEN)
|
2020-09-28 18:19:59 +02:00
|
|
|
user = fetch_user_by_key(data=data, db=db)
|
|
|
|
message = "Your OTP code is {0}".format(user.otp)
|
2020-09-22 13:59:29 +02:00
|
|
|
client.messages.create(to=data.mobile, from_=SMS_SENDER, body=message)
|