|
1
|
|
|
# frozen_string_literal: true |
|
2
|
|
|
|
|
3
|
|
|
# This program is an Alexa skill web service for Mental Health Assessments. |
|
4
|
|
|
# It is a Sinatra web application that uses Ralyxa to communicate requests and responses to Amazon. |
|
5
|
|
|
# It contains functionality to import and manage surveys and instruments. |
|
6
|
|
|
# It allows an Amazon user to take an assessment by saying "open Mental Health". |
|
7
|
|
|
# This web application sits behind the https://github.com/stevenbeales/mental-health Alexa skill |
|
8
|
|
|
# |
|
9
|
|
|
# Author:: Steven Beales (mailto:[email protected]) |
|
10
|
|
|
# Copyright:: Copyright (c) 2018 Ardint |
|
11
|
|
|
# License:: MIT |
|
12
|
|
|
|
|
13
|
|
|
ENV['RACK_ENV'] ||= 'development' |
|
14
|
|
|
|
|
15
|
|
|
require 'sinatra' |
|
16
|
|
|
require 'ralyxa' |
|
17
|
|
|
require 'sinatra-initializers' |
|
18
|
|
|
require_relative 'config/db' |
|
19
|
|
|
require_relative 'app/services/init' |
|
20
|
|
|
require_relative 'app/models/init' |
|
21
|
|
|
|
|
22
|
|
|
configure { set :server, :puma } |
|
23
|
|
|
set :app_file, __FILE__ |
|
24
|
|
|
set :root, File.dirname(__FILE__) |
|
25
|
|
|
set :public_folder, File.dirname(__FILE__) + '/public' |
|
26
|
|
|
|
|
27
|
|
|
# This class is the main entry point to Application. |
|
28
|
|
|
# Takes an incoming Alexa requests and dispatches |
|
29
|
|
|
# to a matching intent in intents folder |
|
30
|
|
|
class App < Sinatra::Base |
|
31
|
|
|
|
|
32
|
|
|
# Register initializers a la Rails |
|
33
|
|
|
register Sinatra::Initializers |
|
34
|
|
|
|
|
35
|
|
|
# Entry point for requests from Amazon Alexa. |
|
36
|
|
|
# The incoming requests are dispatched to intents in the intents folder by Ralyxa. |
|
37
|
|
|
post '/' do |
|
38
|
|
|
begin |
|
39
|
|
|
Ralyxa::Skill.handle(request) |
|
40
|
|
|
rescue StandardError => exception |
|
41
|
|
|
Bugsnag.notify(exception) |
|
42
|
|
|
end |
|
43
|
|
|
end |
|
44
|
|
|
end |
|
45
|
|
|
|