-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_mail_gun_ruby.rb
More file actions
39 lines (33 loc) · 888 Bytes
/
example_mail_gun_ruby.rb
File metadata and controls
39 lines (33 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require 'sinatra'
require 'twilio-ruby'
require 'puma'
class ExampleMailGunRuby < Sinatra::Base
configure do
set :notify_number, ENV['NOTIFY_NUMBER']
set :twilio_number, ENV['TWILIO_NUMBER']
set :twilio_sid, ENV['TWILIO_SID']
set :twilio_token, ENV['TWILIO_TOKEN']
end
def twilio_auth
account_sid = settings.twilio_sid
auth_token = settings.twilio_token
client = Twilio::REST::Client.new account_sid, auth_token
end
def send_sms_with_twilio(number, subject)
client = twilio_auth
client.account.sms.messages.create(
:from => "+#{settings.twilio_number}",
:to => "+#{number}",
:body => subject
)
end
def notify(subject)
send_sms_with_twilio(settings.notify_number, subject)
end
post '/new_email' do
mail = params
if mail['subject'].include? "[IMPORTANT]"
notify("IMPORTANT EMAIL RECEIVED #{mail['subject']}")
end
end
end