OTP SMS Mobile Verification in Ruby

Step 1: Install Required Gems

gem 'twilio-ruby', '~> 5.47', '>= 5.47.0'

Step 2: Configure Twilio

require 'twilio-ruby'

account_sid = 'your_account_sid'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

Step 3: Generate and Send OTP

otp = rand.to_s[2..5]
@client.messages.create(
  from: 'your_twilio_number',
  to: 'recipient_number',
  body: "Your OTP is: #{otp}"
)

Step 4: Verify OTP

# Compare the user input OTP with the generated OTP
if user_input_otp == otp
  # OTP is valid
else
  # OTP is invalid
end