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)