-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
40 lines (31 loc) · 915 Bytes
/
app.rb
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
39
40
require 'rubygems'
require 'bundler'
Bundler.require
$: << File.expand_path('../', __FILE__)
Dir[__dir__ + "/lib/*.rb"].each { |file| require file }
require 'dotenv'
require 'sinatra/base'
Dotenv.load
$redis = Redis.new
module ApartmentBuzzer
class App < Sinatra::Application
# Twilio incoming call webhook.
get "/buzzer" do
content_type "text/xml"
buzzer_response.generate
end
# Incoming SMS messages.
post "/message" do
# Twilio SMS POST attributes: https://www.twilio.com/docs/api/twiml/sms/twilio_request#synchronous.
if params[:Body].match(/^.*(landlord|toggle|🎚|switch|yes|no).*$/i)
buzzer_response.toggle_landlord
else
Twilio::TwiML::MessagingResponse.new.message(body: "Wut 🤔").to_s
end
end
private
def buzzer_response
@buzzer_response ||= BuzzerResponse.new(params[:phone_number])
end
end
end