-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.rb
47 lines (37 loc) · 1.07 KB
/
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
41
42
43
44
45
46
47
require 'rubygems'
require 'sinatra/base'
require 'yaml'
require 'pusher'
class App < Sinatra::Base
set :public_folder, Proc.new { File.join(root, "public") }
config = YAML.load_file('./config.yml')
Pusher.app_id = config['pusher']['app_id']
Pusher.key = config['pusher']['app_key']
Pusher.secret = config['pusher']['app_secret']
get '/' do
@app_key = config['pusher']['app_key']
erb :index
end
post '/call' do
if( params['AccountSid'] != config['twilio']['account_sid'] )
status 401
else
Pusher['calls'].trigger('call_incoming', {
:from_number => '...' + params['From'][-4, 4],
:timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S")
})
end
end
post '/sms' do
if( params['AccountSid'] != config['twilio']['account_sid'] )
status 401
else
Pusher['sms'].trigger('sms_received', {
:from_number => '...' + params['From'][-4, 4],
:timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S"),
:text => params['Body']
})
end
end
run! if app_file == $0
end