from twilio.rest import Client from secrets import randbits from constants import ACCOUNT_ID, TOKEN, SMS_SENDER from database.crud import save_otp def connect_api(): account_sid = ACCOUNT_ID auth_token = TOKEN client = Client(account_sid, auth_token) return client def generate_code(): bits = 16 code = randbits(bits) return code def send_otp(receiver): client = connect_api() code = generate_code() message = "Your OTP code is {0}".format(code) client.messages.create(to=receiver, from_=SMS_SENDER, body=message) save_otp(receiver, code)