from twilio.rest import Client from constants import ACCOUNT_ID, SMS_SENDER, TOKEN from database.crud import fetch_user_by_email, fetch_user_by_key def create_twilio_client(account_sid, auth_token): client = Client(account_sid, auth_token) return client def send_otp(data, db): client = create_twilio_client(account_sid=ACCOUNT_ID, auth_token=TOKEN) user = fetch_user_by_key(data=data, db=db) message = "Your OTP code is {0}".format(user.otp) # client.messages.create(to=data.mobile, from_=SMS_SENDER, body=message) def resend_otp(data, db): client = create_twilio_client(account_sid=ACCOUNT_ID, auth_token=TOKEN) user = fetch_user_by_email(data=data, db=db) message = "Your OTP code is {0}".format(user.otp) # client.messages.create(to=data.mobile, from_=SMS_SENDER, body=message) return user