Skip to content

Commit

Permalink
Add email notification for SMS messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gaffneyc committed Jan 16, 2025
1 parent 9ffb527 commit e2783ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions emailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ def voicemail_notification(url, duration, phone_number)
response = @sendgrid.client.mail._("send").post(request_body: message.to_json)
raise "#{response.status_code}: #{response.body}" if response.status_code != "202"
end

def sms_notification(phone_number, body)
message = SendGrid::Mail.new
message.from = SendGrid::Email.new(email: ENV["EMAIL_FROM"])
message.subject = "New SMS from #{phone_number}"

personalization = SendGrid::Personalization.new
personalization.add_to(SendGrid::Email.new(email: ENV["EMAIL_TO"]))
message.add_personalization(personalization)

message.add_content(SendGrid::Content.new(type: "text/plain", value: body))

response = @sendgrid.client.mail._("send").post(request_body: message.to_json)
raise "#{response.status_code}: #{response.body}" if response.status_code != "202"
end
end
8 changes: 5 additions & 3 deletions no_phone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def sound_url(sound)
post "/sms" do
content_type "text/xml"

Twilio::TwiML::MessagingResponse.new do |r|
r.message body: "Thanks for contacting [i] Collective Idea. Please visit http://collectiveidea.com"
end.to_s
Emailer.new.tap do |email|
email.sms_notification(params["From"], params["Body"])
end

Twilio::TwiML::MessagingResponse.new.to_s
end

# Caller selected a menu item
Expand Down

0 comments on commit e2783ed

Please sign in to comment.