Skip to content

Instantly share code, notes, and snippets.

@dsasse07
Created January 10, 2021 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsasse07/84e165ccc8400e2ad69ccb23de8c223a to your computer and use it in GitHub Desktop.
Save dsasse07/84e165ccc8400e2ad69ccb23de8c223a to your computer and use it in GitHub Desktop.
Incorporating Twilio send SMS code snippet into a module for inclusion in necessary classes.
require 'dotenv/load' #This ruby gem will is what we will be using to secure our Twilio credentials
require 'twilio-ruby'
module TwilioControls
# To set up environmental variables, see http://twil.io/secure
@@account_sid = ENV['TWILIO_ACCOUNT_SID'] #This is used in conjuction with the 'dotenv/load' gem
@@auth_token = ENV['TWILIO_AUTH_TOKEN'] #This is used in conjuction with the 'dotenv/load' gem
@@client = Twilio::REST::Client.new(@@account_sid, @@auth_token)
@@from = '+1##########' # Your Twilio number
to = '+1##########' # Phone number to receive the text message
def send_sms(to_phone_number, message)
@@client.messages.create(
from: @@from,
to: to_phone_number,
body: message
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment