Skip to content

Instantly share code, notes, and snippets.

@nvh0412
Created December 8, 2015 14:52
Show Gist options
  • Save nvh0412/35538e26d3d643a8af16 to your computer and use it in GitHub Desktop.
Save nvh0412/35538e26d3d643a8af16 to your computer and use it in GitHub Desktop.
Send SMS with twilio
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