Class: GoogleAssistant::Assistant
- Inherits:
- 
      Object
      
        - Object
- GoogleAssistant::Assistant
 
- Defined in:
- lib/google_assistant/assistant.rb
Constant Summary collapse
- InvalidIntent =
- Class.new(StandardError) 
- InvalidMessage =
- Class.new(StandardError) 
- InvalidInputPrompt =
- Class.new(StandardError) 
- InvalidPermission =
- Class.new(StandardError) 
- InvalidPermissionContext =
- Class.new(StandardError) 
- MissingRequestInputs =
- Class.new(StandardError) 
- MissingRequestIntent =
- Class.new(StandardError) 
Instance Attribute Summary collapse
- 
  
    
      #params  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute params. 
- 
  
    
      #response  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute response. 
Instance Method Summary collapse
- #arguments ⇒ Object
- #ask(prompt:, no_input_prompt: []) ⇒ Object
- #ask_for_permission(context:, permissions:) ⇒ Object
- #conversation ⇒ Object
- #device ⇒ Object
- 
  
    
      #initialize(params, response)  ⇒ Assistant 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Assistant. 
- #intent ⇒ Object
- #permission_granted? ⇒ Boolean
- #respond_to {|_self| ... } ⇒ Object
- #tell(message) ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(params, response) ⇒ Assistant
Returns a new instance of Assistant.
| 17 18 19 20 | # File 'lib/google_assistant/assistant.rb', line 17 def initialize(params, response) @params = params @response = response end | 
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
| 15 16 17 | # File 'lib/google_assistant/assistant.rb', line 15 def params @params end | 
#response ⇒ Object (readonly)
Returns the value of attribute response.
| 15 16 17 | # File 'lib/google_assistant/assistant.rb', line 15 def response @response end | 
Instance Method Details
#arguments ⇒ Object
| 34 35 36 37 38 | # File 'lib/google_assistant/assistant.rb', line 34 def arguments @_arguments ||= inputs[0]["arguments"].map do |argument| Argument.from(argument) end end | 
#ask(prompt:, no_input_prompt: []) ⇒ Object
| 73 74 75 76 77 78 79 80 81 | # File 'lib/google_assistant/assistant.rb', line 73 def ask(prompt:, no_input_prompt: []) raise InvalidInputPrompt if prompt.nil? || prompt.empty? no_input_prompt = [*no_input_prompt].compact prompt = build_input_prompt(prompt, no_input_prompt) expected_intent = build_expected_intent(StandardIntents::TEXT) build_ask_response(prompt, expected_intent) end | 
#ask_for_permission(context:, permissions:) ⇒ Object
| 83 84 85 86 87 88 89 90 91 92 93 94 | # File 'lib/google_assistant/assistant.rb', line 83 def (context:, permissions:) raise InvalidPermissionContext if context.nil? || context.empty? = [*].compact raise InvalidPermission unless Permission.valid?() raise InvalidPermission if .size == 0 prompt = build_input_prompt("placeholder for permission") expected_intent = build_expected_intent(StandardIntents::PERMISSION, , context) build_ask_response(prompt, expected_intent) end | 
#conversation ⇒ Object
| 47 48 49 | # File 'lib/google_assistant/assistant.rb', line 47 def conversation @_conversation ||= Conversation.new(conversation_params) end | 
#device ⇒ Object
| 55 56 57 | # File 'lib/google_assistant/assistant.rb', line 55 def device @_device ||= Device.new(device_params) end | 
#intent ⇒ Object
| 30 31 32 | # File 'lib/google_assistant/assistant.rb', line 30 def intent @_intent ||= Intent.new(intent_string) end | 
#permission_granted? ⇒ Boolean
| 40 41 42 43 44 45 | # File 'lib/google_assistant/assistant.rb', line 40 def arguments.any? do |argument| argument.is_a?(PermissionArgument) && argument. end end | 
#respond_to {|_self| ... } ⇒ Object
| 22 23 24 25 26 27 28 | # File 'lib/google_assistant/assistant.rb', line 22 def respond_to(&block) yield(self) response.headers["Google-Assistant-API-Version"] = "v1" intent.call end | 
#tell(message) ⇒ Object
| 59 60 61 62 63 64 65 66 67 68 69 70 71 | # File 'lib/google_assistant/assistant.rb', line 59 def tell() raise InvalidMessage if .nil? || .empty? final_response = { speech_response: {} } if is_ssml?() final_response[:speech_response][:ssml] = else final_response[:speech_response][:text_to_speech] = end build_response(nil, false, nil, final_response) end |