Working on a Rails project that needs to send a link to a record to someone via SMS.
/services/twilio_client.rb:
def send_text(job, message)
client = Twilio::REST::Client.new account_sid, auth_token
client.messages.create(
to: job.cell_number,
from: phone_number,
body: message
)
end
From Controller:
if job.save?
message = "#{@job.company} worker, you've got a new job. See it here:"
TwilioClient.new.send_text(@job, message)
In an ideal world, I could send them a link directly to the job via SMS, but Twilio won't accept ruby code as a media_url
and dropping #{@job}
in the message results in receiving the object #<Job:0x00007f0b60818338>
in the SMS.
Clearly, this is a syntax issue, but try as I might I can't find a solution in the docs, the twilio-ruby gem, or examples published on the interweb.