Created
December 8, 2015 14:52
-
-
Save nvh0412/35538e26d3d643a8af16 to your computer and use it in GitHub Desktop.
Send SMS with twilio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_message(cart) | |
message = "\nYour order:\n" | |
cart.orderlines.each do |orderline| | |
message += "* #{orderline.food.name} x #{orderline.quantity} - price: $#{orderline.unit_price}\n" | |
end | |
message += "\nTotal value: #{cart.orderlines.sum(:unit_price)}" | |
@client = Twilio::REST::Client.new ENV['TWILIO_SID'], ENV['TWILIO_TOKEN'] | |
@client.messages.create( | |
from: ENV['TWILIO_TEL'], | |
to: phone, | |
body: message | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment