Send Text Message and Voice Message Using Twilio with Rails 4

Hello Guys,

Send text message and voice message with call using twilio with rails 4

here my steps:

Step1: Need to add this into you gem file

gem ‘twilio-ruby’, ‘~> 4.1.0’ (do bundle install)

Step 2: set your twilio application and secret key in your secret.yml file and create method

twilio_account_sid: XXXXXXXXXXX
twilio_auth_token: XXXXXXXXXXX


Step 3: creating Method for sending the Text Message

# Method for giving the twillo credential to send message to phone number def send_otp
def send_otp            Twilio::REST::Client.new(Rails.application.secrets.twilio_account_sid,Rails.application.secrets.twilio_auth_token)
end

  # Method for generating random otp number
  def generated_otp
     otp_number = rand(0000..9999).to_s.rjust(4, “0”)
 end

 # Method for checking the onfirmation of the particular mobiler number otp
 def confirm_verify_number
    # make it session nil and send otp request to phone number
    send_request = send_otp_request
 end

  # Method for send otp request to the phone number
  def send_otp_request
     # generating the otp number
     otp_number = generated_otp
     send_otp.account.messages.create(to: “+1″<<#{Your Phone Number},from: “#{Twilio Number}”,body: otp_number.to_i)
 end

it will send message to your phone

Step 4: creating the method for creating the voice message(need follow same step last method need to replace with below method)

def send_otp_request
      # generating the otp number
     otp_number = generated_otp
    # create call
   send_otp.account.calls.create(
:from => ‘+16467367408’,:to => “+1″+#{Phone Number}r,:url =>     “http://twimlets.com/echoTwiml=%3CResponse%3E%3CSay%3EThank+you+to+be+part+of+adsonrides.com+your+number+is+#{otp_number[0]}+#{otp_number[1]}+#{otp_number[2]}+#{otp_number[3]}+once+again+#{otp_number[0]}+#{otp_number[1]}+#{otp_number[2]}+#{otp_number[3]}+Please+Do+Not+Share+Number+With+Any+One+Thank+You+Enjoy+Our+Services+Good+Bye.%3C%2FSay%3E%3C%2FResponse%3E”)

end

enjoy this blog without using any twilio setting

Thank You !!!!!

About the author

Being the CEO and Founder of ClecoTech International, Mr. Ashish Prajapati is dedicated towards his aim of mentoring young startups into a full-fledged businesses. He is helping startups from America, Europe, India, and various other countries through proper guidance and the use of latest technologies to develop their innovation and ideas into definite realities.

Leave a Reply

Your email address will not be published. Required fields are marked *