From 460390ed648c6e97a61d98c6bbd9daf7c2033e24 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Sun, 28 May 2017 22:15:07 -0400 Subject: [PATCH 01/12] Switch to camelCase in JSON --- lib/google_assistant/argument.rb | 6 +++--- lib/google_assistant/conversation.rb | 4 ++-- lib/google_assistant/device.rb | 4 ++-- .../response/ask_for_permission.rb | 4 ++-- lib/google_assistant/response/base.rb | 20 +++++++++---------- lib/google_assistant/response/input_prompt.rb | 2 +- .../response/speech_response.rb | 4 ++-- lib/google_assistant/user.rb | 10 +++++----- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/google_assistant/argument.rb b/lib/google_assistant/argument.rb index 1aaffb7..a4147b1 100644 --- a/lib/google_assistant/argument.rb +++ b/lib/google_assistant/argument.rb @@ -6,7 +6,7 @@ class Argument def self.from(opts) case opts["name"] - when "permission_granted" + when "permissionGranted" PermissionArgument.new(opts) when "text" TextArgument.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/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/response/ask_for_permission.rb b/lib/google_assistant/response/ask_for_permission.rb index 51e21fa..d304885 100644 --- a/lib/google_assistant/response/ask_for_permission.rb +++ b/lib/google_assistant/response/ask_for_permission.rb @@ -18,8 +18,8 @@ def to_json response = super(true) expected_intent = build_expected_intent(StandardIntents::PERMISSION, permissions, context) - expected_inputs = build_expected_inputs(expected_intent: expected_intent) - response[:expected_inputs] = expected_inputs + expected_inputs = build_expected_inputs(expectedIntent: expected_intent) + response[:expectedInputs] = expected_inputs response end diff --git a/lib/google_assistant/response/base.rb b/lib/google_assistant/response/base.rb index 0d874dc..71bf015 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,9 +56,9 @@ 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, + expected_intent[:inputValueSpec] = { + permissionValueSpec: { + optContext: context, permissions: permissions } } @@ -70,7 +70,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..cc9194f 100644 --- a/lib/google_assistant/user.rb +++ b/lib/google_assistant/user.rb @@ -5,21 +5,21 @@ 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"] 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 From 33aeffc42e2a15dd3859eaaf207cfe1df16f0edc Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Sun, 28 May 2017 22:17:41 -0400 Subject: [PATCH 02/12] Upgrade to Google Assistant API v2 --- README.md | 6 +++++- lib/google_assistant/assistant.rb | 2 +- test/google_assistant/test_assistant.rb | 2 +- test/test_google_assistant.rb | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8d605c4..5aa0878 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 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/test/google_assistant/test_assistant.rb b/test/google_assistant/test_assistant.rb index 4b51966..368aa05 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 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 From 73a3fec34b83f5e0eaafefdd3375998d686e234f Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Sun, 28 May 2017 22:23:02 -0400 Subject: [PATCH 03/12] Rename intents and inputValueSpec --- lib/google_assistant/intent.rb | 6 +++--- lib/google_assistant/response/base.rb | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) 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/base.rb b/lib/google_assistant/response/base.rb index 71bf015..dd0a6bc 100644 --- a/lib/google_assistant/response/base.rb +++ b/lib/google_assistant/response/base.rb @@ -56,7 +56,8 @@ 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[:inputValueSpec] = { + expected_intent[:inputValueData] = { + "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec", permissionValueSpec: { optContext: context, permissions: permissions From 252906909adc506ae41a2b27eaf1c29f1badd467 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Wed, 31 May 2017 07:41:17 -0400 Subject: [PATCH 04/12] Add folder for samples --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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/* From b83ba8ef0ba0500a4844e430c412c326c704a6cb Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Wed, 31 May 2017 07:46:44 -0400 Subject: [PATCH 05/12] Add user locale --- lib/google_assistant/user.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/google_assistant/user.rb b/lib/google_assistant/user.rb index cc9194f..9ad767f 100644 --- a/lib/google_assistant/user.rb +++ b/lib/google_assistant/user.rb @@ -8,6 +8,7 @@ def initialize(opts) @id = opts["userId"] @profile = opts["profile"] || {} @access_token = opts["accessToken"] + @locale = opts["locale"] end def display_name From 4840846013e12c5fed4ab63bf7fba05966eca021 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Fri, 2 Jun 2017 11:34:53 -0400 Subject: [PATCH 06/12] Fix parameter typo --- lib/google_assistant/response/ask_for_permission.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/google_assistant/response/ask_for_permission.rb b/lib/google_assistant/response/ask_for_permission.rb index d304885..99003cd 100644 --- a/lib/google_assistant/response/ask_for_permission.rb +++ b/lib/google_assistant/response/ask_for_permission.rb @@ -18,7 +18,7 @@ def to_json response = super(true) expected_intent = build_expected_intent(StandardIntents::PERMISSION, permissions, context) - expected_inputs = build_expected_inputs(expectedIntent: expected_intent) + expected_inputs = build_expected_inputs(expected_intent: expected_intent) response[:expectedInputs] = expected_inputs response From 76b96a8b9ed622f76e043f0d1ee6cb6e363b7e54 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Fri, 2 Jun 2017 11:46:45 -0400 Subject: [PATCH 07/12] Remove permissionValueSpec which apparently has been flattened --- lib/google_assistant/response/base.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/google_assistant/response/base.rb b/lib/google_assistant/response/base.rb index dd0a6bc..01e3016 100644 --- a/lib/google_assistant/response/base.rb +++ b/lib/google_assistant/response/base.rb @@ -58,10 +58,8 @@ def build_expected_intent(intent, permissions = nil, context = nil) expected_intent[:inputValueData] = { "@type": "type.googleapis.com/google.actions.v2.PermissionValueSpec", - permissionValueSpec: { - optContext: context, - permissions: permissions - } + optContext: context, + permissions: permissions } end From 700e064269f13f3bea3f5ac56782de1ce263a192 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Fri, 2 Jun 2017 12:05:53 -0400 Subject: [PATCH 08/12] Update permission object model --- lib/google_assistant/argument.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/google_assistant/argument.rb b/lib/google_assistant/argument.rb index a4147b1..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 "permissionGranted" + when "PERMISSION" PermissionArgument.new(opts) - when "text" + when "TEXT" TextArgument.new(opts) else Argument.new(opts) From 1753f35c7b56767675b67a1c113a2b157ca14081 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Fri, 2 Jun 2017 12:47:08 -0400 Subject: [PATCH 09/12] Got tests passing - now to make sure they're all correct --- README.md | 2 +- test/fixtures/coarse_location_granted.json | 20 ++-- test/fixtures/empty_arguments_request.json | 10 +- test/fixtures/main_intent_request.json | 10 +- test/fixtures/permission_denied.json | 18 +-- test/fixtures/precise_location_granted.json | 22 ++-- test/fixtures/single_argument_request.json | 18 +-- test/fixtures/text_intent_request.json | 18 +-- test/fixtures/user_name_granted.json | 24 ++-- test/google_assistant/test_argument.rb | 22 ++-- test/google_assistant/test_assistant.rb | 115 ++++++++++---------- test/google_assistant/test_conversation.rb | 2 +- test/google_assistant/test_device.rb | 8 +- test/google_assistant/test_user.rb | 20 ++-- 14 files changed, 154 insertions(+), 155 deletions(-) diff --git a/README.md b/README.md index 5aa0878..2d2fab8 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,7 @@ You can use any hosting platform. "actions": [ { "initialTrigger": { - "intent": "assistant.intent.action.MAIN" + "intent": "actions.intent.MAIN" }, "httpExecution": { "url": "https://yourapp.domain.com/path-to-your-assistant" diff --git a/test/fixtures/coarse_location_granted.json b/test/fixtures/coarse_location_granted.json index 128c56e..3057709 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\":{}}", + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", "type": 2 }, "inputs": [ { - "intent": "assistant.intent.action.PERMISSION", - "raw_inputs": [ + "intent": "actions.intent.PERMISSION", + "rawInputs": [ { - "input_type": 2, + "inputType": 2, "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..3c5a711 100644 --- a/test/fixtures/empty_arguments_request.json +++ b/test/fixtures/empty_arguments_request.json @@ -1,21 +1,21 @@ { "conversation": { - "conversation_id": "1234567890", + "conversationId": "1234567890", "type": 1 }, "inputs": [ { "arguments": [], - "intent": "assistant.intent.action.MAIN", - "raw_inputs": [ + "intent": "actions.intent.MAIN", + "rawInputs": [ { - "input_type": 2, + "inputType": 2, "query": "Google Assistant Ruby Test" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/main_intent_request.json b/test/fixtures/main_intent_request.json index a1f1f5a..3c5a711 100644 --- a/test/fixtures/main_intent_request.json +++ b/test/fixtures/main_intent_request.json @@ -1,21 +1,21 @@ { "conversation": { - "conversation_id": "1234567890", + "conversationId": "1234567890", "type": 1 }, "inputs": [ { "arguments": [], - "intent": "assistant.intent.action.MAIN", - "raw_inputs": [ + "intent": "actions.intent.MAIN", + "rawInputs": [ { - "input_type": 2, + "inputType": 2, "query": "Google Assistant Ruby Test" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/permission_denied.json b/test/fixtures/permission_denied.json index 5fb2135..71cfaba 100644 --- a/test/fixtures/permission_denied.json +++ b/test/fixtures/permission_denied.json @@ -1,28 +1,28 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", "type": 2 }, "inputs": [ { - "intent": "assistant.intent.action.PERMISSION", - "raw_inputs": [ + "intent": "actions.intent.PERMISSION", + "rawInputs": [ { - "input_type": 2, + "inputType": 2, "query": "nope" } ], "arguments": [ { - "name": "permission_granted", - "raw_text": "nope", - "text_value": "false" + "name": "PERMISSION", + "rawText": "nope", + "textValue": "false" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/precise_location_granted.json b/test/fixtures/precise_location_granted.json index e837705..7137ec5 100644 --- a/test/fixtures/precise_location_granted.json +++ b/test/fixtures/precise_location_granted.json @@ -1,29 +1,29 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", "type": 2 }, "inputs": [ { - "intent": "assistant.intent.action.PERMISSION", - "raw_inputs": [ + "intent": "actions.intent.PERMISSION", + "rawInputs": [ { - "input_type": 2, + "inputType": 2, "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": { @@ -31,8 +31,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..1a00b82 100644 --- a/test/fixtures/single_argument_request.json +++ b/test/fixtures/single_argument_request.json @@ -1,28 +1,28 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", "type": 2 }, "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": 2, "query": "this is a query" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/text_intent_request.json b/test/fixtures/text_intent_request.json index 27485ff..6a14bbe 100644 --- a/test/fixtures/text_intent_request.json +++ b/test/fixtures/text_intent_request.json @@ -1,28 +1,28 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", "type": 2 }, "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": 2, "query": "this is some input" } ] } ], "user": { - "user_id": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" + "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/user_name_granted.json b/test/fixtures/user_name_granted.json index f621a8f..5bec4b3 100644 --- a/test/fixtures/user_name_granted.json +++ b/test/fixtures/user_name_granted.json @@ -1,33 +1,33 @@ { "conversation": { - "conversation_id": "1234567890", - "conversation_token": "{\"state\":null,\"data\":{}}", + "conversationId": "1234567890", + "conversationToken": "{\"state\":null,\"data\":{}}", "type": 2 }, "inputs": [ { - "intent": "assistant.intent.action.PERMISSION", - "raw_inputs": [ + "intent": "actions.intent.PERMISSION", + "rawInputs": [ { - "input_type": 2, + "inputType": 2, "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=", "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 368aa05..c86484a 100644 --- a/test/google_assistant/test_assistant.rb +++ b/test/google_assistant/test_assistant.rb @@ -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 @@ -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 From 6b0acc14d6d48491e0a087af149f0a205d9e3be8 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Fri, 2 Jun 2017 12:51:36 -0400 Subject: [PATCH 10/12] Updated fixtures --- test/fixtures/coarse_location_granted.json | 4 ++-- test/fixtures/empty_arguments_request.json | 5 +++-- test/fixtures/main_intent_request.json | 6 +++--- test/fixtures/permission_denied.json | 5 +++-- test/fixtures/precise_location_granted.json | 5 +++-- test/fixtures/single_argument_request.json | 5 +++-- test/fixtures/text_intent_request.json | 5 +++-- test/fixtures/user_name_granted.json | 5 +++-- test/google_assistant/test_assistant.rb | 2 +- 9 files changed, 24 insertions(+), 18 deletions(-) diff --git a/test/fixtures/coarse_location_granted.json b/test/fixtures/coarse_location_granted.json index 3057709..c20be14 100644 --- a/test/fixtures/coarse_location_granted.json +++ b/test/fixtures/coarse_location_granted.json @@ -2,14 +2,14 @@ "conversation": { "conversationId": "1234567890", "conversationToken": "{\"state\":null,\"data\":{}}", - "type": 2 + "type": "ACTIVE" }, "inputs": [ { "intent": "actions.intent.PERMISSION", "rawInputs": [ { - "inputType": 2, + "inputType": "KEYBOARD", "query": "sure" } ], diff --git a/test/fixtures/empty_arguments_request.json b/test/fixtures/empty_arguments_request.json index 3c5a711..bbfdadb 100644 --- a/test/fixtures/empty_arguments_request.json +++ b/test/fixtures/empty_arguments_request.json @@ -1,7 +1,7 @@ { "conversation": { "conversationId": "1234567890", - "type": 1 + "type": "NEW" }, "inputs": [ { @@ -9,13 +9,14 @@ "intent": "actions.intent.MAIN", "rawInputs": [ { - "inputType": 2, + "inputType": "KEYBOARD", "query": "Google Assistant Ruby Test" } ] } ], "user": { + "locale": "en-US", "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/main_intent_request.json b/test/fixtures/main_intent_request.json index 3c5a711..0002047 100644 --- a/test/fixtures/main_intent_request.json +++ b/test/fixtures/main_intent_request.json @@ -1,21 +1,21 @@ { "conversation": { "conversationId": "1234567890", - "type": 1 + "type": "NEW" }, "inputs": [ { - "arguments": [], "intent": "actions.intent.MAIN", "rawInputs": [ { - "inputType": 2, + "inputType": "KEYBOARD", "query": "Google Assistant Ruby Test" } ] } ], "user": { + "locale": "en-US", "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/permission_denied.json b/test/fixtures/permission_denied.json index 71cfaba..6810699 100644 --- a/test/fixtures/permission_denied.json +++ b/test/fixtures/permission_denied.json @@ -2,14 +2,14 @@ "conversation": { "conversationId": "1234567890", "conversationToken": "{\"state\":null,\"data\":{}}", - "type": 2 + "type": "ACTIVE" }, "inputs": [ { "intent": "actions.intent.PERMISSION", "rawInputs": [ { - "inputType": 2, + "inputType": "KEYBOARD", "query": "nope" } ], @@ -23,6 +23,7 @@ } ], "user": { + "locale": "en-US", "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/precise_location_granted.json b/test/fixtures/precise_location_granted.json index 7137ec5..9a9b4b1 100644 --- a/test/fixtures/precise_location_granted.json +++ b/test/fixtures/precise_location_granted.json @@ -2,14 +2,14 @@ "conversation": { "conversationId": "1234567890", "conversationToken": "{\"state\":null,\"data\":{}}", - "type": 2 + "type": "ACTIVE" }, "inputs": [ { "intent": "actions.intent.PERMISSION", "rawInputs": [ { - "inputType": 2, + "inputType": "KEYBOARD", "query": "sure" } ], @@ -23,6 +23,7 @@ } ], "user": { + "locale": "en-US", "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" }, "device": { diff --git a/test/fixtures/single_argument_request.json b/test/fixtures/single_argument_request.json index 1a00b82..5987e83 100644 --- a/test/fixtures/single_argument_request.json +++ b/test/fixtures/single_argument_request.json @@ -2,7 +2,7 @@ "conversation": { "conversationId": "1234567890", "conversationToken": "{\"state\":null,\"data\":{}}", - "type": 2 + "type": "ACTIVE" }, "inputs": [ { @@ -16,13 +16,14 @@ "intent": "actions.intent.TEXT", "rawInputs": [ { - "inputType": 2, + "inputType": "KEYBOARD", "query": "this is a query" } ] } ], "user": { + "locale": "en-US", "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/text_intent_request.json b/test/fixtures/text_intent_request.json index 6a14bbe..3ae2070 100644 --- a/test/fixtures/text_intent_request.json +++ b/test/fixtures/text_intent_request.json @@ -2,7 +2,7 @@ "conversation": { "conversationId": "1234567890", "conversationToken": "{\"state\":null,\"data\":{}}", - "type": 2 + "type": "ACTIVE" }, "inputs": [ { @@ -16,13 +16,14 @@ "intent": "actions.intent.TEXT", "rawInputs": [ { - "inputType": 2, + "inputType": "KEYBOARD", "query": "this is some input" } ] } ], "user": { + "locale": "en-US", "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=" } } diff --git a/test/fixtures/user_name_granted.json b/test/fixtures/user_name_granted.json index 5bec4b3..fcc2291 100644 --- a/test/fixtures/user_name_granted.json +++ b/test/fixtures/user_name_granted.json @@ -2,14 +2,14 @@ "conversation": { "conversationId": "1234567890", "conversationToken": "{\"state\":null,\"data\":{}}", - "type": 2 + "type": "ACTIVE" }, "inputs": [ { "intent": "actions.intent.PERMISSION", "rawInputs": [ { - "inputType": 2, + "inputType": "KEYBOARD", "query": "sure" } ], @@ -23,6 +23,7 @@ } ], "user": { + "locale": "en-US", "userId": "qwERtyUiopaSdfGhJklzXCVBNm/tF=", "profile": { "displayName": "John Smith", diff --git a/test/google_assistant/test_assistant.rb b/test/google_assistant/test_assistant.rb index c86484a..b2896d4 100644 --- a/test/google_assistant/test_assistant.rb +++ b/test/google_assistant/test_assistant.rb @@ -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 From 0167dfd826e3418c1eecf53d3afe3c1257e43539 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Fri, 2 Jun 2017 13:48:47 -0400 Subject: [PATCH 11/12] Update README for new version --- README.md | 67 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 2d2fab8..f4d288a 100644 --- a/README.md +++ b/README.md @@ -37,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?" ] @@ -92,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. ] @@ -146,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 @@ -158,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"] @@ -192,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 @@ -215,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 @@ -237,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 @@ -264,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": "actions.intent.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 + } + } } ``` @@ -297,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 @@ -306,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. From 46592dfffb37aa072e3f0980c1775d1db79179e9 Mon Sep 17 00:00:00 2001 From: Aaron Milam Date: Fri, 2 Jun 2017 13:50:24 -0400 Subject: [PATCH 12/12] Bump to version 2 --- lib/google_assistant/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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