from twilio.rest import Client from secrets import randbits from constants import ACCOUNT_ID, TOKEN, SMS_SENDER from database.crud import save_otp async def connect_api(): account_sid = ACCOUNT_ID auth_token = TOKEN client = Client(account_sid, auth_token) return client async def generate_code(): bits = 16 code = randbits(bits) return code async 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)