Class: Hg::Assistant::Controller
- Inherits:
-
Controller
- Object
- Controller
- Hg::Assistant::Controller
- Includes:
- ActionView::Helpers::SanitizeHelper
- Defined in:
- lib/hg/assistant/controller.rb
Overview
TODO: Move Messenger-specific behavior out of base controller class.
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#merged_context ⇒ ActiveSupport::HashWithIndifferentAccess
Generate a context based on merging the params into the user's current context.
-
#respond(speech_response, display_text: nil) ⇒ Object
TODO: allow specifying reprompts.
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
7 8 9 |
# File 'lib/hg/assistant/controller.rb', line 7 def response @response end |
Instance Method Details
#merged_context ⇒ ActiveSupport::HashWithIndifferentAccess
Generate a context based on merging the params into the user's current context.
37 38 39 40 41 42 43 |
# File 'lib/hg/assistant/controller.rb', line 37 def merged_context context_field = Hg::Assistant::Bot.config.user_context_field ActiveSupport::HashWithIndifferentAccess .new((user.public_send(context_field) || {}) .merge(params)) end |
#respond(speech_response, display_text: nil) ⇒ Object
TODO: allow specifying reprompts
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hg/assistant/controller.rb', line 11 def respond(speech_response, display_text: nil) # Clean up speech responses: fix heredocs, remove linebreaks, # fix multiple spaces. speech_response = speech_response.strip_heredoc.squish # Use the speech response as the display text, if none provided. display_text = speech_response || display_text # Remove any SSML tags from the display text. display_text = (display_text).squish # Generate a proper webhook fulfillment response object. { speech: speech_response, display_text: display_text, data: { google: { expect_user_response: false } } } end |