last-resort 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/.rspec +3 -0
- data/README.md +23 -20
- data/Rakefile +5 -0
- data/bin/last-resort +39 -2
- data/last-resort.gemspec +9 -5
- data/lib/last-resort.rb +10 -17
- data/lib/last-resort/application.rb +120 -0
- data/lib/last-resort/commands.rb +159 -0
- data/lib/last-resort/config.rb +131 -0
- data/lib/last-resort/contextio.rb +1 -0
- data/lib/last-resort/scheduler.rb +29 -18
- data/lib/last-resort/twilio.rb +49 -47
- data/lib/last-resort/version.rb +2 -4
- data/lib/last-resort/webhooks.rb +6 -5
- data/spec/controller_spec.rb +106 -0
- data/spec/scheduler_spec.rb +77 -0
- data/spec/spec_helper.rb +11 -2
- data/support/Gemfile +3 -0
- data/support/config.ru +11 -0
- data/support/dot_env +7 -0
- data/support/dot_gitignore +1 -0
- metadata +88 -30
- data/config/config.rb +0 -35
- data/lib/last-resort/config-lang.rb +0 -74
- data/lib/last-resort/controller.rb +0 -78
@@ -1,78 +0,0 @@
|
|
1
|
-
# The exception session keeps state between twilio and context-io webhooks. Currently, the system can only handle
|
2
|
-
# one call session at a time, although we plan to change that in future versions.
|
3
|
-
exception_session = nil
|
4
|
-
|
5
|
-
|
6
|
-
# ====== CONTEXT-IO TWILIO ENDPOINTS
|
7
|
-
|
8
|
-
post '/matched_email' do
|
9
|
-
return if LastResort::Scheduler.new.get_matching_schedule.nil?
|
10
|
-
|
11
|
-
contact_names = LastResort::Scheduler.new.get_matching_schedule[:contacts]
|
12
|
-
contacts = []
|
13
|
-
contact_names.each do |name|
|
14
|
-
contacts.push(LastResort::Contact.new(name.to_s, CONFIG.contacts[name][:phone]))
|
15
|
-
end
|
16
|
-
|
17
|
-
hookData = JSON.parse(request_body.read)
|
18
|
-
exception_session = LastResort::ExceptionSession.new(contacts, hookData["message_data"]["subject"])
|
19
|
-
exception_session.notify
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
# ====== SINATRA TWILIO ENDPOINTS
|
24
|
-
|
25
|
-
# Service check method
|
26
|
-
get '/twilio' do
|
27
|
-
"twilio callbacks up and running!"
|
28
|
-
end
|
29
|
-
|
30
|
-
# Performs a test call based on the user's configuration
|
31
|
-
get '/twilio/test' do
|
32
|
-
exception_session.notify
|
33
|
-
end
|
34
|
-
|
35
|
-
# Method invoked to determine how the machine should interact with the user.
|
36
|
-
post '/twilio/call' do
|
37
|
-
content_type 'text/xml'
|
38
|
-
puts "call with #{params.inspect}"
|
39
|
-
|
40
|
-
if params[:CallStatus] == 'no-answer'
|
41
|
-
return Twilio::TwiML::Response.new { |r| r.Hangup }.text
|
42
|
-
end
|
43
|
-
|
44
|
-
response = Twilio::TwiML::Response.new do |r|
|
45
|
-
r.Say "Hello #{exception_session.callee_name}. The following error has occured: #{exception_session.description}", :voice => 'man'
|
46
|
-
r.Gather :numDigits => 1, :action => "http://#{HOST}/twilio/gather_digits" do |d|
|
47
|
-
d.Say "Please enter 1 to handle this bug that you probably didn't even create or 0 or hangup to go back to spending quality time with your family."
|
48
|
-
end
|
49
|
-
end
|
50
|
-
response.text
|
51
|
-
end
|
52
|
-
|
53
|
-
# Called when a user's call ends.
|
54
|
-
post '/twilio/status_callback' do
|
55
|
-
puts "status_callback with #{params.inspect}"
|
56
|
-
exception_session.call_next
|
57
|
-
end
|
58
|
-
|
59
|
-
# Callback to determine user input.
|
60
|
-
post '/twilio/gather_digits' do
|
61
|
-
puts "gather_digits with #{params.inspect}"
|
62
|
-
|
63
|
-
content_type 'text/xml'
|
64
|
-
digit = params[:Digits].to_i
|
65
|
-
|
66
|
-
case digit
|
67
|
-
when 1 # User handles call, so don't call anyone else
|
68
|
-
puts "User entered 1"
|
69
|
-
exception_session.end
|
70
|
-
response = Twilio::TwiML::Response.new do |r|
|
71
|
-
r.Say "Thank you for handling this exception. Goodbye.", :voice => 'man'
|
72
|
-
r.Hangup
|
73
|
-
end
|
74
|
-
return response.text
|
75
|
-
else # Hangup this call and go to the next person
|
76
|
-
return Twilio::TwiML::Response.new {|r| r.Hangup}.text
|
77
|
-
end
|
78
|
-
end
|