diff --git a/.gitignore b/.gitignore index ab05049..2f2d1ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store -*.gem \ No newline at end of file +*.gem +samples/* diff --git a/README.md b/README.md index 8d605c4..f4d288a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ +# Currently upgrading + +I am currently upgrading this gem to work with Google Assistant API v2. Until that is complete, the master branch will not be fully functional. See [v1.0.0](https://github.com/armilam/google-assistant-ruby/tree/v1.0.0) of this gem for the version that works with Google Assistant API v1. + # Google Assistant Ruby Write Google Assistant actions in Ruby. -GoogleAssistant parses Google Assistant requests and provides the framework to respond appropriately. It works with the Google Assistant API v1. +GoogleAssistant parses Google Assistant requests and provides the framework to respond appropriately. It works with the Google Assistant API v2. ## Installation @@ -33,8 +37,8 @@ class GoogleAssistantController < ApplicationController assistant_response = GoogleAssistant.respond_to(params, response) do |assistant| assistant.intent.main do assistant.ask( - prompt: "Hi there! Say something, please.", - no_input_prompt: [ + "Hi there! Say something, please.", + [ "If you said something, I didn't hear you.", "Did you say something?" ] @@ -88,8 +92,8 @@ Request user input by sending an `ask` response. Send a prompt and a set of foll ```rb assistant.intent.main do assistant.ask( - prompt: "Hi there! Say something, please.", # The voice prompt the user will hear. - no_input_prompt: [ + "Hi there! Say something, please.", # The voice prompt the user will hear. + [ "If you said something, I didn't hear you.", # You can provide a number of "no input prompts". A random "Did you say something?" # one will be spoken if the user takes too long to respond. ] @@ -142,8 +146,8 @@ GoogleAssistant.respond_to(params, response) do |assistant| assistant.conversation.state = "asking favorite color" assistant.ask( - prompt: "What is your favorite color?", - no_input_prompt: ["What did you say your favorite color is?"] + "What is your favorite color?", + ["What did you say your favorite color is?"] ) end @@ -154,8 +158,8 @@ GoogleAssistant.respond_to(params, response) do |assistant| assistant.conversation.state = "asking lucky number" assistant.ask( - prompt: "What is your lucky number?", - no_input_prompt: ["What did you say your lucky number is?"] + "What is your lucky number?", + ["What did you say your lucky number is?"] ) elsif assistant.conversation.state == "asking lucky number" favorite_color = assistant.conversation.data["favorite_color"] @@ -188,7 +192,7 @@ Request the user's name. This will result in a prompt to the user like: ```rb assistant.intent.main do # Request the user's name - assistant.ask_for_permission(context: "So that I can address you by name", permissions: GoogleAssistant::Permission::NAME) + assistant.ask_for_permission("So that I can address you by name", GoogleAssistant::Permission::NAME) end assistant.intent.permission do @@ -211,7 +215,7 @@ Request the device's zip code and city. This will result in a prompt to the user ```rb assistant.intent.main do # Request the device's zip code and city - assistant.ask_for_permission(context: "To provide weather information for where you live", permissions: GoogleAssistant::Permission::DEVICE_COARSE_LOCATION) + assistant.ask_for_permission("To provide weather information for where you live", GoogleAssistant::Permission::DEVICE_COARSE_LOCATION) end assistant.intent.permission do @@ -233,7 +237,7 @@ Request the device's precise location. This will result in a prompt to the user ```rb assistant.intent.main do # Request the device's precise location - assistant.ask_for_permission(context: "So that I can find out where you sleep at night", permissions: GoogleAssistant::Permission::DEVICE_PRECISE_LOCATION) + assistant.ask_for_permission("So that I can find out where you sleep at night", GoogleAssistant::Permission::DEVICE_PRECISE_LOCATION) end assistant.intent.permission do @@ -260,24 +264,38 @@ You can use any hosting platform. 3. Deploy your app to the web. Heroku is a good choice. See [Heroku's documentation](https://devcenter.heroku.com/articles/getting-started-with-ruby#introduction) for more info on how to do this. 4. Add an `action.json` file at the root of your project. + ```json { - "versionLabel": "1.0.0", - "agentInfo": { - "languageCode": "en-US", - "projectId": "your-google-project-id", + "manifest": { + "displayName": "My Google Assistant", + "invocationName": "my action", + "shortDescription": "I made an assistant", + "longDescription": "This assistant makes use of the google_assistant Ruby gem. It's very neat.", + "sampleInvocation": [ + "talk to my action" + ], "voiceName": "male_1" }, "actions": [ { - "initialTrigger": { - "intent": "assistant.intent.action.MAIN" + "description": "The main intent", + "name": "MAIN", + "fulfillment": { + "conversationName": "my_action" }, - "httpExecution": { - "url": "https://yourapp.domain.com/path-to-your-assistant" + "intent": { + "name": "actions.intent.MAIN" } } - ] + ], + "conversations": { + "my_action": { + "name": "my_action", + "url": "https://yourapp.domain.com/path-to-your-assistant", + "fulfillmentApiVersion": 2 + } + } } ``` @@ -293,7 +311,7 @@ You can use any hosting platform. ## Authentication -You can require users to log in to your service before using your assistant. Read about it in [Google's documentation](https://developers.google.com/actions/develop/identity/oauth2-code-flow). The basic flow is this: +You can require users to log in to your service before using your assistant. Read about it in [Google's documentation](https://developers.google.com/actions/identity/account-linking#account_linking_at_invocation_time). The basic flow is this: 1. User tries to talk to your assistant 2. Google tells the user they need to sign in, which they can do via the Home app on their phone @@ -302,15 +320,14 @@ You can require users to log in to your service before using your assistant. Rea 5. Google stores the user's Oauth access and refresh tokens 6. For each subsequent request the user makes to your assistant, Google sends the user's access token so you can identify the user -In order to set this up in your assistant, the basic instructions are as follows. Read Google's documentation for the full details. +When you have everything set up, you can find the user's access token for your app in `assistant.user.access_token`. + +#### Account linking during the conversation -1. Implement Oauth in your application -2. Set up an Oauth client in the [Google Developer Console](https://console.developers.google.com) -3. In the application's `action.json` file, set up account linking according to [Google's Instructions](https://developers.google.com/actions/develop/identity/account-linking#enabling_account_linking) -4. Use `assistant.user.access_token` to identify the user +This gem doesn't yet support account linking during the conversation. This would be neat to have. See [#32](https://github.com/armilam/google-assistant-ruby/issues/32). ## More information -Check out Google's instructions at https://developers.google.com/actions/develop/sdk/getting-started for more detail on writing and testing a Google Assistant action. +Check out Google's instructions at https://developers.google.com/actions/sdk/ for more detail on writing and testing a Google Assistant action. Check out https://github.com/armilam/google_assistant_example for a simple example of this gem in action. diff --git a/lib/google_assistant/argument.rb b/lib/google_assistant/argument.rb index 1aaffb7..83031db 100644 --- a/lib/google_assistant/argument.rb +++ b/lib/google_assistant/argument.rb @@ -6,9 +6,9 @@ class Argument def self.from(opts) case opts["name"] - when "permission_granted" + when "PERMISSION" PermissionArgument.new(opts) - when "text" + when "TEXT" TextArgument.new(opts) else Argument.new(opts) @@ -17,8 +17,8 @@ def self.from(opts) def initialize(opts) @name = opts["name"] - @raw_text = opts["raw_text"] - @text_value = opts["text_value"] + @raw_text = opts["rawText"] + @text_value = opts["textValue"] end end diff --git a/lib/google_assistant/assistant.rb b/lib/google_assistant/assistant.rb index 6bd3743..2b731ec 100644 --- a/lib/google_assistant/assistant.rb +++ b/lib/google_assistant/assistant.rb @@ -15,7 +15,7 @@ def initialize(params, response) def respond_to(&block) yield(self) - response.headers["Google-Assistant-API-Version"] = "v1" + response.headers["Google-Assistant-API-Version"] = "v2" intent.call end diff --git a/lib/google_assistant/conversation.rb b/lib/google_assistant/conversation.rb index 83271a2..92aa347 100644 --- a/lib/google_assistant/conversation.rb +++ b/lib/google_assistant/conversation.rb @@ -13,9 +13,9 @@ class Type attr_reader :id, :type, :dialog_state def initialize(opts) - @id = opts["conversation_id"] + @id = opts["conversationId"] @type = opts["type"] - @dialog_state = DialogState.new(opts["conversation_token"]) + @dialog_state = DialogState.new(opts["conversationToken"]) end def state diff --git a/lib/google_assistant/device.rb b/lib/google_assistant/device.rb index a54ec26..7da7c91 100644 --- a/lib/google_assistant/device.rb +++ b/lib/google_assistant/device.rb @@ -12,11 +12,11 @@ def city end def zip_code - location["zip_code"] + location["zipCode"] end def formatted_address - location["formatted_address"] + location["formattedAddress"] end def latitude diff --git a/lib/google_assistant/intent.rb b/lib/google_assistant/intent.rb index 6cb4063..e123605 100644 --- a/lib/google_assistant/intent.rb +++ b/lib/google_assistant/intent.rb @@ -4,13 +4,13 @@ module GoogleAssistant class StandardIntents # Assistant fires MAIN intent for queries like [talk to $action]. - MAIN = "assistant.intent.action.MAIN" + MAIN = "actions.intent.MAIN" # Assistant fires TEXT intent when action issues ask intent. - TEXT = "assistant.intent.action.TEXT" + TEXT = "actions.intent.TEXT" # Assistant fires PERMISSION intent when action invokes askForPermission. - PERMISSION = "assistant.intent.action.PERMISSION" + PERMISSION = "actions.intent.PERMISSION" end class Intent diff --git a/lib/google_assistant/response/ask_for_permission.rb b/lib/google_assistant/response/ask_for_permission.rb index 51e21fa..99003cd 100644 --- a/lib/google_assistant/response/ask_for_permission.rb +++ b/lib/google_assistant/response/ask_for_permission.rb @@ -19,7 +19,7 @@ def to_json expected_intent = build_expected_intent(StandardIntents::PERMISSION, permissions, context) expected_inputs = build_expected_inputs(expected_intent: expected_intent) - response[:expected_inputs] = expected_inputs + response[:expectedInputs] = expected_inputs response end diff --git a/lib/google_assistant/response/base.rb b/lib/google_assistant/response/base.rb index 0d874dc..01e3016 100644 --- a/lib/google_assistant/response/base.rb +++ b/lib/google_assistant/response/base.rb @@ -12,8 +12,8 @@ def initialize(conversation = nil) def to_json(expect_user_response) response = {} - response[:conversation_token] = conversation.dialog_state.to_json if conversation&.dialog_state - response[:expect_user_response] = expect_user_response + response[:conversationToken] = conversation.dialog_state.to_json if conversation&.dialog_state + response[:expectUserResponse] = expect_user_response response end @@ -32,8 +32,8 @@ def build_input_prompt(prompt, no_input_prompts) end { - initial_prompts: initial_prompts, - no_input_prompts: no_input_prompts + initialPrompts: initial_prompts, + noInputPrompts: no_input_prompts } end @@ -41,8 +41,8 @@ def build_expected_inputs(prompt: "placeholder", no_input_prompts: [], expected_ prompt = build_input_prompt(prompt, no_input_prompts) expected_inputs = [{ - input_prompt: prompt, - possible_intents: [expected_intent] + inputPrompt: prompt, + possibleIntents: [expected_intent] }] end @@ -56,11 +56,10 @@ def build_expected_intent(intent, permissions = nil, context = nil) raise GoogleAssistant::InvalidPermission if permissions.empty? raise GoogleAssistant::InvalidPermission unless GoogleAssistant::Permission.valid?(permissions) - expected_intent[:input_value_spec] = { - permission_value_spec: { - opt_context: context, - permissions: permissions - } + expected_intent[:inputValueData] = { + "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec", + optContext: context, + permissions: permissions } end @@ -70,7 +69,7 @@ def build_expected_intent(intent, permissions = nil, context = nil) private def prompt_type(text) - is_ssml?(text) ? :ssml : :text_to_speech + is_ssml?(text) ? :ssml : :textToSpeech end def is_ssml?(text) diff --git a/lib/google_assistant/response/input_prompt.rb b/lib/google_assistant/response/input_prompt.rb index 01a3b87..74687e3 100644 --- a/lib/google_assistant/response/input_prompt.rb +++ b/lib/google_assistant/response/input_prompt.rb @@ -19,7 +19,7 @@ def to_json expected_intent = build_expected_intent(StandardIntents::TEXT) expected_inputs = build_expected_inputs(prompt: prompt, no_input_prompts: no_input_prompts, expected_intent: expected_intent) - response[:expected_inputs] = expected_inputs + response[:expectedInputs] = expected_inputs response end diff --git a/lib/google_assistant/response/speech_response.rb b/lib/google_assistant/response/speech_response.rb index 03dff74..11d3f43 100644 --- a/lib/google_assistant/response/speech_response.rb +++ b/lib/google_assistant/response/speech_response.rb @@ -21,9 +21,9 @@ def to_json speech_response = if is_ssml?(message) { ssml: message } else - { text_to_speech: message } + { textToSpeech: message } end - response[:final_response] = { speech_response: speech_response } + response[:finalResponse] = { speechResponse: speech_response } response end diff --git a/lib/google_assistant/user.rb b/lib/google_assistant/user.rb index 8fca476..9ad767f 100644 --- a/lib/google_assistant/user.rb +++ b/lib/google_assistant/user.rb @@ -5,21 +5,22 @@ class User attr_reader :id, :profile, :access_token def initialize(opts) - @id = opts["user_id"] + @id = opts["userId"] @profile = opts["profile"] || {} - @access_token = opts["access_token"] + @access_token = opts["accessToken"] + @locale = opts["locale"] end def display_name - profile["display_name"] + profile["displayName"] end def given_name - profile["given_name"] + profile["givenName"] end def family_name - profile["family_name"] + profile["familyName"] end end end diff --git a/lib/google_assistant/version.rb b/lib/google_assistant/version.rb index 6b8576c..ec53154 100644 --- a/lib/google_assistant/version.rb +++ b/lib/google_assistant/version.rb @@ -1,3 +1,3 @@ module GoogleAssistant - VERSION = "1.0.0" + VERSION = "2.0.0" end diff --git a/test/fixtures/coarse_location_granted.json b/test/fixtures/coarse_location_granted.json index 128c56e..c20be14 100644 --- a/test/fixtures/coarse_location_granted.json +++ b/test/fixtures/coarse_location_granted.json @@ -1,33 +1,33 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", - "type": 2 + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", + "type": "ACTIVE" }, "inputs": [ { - "intent": "assistant.intent.action.PERMISSION", - "raw_inputs": [ + "intent": "actions.intent.PERMISSION", + "rawInputs": [ { - "input_type": 2, + "inputType": "KEYBOARD", "query": "sure" } ], "arguments": [ { - "name": "permission_granted", - "raw_text": "sure", - "text_value": "true" + "name": "PERMISSION", + "rawText": "sure", + "textValue": "true" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" }, "device": { "location": { - "zip_code": "94043", + "zipCode": "94043", "city": "Mountain View" } } diff --git a/test/fixtures/empty_arguments_request.json b/test/fixtures/empty_arguments_request.json index a1f1f5a..bbfdadb 100644 --- a/test/fixtures/empty_arguments_request.json +++ b/test/fixtures/empty_arguments_request.json @@ -1,21 +1,22 @@ { "conversation": { - "conversation_id": "1234567890", - "type": 1 + "conversationId": "1234567890", + "type": "NEW" }, "inputs": [ { "arguments": [], - "intent": "assistant.intent.action.MAIN", - "raw_inputs": [ + "intent": "actions.intent.MAIN", + "rawInputs": [ { - "input_type": 2, + "inputType": "KEYBOARD", "query": "Google Assistant Ruby Test" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "locale": "en-US", + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/main_intent_request.json b/test/fixtures/main_intent_request.json index a1f1f5a..0002047 100644 --- a/test/fixtures/main_intent_request.json +++ b/test/fixtures/main_intent_request.json @@ -1,21 +1,21 @@ { "conversation": { - "conversation_id": "1234567890", - "type": 1 + "conversationId": "1234567890", + "type": "NEW" }, "inputs": [ { - "arguments": [], - "intent": "assistant.intent.action.MAIN", - "raw_inputs": [ + "intent": "actions.intent.MAIN", + "rawInputs": [ { - "input_type": 2, + "inputType": "KEYBOARD", "query": "Google Assistant Ruby Test" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "locale": "en-US", + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/permission_denied.json b/test/fixtures/permission_denied.json index 5fb2135..6810699 100644 --- a/test/fixtures/permission_denied.json +++ b/test/fixtures/permission_denied.json @@ -1,28 +1,29 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", - "type": 2 + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", + "type": "ACTIVE" }, "inputs": [ { - "intent": "assistant.intent.action.PERMISSION", - "raw_inputs": [ + "intent": "actions.intent.PERMISSION", + "rawInputs": [ { - "input_type": 2, + "inputType": "KEYBOARD", "query": "nope" } ], "arguments": [ { - "name": "permission_granted", - "raw_text": "nope", - "text_value": "false" + "name": "PERMISSION", + "rawText": "nope", + "textValue": "false" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "locale": "en-US", + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/precise_location_granted.json b/test/fixtures/precise_location_granted.json index e837705..9a9b4b1 100644 --- a/test/fixtures/precise_location_granted.json +++ b/test/fixtures/precise_location_granted.json @@ -1,29 +1,30 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", - "type": 2 + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", + "type": "ACTIVE" }, "inputs": [ { - "intent": "assistant.intent.action.PERMISSION", - "raw_inputs": [ + "intent": "actions.intent.PERMISSION", + "rawInputs": [ { - "input_type": 2, + "inputType": "KEYBOARD", "query": "sure" } ], "arguments": [ { - "name": "permission_granted", - "raw_text": "sure", - "text_value": "true" + "name": "PERMISSION", + "rawText": "sure", + "textValue": "true" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "locale": "en-US", + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" }, "device": { "location": { @@ -31,8 +32,8 @@ "latitude": 37.422, "longitude": -122.084 }, - "formatted_address": "1600 Amphitheatre Parkway, Mountain View, CA 94043, United States", - "zip_code": "94043", + "formattedAddress": "1600 Amphitheatre Parkway, Mountain View, CA 94043, United States", + "zipCode": "94043", "city": "Mountain View" } } diff --git a/test/fixtures/single_argument_request.json b/test/fixtures/single_argument_request.json index 86d4bff..5987e83 100644 --- a/test/fixtures/single_argument_request.json +++ b/test/fixtures/single_argument_request.json @@ -1,28 +1,29 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", - "type": 2 + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", + "type": "ACTIVE" }, "inputs": [ { "arguments": [ { - "name": "text", - "raw_text": "this is some raw text", - "text_value": "this is a text value" + "name": "TEXT", + "rawText": "this is some raw text", + "textValue": "this is a text value" } ], - "intent": "assistant.intent.action.TEXT", - "raw_inputs": [ + "intent": "actions.intent.TEXT", + "rawInputs": [ { - "input_type": 2, + "inputType": "KEYBOARD", "query": "this is a query" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "locale": "en-US", + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/text_intent_request.json b/test/fixtures/text_intent_request.json index 27485ff..3ae2070 100644 --- a/test/fixtures/text_intent_request.json +++ b/test/fixtures/text_intent_request.json @@ -1,28 +1,29 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", - "type": 2 + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", + "type": "ACTIVE" }, "inputs": [ { "arguments": [ { - "name": "text", - "raw_text": "this is some input", - "text_value": "this is some input" + "name": "TEXT", + "rawText": "this is some input", + "textValue": "this is some input" } ], - "intent": "assistant.intent.action.TEXT", - "raw_inputs": [ + "intent": "actions.intent.TEXT", + "rawInputs": [ { - "input_type": 2, + "inputType": "KEYBOARD", "query": "this is some input" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "locale": "en-US", + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/user_name_granted.json b/test/fixtures/user_name_granted.json index f621a8f..fcc2291 100644 --- a/test/fixtures/user_name_granted.json +++ b/test/fixtures/user_name_granted.json @@ -1,33 +1,34 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", - "type": 2 + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", + "type": "ACTIVE" }, "inputs": [ { - "intent": "assistant.intent.action.PERMISSION", - "raw_inputs": [ + "intent": "actions.intent.PERMISSION", + "rawInputs": [ { - "input_type": 2, + "inputType": "KEYBOARD", "query": "sure" } ], "arguments": [ { - "name": "permission_granted", - "raw_text": "sure", - "text_value": "true" + "name": "PERMISSION", + "rawText": "sure", + "textValue": "true" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=", + "locale": "en-US", + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=", "profile": { - "display_name": "John Smith", - "given_name": "John", - "family_name": "Smith" + "displayName": "John Smith", + "givenName": "John", + "familyName": "Smith" } } } diff --git a/test/google_assistant/test_argument.rb b/test/google_assistant/test_argument.rb index 9955472..5659ee5 100644 --- a/test/google_assistant/test_argument.rb +++ b/test/google_assistant/test_argument.rb @@ -2,14 +2,14 @@ require "google_assistant/argument" describe GoogleAssistant::Argument do - let(:params) { { "name" => "a name", "raw_text" => "some raw text", "text_value" => "some text value" } } + let(:params) { { "name" => "a name", "rawText" => "some raw text", "textValue" => "some text value" } } subject { GoogleAssistant::Argument.new(params) } describe "#from" do subject { GoogleAssistant::Argument.from(params) } - describe "when name is permission_granted" do - let(:params) { { "name" => "permission_granted" } } + describe "when name is PERMISSION" do + let(:params) { { "name" => "PERMISSION" } } it "returns a PermissionArgument object" do assert_equal(GoogleAssistant::PermissionArgument, subject.class) @@ -17,7 +17,7 @@ end describe "when name is text" do - let(:params) { { "name" => "text" } } + let(:params) { { "name" => "TEXT" } } it "returns a TextArgument object" do assert_equal(GoogleAssistant::TextArgument, subject.class) @@ -37,31 +37,31 @@ it "sets the class's attributes" do assert_equal(params["name"], subject.name) - assert_equal(params["raw_text"], subject.raw_text) - assert_equal(params["text_value"], subject.text_value) + assert_equal(params["rawText"], subject.raw_text) + assert_equal(params["textValue"], subject.text_value) end end end describe GoogleAssistant::TextArgument do - let(:params) { { "name" => "text", "text_value" => "some text value" } } + let(:params) { { "name" => "TEXT", "textValue" => "some text value" } } subject { GoogleAssistant::Argument.from(params) } describe "#value" do it "returns the value of text_value" do - assert_equal(params["text_value"], subject.value) + assert_equal(params["textValue"], subject.value) end end end describe GoogleAssistant::PermissionArgument do - let(:params) { { "name" => "permission_granted", "text_value" => text_value } } + let(:params) { { "name" => "PERMISSION", "textValue" => text_value } } subject { GoogleAssistant::Argument.from(params) } describe "#permission_granted?" do - describe "when text_value is true" do + describe "when textValue is true" do let(:text_value) { "true" } it "returns true" do @@ -69,7 +69,7 @@ end end - describe "when text_value is false" do + describe "when textValue is false" do let(:text_value) { "false" } it "returns false" do diff --git a/test/google_assistant/test_assistant.rb b/test/google_assistant/test_assistant.rb index 4b51966..b2896d4 100644 --- a/test/google_assistant/test_assistant.rb +++ b/test/google_assistant/test_assistant.rb @@ -31,7 +31,7 @@ it "sets google assistant version header on the response" do subject.respond_to {} - assert_equal("v1", response.headers["Google-Assistant-API-Version"]) + assert_equal("v2", response.headers["Google-Assistant-API-Version"]) end describe "when on the MAIN intent" do @@ -102,7 +102,7 @@ argument = subject.arguments.first - assert_equal("text", argument.name) + assert_equal("TEXT", argument.name) assert_equal("this is some raw text", argument.raw_text) assert_equal("this is a text value", argument.text_value) end @@ -140,7 +140,7 @@ conversation = subject.conversation assert_equal("1234567890", conversation.id) - assert_equal(2, conversation.type) + assert_equal("ACTIVE", conversation.type) assert_equal(GoogleAssistant::DialogState, conversation.dialog_state.class) end end @@ -173,9 +173,9 @@ message = "An SSML message" expected_response = { - expect_user_response: false, - final_response: { - speech_response: { ssml: message } + expectUserResponse: false, + finalResponse: { + speechResponse: { ssml: message } } } @@ -189,9 +189,9 @@ message = "A plain text message" expected_response = { - expect_user_response: false, - final_response: { - speech_response: { text_to_speech: message } + expectUserResponse: false, + finalResponse: { + speechResponse: { textToSpeech: message } } } @@ -239,15 +239,15 @@ response = subject.ask("Some SSML input prompt") expected_response = { - conversation_token: "{\"state\":null,\"data\":{}}", - expect_user_response: true, - expected_inputs: [ + conversationToken: "{\"state\":null,\"data\":{}}", + expectUserResponse: true, + expectedInputs: [ { - input_prompt: { - initial_prompts: [{ ssml: "Some SSML input prompt" }], - no_input_prompts: [] + inputPrompt: { + initialPrompts: [{ ssml: "Some SSML input prompt" }], + noInputPrompts: [] }, - possible_intents: [{ intent: "assistant.intent.action.TEXT" }] + possibleIntents: [{ intent: "actions.intent.TEXT" }] } ] } @@ -262,15 +262,15 @@ response = subject.ask("Some text input prompt") expected_response = { - conversation_token: "{\"state\":null,\"data\":{}}", - expect_user_response: true, - expected_inputs: [ + conversationToken: "{\"state\":null,\"data\":{}}", + expectUserResponse: true, + expectedInputs: [ { - input_prompt: { - initial_prompts: [{ text_to_speech: "Some text input prompt" }], - no_input_prompts: [] + inputPrompt: { + initialPrompts: [{ textToSpeech: "Some text input prompt" }], + noInputPrompts: [] }, - possible_intents: [{ intent: "assistant.intent.action.TEXT" }] + possibleIntents: [{ intent: "actions.intent.TEXT" }] } ] } @@ -288,15 +288,15 @@ response = subject.ask("Some input prompt") expected_response = { - conversation_token: { state: "a state", data: { "a data key" => "the data value" } }.to_json, - expect_user_response: true, - expected_inputs: [ + conversationToken: { state: "a state", data: { "a data key" => "the data value" } }.to_json, + expectUserResponse: true, + expectedInputs: [ { - input_prompt: { - initial_prompts: [{ text_to_speech: "Some input prompt" }], - no_input_prompts: [] + inputPrompt: { + initialPrompts: [{ textToSpeech: "Some input prompt" }], + noInputPrompts: [] }, - possible_intents: [{ intent: "assistant.intent.action.TEXT" }] + possibleIntents: [{ intent: "actions.intent.TEXT" }] } ] } @@ -305,7 +305,7 @@ end end - describe "when given a string no_input_prompt" do + describe "when given a string no_inputPrompt" do it "returns a JSON hash response with text" do response = subject.ask( @@ -314,15 +314,15 @@ ) expected_response = { - conversation_token: "{\"state\":null,\"data\":{}}", - expect_user_response: true, - expected_inputs: [ + conversationToken: "{\"state\":null,\"data\":{}}", + expectUserResponse: true, + expectedInputs: [ { - input_prompt: { - initial_prompts: [{ text_to_speech: "Some text input prompt" }], - no_input_prompts: [{ text_to_speech: "A no input prompt" }] + inputPrompt: { + initialPrompts: [{ textToSpeech: "Some text input prompt" }], + noInputPrompts: [{ textToSpeech: "A no input prompt" }] }, - possible_intents: [{ intent: "assistant.intent.action.TEXT" }] + possibleIntents: [{ intent: "actions.intent.TEXT" }] } ] } @@ -331,7 +331,7 @@ end end - describe "when given an array of strings for no_input_prompt" do + describe "when given an array of strings for no_inputPrompt" do it "returns a JSON hash response with text" do response = subject.ask( @@ -343,18 +343,18 @@ ) expected_response = { - conversation_token: "{\"state\":null,\"data\":{}}", - expect_user_response: true, - expected_inputs: [ + conversationToken: "{\"state\":null,\"data\":{}}", + expectUserResponse: true, + expectedInputs: [ { - input_prompt: { - initial_prompts: [{ text_to_speech: "Some text input prompt" }], - no_input_prompts: [ - { text_to_speech: "A no input prompt" }, + inputPrompt: { + initialPrompts: [{ textToSpeech: "Some text input prompt" }], + noInputPrompts: [ + { textToSpeech: "A no input prompt" }, { ssml: "Yet another no input prompt" } ] }, - possible_intents: [{ intent: "assistant.intent.action.TEXT" }] + possibleIntents: [{ intent: "actions.intent.TEXT" }] } ] } @@ -408,22 +408,21 @@ response = subject.ask_for_permission("A context", GoogleAssistant::Permission::NAME) expected_response = { - conversation_token: "{\"state\":null,\"data\":{}}", - expect_user_response: true, - expected_inputs: [ + conversationToken: "{\"state\":null,\"data\":{}}", + expectUserResponse: true, + expectedInputs: [ { - input_prompt: { - initial_prompts: [{ text_to_speech: "placeholder" }], - no_input_prompts: [] + inputPrompt: { + initialPrompts: [{ textToSpeech: "placeholder" }], + noInputPrompts: [] }, - possible_intents: [ + possibleIntents: [ { - intent: "assistant.intent.action.PERMISSION", - input_value_spec: { - permission_value_spec: { - opt_context: "A context", - permissions: ["NAME"] - } + intent: "actions.intent.PERMISSION", + inputValueData: { + "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec", + optContext: "A context", + permissions: ["NAME"] } } ] diff --git a/test/google_assistant/test_conversation.rb b/test/google_assistant/test_conversation.rb index 6c805d1..5a754f3 100644 --- a/test/google_assistant/test_conversation.rb +++ b/test/google_assistant/test_conversation.rb @@ -2,7 +2,7 @@ require "google_assistant/conversation" describe GoogleAssistant::Conversation do - let(:conversation_params) { { "conversation_id" => "abc123", "type" => 1, "conversation_token" => { "state" => "some state", "data" => { "some data" => "a value" } } } } + let(:conversation_params) { { "conversationId" => "abc123", "type" => 1, "conversationToken" => { "state" => "some state", "data" => { "some data" => "a value" } } } } subject { GoogleAssistant::Conversation.new(conversation_params) } describe "#initialize" do diff --git a/test/google_assistant/test_device.rb b/test/google_assistant/test_device.rb index ff6043f..db80f6e 100644 --- a/test/google_assistant/test_device.rb +++ b/test/google_assistant/test_device.rb @@ -9,8 +9,8 @@ "latitude" => 37.422, "longitude" => -122.084 }, - "formatted_address" => "1600 Amphitheatre Parkway, Mountain View, CA 94043, United States", - "zip_code" => "94043", + "formattedAddress" => "1600 Amphitheatre Parkway, Mountain View, CA 94043, United States", + "zipCode" => "94043", "city" => "Mountain View" } } @@ -35,14 +35,14 @@ describe "#zip_code" do it "returns the zip_code from the hash" do - assert_equal(params["location"]["zip_code"], subject.zip_code) + assert_equal(params["location"]["zipCode"], subject.zip_code) end end describe "#formatted_address" do it "returns the formatted_address from the hash" do - assert_equal(params["location"]["formatted_address"], subject.formatted_address) + assert_equal(params["location"]["formattedAddress"], subject.formatted_address) end end diff --git a/test/google_assistant/test_user.rb b/test/google_assistant/test_user.rb index 8efeaf7..84c24bc 100644 --- a/test/google_assistant/test_user.rb +++ b/test/google_assistant/test_user.rb @@ -4,12 +4,12 @@ describe GoogleAssistant::User do let(:params) do { - "user_id" => "some user id", - "access_token" => "iuaweLJ7igJgkyUGl7gujy52i8Iu609unjBJbk6", + "userId" => "some user id", + "accessToken" => "iuaweLJ7igJgkyUGl7gujy52i8Iu609unjBJbk6", "profile" => { - "display_name" => "Johnny", - "given_name" => "John", - "family_name" => "Smith" + "displayName" => "Johnny", + "givenName" => "John", + "familyName" => "Smith" } } end @@ -18,8 +18,8 @@ describe "#initialize" do it "sets the class's attributes" do - assert_equal(params["user_id"], subject.id) - assert_equal(params["access_token"], subject.access_token) + assert_equal(params["userId"], subject.id) + assert_equal(params["accessToken"], subject.access_token) assert_equal(params["profile"], subject.profile) end end @@ -27,21 +27,21 @@ describe "#display_name" do it "returns the display_name from the hash" do - assert_equal(params["profile"]["display_name"], subject.display_name) + assert_equal(params["profile"]["displayName"], subject.display_name) end end describe "#given_name" do it "returns the given_name from the hash" do - assert_equal(params["profile"]["given_name"], subject.given_name) + assert_equal(params["profile"]["givenName"], subject.given_name) end end describe "#family_name" do it "returns the family_name from the hash" do - assert_equal(params["profile"]["family_name"], subject.family_name) + assert_equal(params["profile"]["familyName"], subject.family_name) end end end diff --git a/test/test_google_assistant.rb b/test/test_google_assistant.rb index e52c642..31a1328 100644 --- a/test/test_google_assistant.rb +++ b/test/test_google_assistant.rb @@ -25,7 +25,7 @@ assert(called_intent) assert(assistant.is_a?(GoogleAssistant::Assistant)) assert_equal(params, assistant.params) - assert_equal("v1", response.headers["Google-Assistant-API-Version"]) + assert_equal("v2", response.headers["Google-Assistant-API-Version"]) assert_equal(response, assistant.response) end end