-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
39 lines (30 loc) · 1.11 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
require 'dotenv/load'
require 'sinatra'
require 'httparty'
require 'stripe'
require './app/api_gateway/base'
require './app/api_gateway/slack'
require './app/notifier/default'
require './app/notifier/slack'
require './app/receipt_email_sender'
require './app/slack_inviter'
require './app/typeform_response'
post '/' do
payload = request.body.read
if ENV['TYPEFORM_SECRET']
hash = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), ENV['TYPEFORM_SECRET'], payload)
actual_signature = 'sha256=' + Base64.strict_encode64(hash)
unless Rack::Utils.secure_compare(actual_signature, request.env['HTTP_Typeform-Signature'])
return halt 500, "Signatures don't match!"
end
end
params = JSON.parse(payload)
event = TypeformResponse.new(params)
if event.response?
first_name = event.answer_for_field(ENV['FIRST_NAME_FIELD_ID'])
last_name = event.answer_for_field(ENV['LAST_NAME_FIELD_ID'])
email = event.answer_for_field(ENV['EMAIL_FIELD_ID'])
SlackInviter.new.invite(first_name, last_name, email)
ReceiptEmailSender.new(event.form_id, event.response_token, email).send_email
end
end