Skip to content

Commit d29f6fb

Browse files
authored
Merge pull request #4 from rigatti/updateModel
Update model V2
2 parents d114d24 + 3f303b1 commit d29f6fb

35 files changed

+323
-648
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public class TextRequestHandler extends RequestHandler {
154154

155155
@Override
156156
public RootResponse getResponse() {
157-
return ResponseBuilder.tellResponse("You've just said: " + getRootRequest().inputs.get(0).raw_inputs.get(0).query);
157+
return ResponseBuilder.tellResponse("You've just said: " + getRootRequest().inputs.get(0).rawInputs.get(0).query);
158158
}
159159
}
160160
```

gactions-sample/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ apply plugin: 'war'
66
apply plugin: 'com.google.cloud.tools.appengine'
77

88
compileJava {
9-
targetCompatibility = JavaVersion.VERSION_1_7
10-
sourceCompatibility = JavaVersion.VERSION_1_7
9+
targetCompatibility = JavaVersion.VERSION_1_8
10+
sourceCompatibility = JavaVersion.VERSION_1_8
1111
}
1212

1313
repositories {
@@ -23,7 +23,7 @@ repositories {
2323
dependencies {
2424
providedCompile 'javax.servlet:servlet-api:2.5'
2525
// compile project(':gactions')
26-
compile 'com.frogermcs.gactions:gactions:0.1.1'
26+
compile 'com.frogermcs.gactions:gactions:0.2.0'
2727
compile 'com.google.appengine:appengine:+'
2828
testCompile group: 'junit', name: 'junit', version: '4.11'
2929
}

gactions-sample/src/main/java/com/frogermcs/gactions/sample/TextRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public class TextRequestHandler extends RequestHandler {
1616

1717
@Override
1818
public RootResponse getResponse() {
19-
return ResponseBuilder.tellResponse("You've just said: " + getRootRequest().inputs.get(0).raw_inputs.get(0).query);
19+
return ResponseBuilder.tellResponse("You've just said: " + getRootRequest().inputs.get(0).rawInputs.get(0).query);
2020
}
2121
}

gactions/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apply plugin: 'java'
22

33
compileJava {
4-
targetCompatibility = JavaVersion.VERSION_1_7
5-
sourceCompatibility = JavaVersion.VERSION_1_7
4+
targetCompatibility = JavaVersion.VERSION_1_8
5+
sourceCompatibility = JavaVersion.VERSION_1_8
66
}
77

88
repositories {
@@ -16,12 +16,14 @@ repositories {
1616
dependencies {
1717
compile 'com.google.code.findbugs:jsr305:3.0.1'
1818
compile 'com.google.code.gson:gson:2.8.0'
19+
compile 'org.projectlombok:lombok:1.16.2'
1920

20-
testCompile 'junit:junit:4.11'
21-
testCompile 'org.mockito:mockito-core:1.+'
21+
testCompile 'junit:junit:4.12'
22+
testCompile 'org.mockito:mockito-core:2.+'
2223
testCompile 'org.hamcrest:hamcrest-core:1.3'
2324
testCompile 'org.hamcrest:hamcrest-library:1.3'
2425
testCompile 'org.hamcrest:hamcrest-integration:1.3'
26+
2527
}
2628

2729
apply from: rootProject.file('gradle/gradle-bintray-push.gradle')

gactions/src/main/java/com/frogermcs/gactions/ResponseBuilder.java

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,99 @@
1212
*/
1313
public class ResponseBuilder {
1414

15-
/**
16-
* @param message - speech response for Google Actions request
17-
* @return {@link RootResponse} object that contains speech response for Google Actions request
18-
*/
1915
public static RootResponse tellResponse(String message) {
16+
return ResponseBuilder.tellResponse(SpeechResponse.builder().textToSpeech(message).displayText(message).build());
17+
}
18+
19+
public static RootResponse tellResponse(SpeechResponse message) {
2020
RootResponse rootResponse = new RootResponse();
21-
rootResponse.expect_user_response = false;
22-
rootResponse.final_response = new FinalResponse();
23-
rootResponse.final_response.speech_response = new SpeechResponse(message, null);
21+
rootResponse.expectUserResponse = false;
22+
rootResponse.finalResponse = new FinalResponse();
23+
rootResponse.finalResponse.speechResponse = message;
2424
return rootResponse;
2525
}
2626

27-
/**
28-
* @param message - speech response for Google Actions request
29-
* @return {@link RootResponse} object that uses speech response to ask user for additional data
30-
*/
3127
public static RootResponse askResponse(String message) {
28+
return ResponseBuilder.askResponse(SpeechResponse.builder().textToSpeech(message).displayText(message).build());
29+
}
30+
31+
public static RootResponse askResponse(SpeechResponse message) {
3232
return askResponse(message, null, null);
3333
}
3434

35-
/**
36-
* @param message - speech response for Google Actions request
37-
* @param noInputPrompts
38-
* @return {@link RootResponse} object that uses speech response to ask user for additional data
39-
*/
4035
public static RootResponse askResponse(String message, String[] noInputPrompts) {
4136
return askResponse(message, null, noInputPrompts);
4237
}
4338

39+
public static RootResponse askResponseWithRichInput(SpeechResponse message) {
40+
return askResponseWithRichInput(message, null, null, null);
41+
}
42+
43+
public static RootResponse askResponseWithRichInput(SpeechResponse message, String conversationToken, List<SpeechResponse> noInputPrompts, List<SuggestionResponse> suggestions ) {
44+
RootResponse rootResponse = new RootResponse();
45+
rootResponse.expectUserResponse = true;
46+
rootResponse.conversationToken = conversationToken;
47+
rootResponse.expectedInputs = new ArrayList<>();
48+
49+
ExpectedInputs expectedInput = new ExpectedInputs();
50+
expectedInput.inputPrompt = new InputPrompt();
51+
52+
RichInitialPromptItems richInitialPromptItems = RichInitialPromptItems.builder().simpleResponse(message).build();
53+
54+
RichInitialPrompt richInitialPrompt = RichInitialPrompt.builder().items(Collections.singletonList(richInitialPromptItems)).suggestions(suggestions).build();
55+
56+
expectedInput.inputPrompt.richInitialPrompt = richInitialPrompt;
57+
58+
if (noInputPrompts != null && noInputPrompts.size() > 0) {
59+
expectedInput.inputPrompt.noInputPrompts = noInputPrompts;
60+
}
61+
62+
expectedInput.possibleIntents = new ArrayList<>();
63+
expectedInput.possibleIntents.add(new ExpectedIntent(StandardIntents.TEXT));
64+
65+
rootResponse.expectedInputs.add(expectedInput);
66+
return rootResponse;
67+
}
68+
4469
/**
4570
* @param message - speech response for Google Actions request
4671
* @param conversationToken
4772
* @param noInputPrompts
4873
* @return {@link RootResponse} object that uses speech response to ask user for additional data
4974
*/
50-
public static RootResponse askResponse(String message, String conversationToken, String[] noInputPrompts) {
75+
public static RootResponse askResponse(SpeechResponse message, String conversationToken, List<SpeechResponse> noInputPrompts ) {
5176
RootResponse rootResponse = new RootResponse();
52-
rootResponse.expect_user_response = true;
53-
rootResponse.conversation_token = conversationToken;
54-
rootResponse.expected_inputs = new ArrayList<>();
77+
rootResponse.expectUserResponse = true;
78+
rootResponse.conversationToken = conversationToken;
79+
rootResponse.expectedInputs = new ArrayList<>();
5580

5681
ExpectedInputs expectedInput = new ExpectedInputs();
57-
expectedInput.input_prompt = new InputPrompt();
58-
expectedInput.input_prompt.initial_prompts = Collections.singletonList(new SpeechResponse(message, null));
59-
60-
if (noInputPrompts != null && noInputPrompts.length > 0) {
61-
expectedInput.input_prompt.no_input_prompts = new ArrayList<>();
62-
for (String noInputPrompt : noInputPrompts) {
63-
expectedInput.input_prompt.no_input_prompts.add(new SpeechResponse(noInputPrompt, null));
64-
}
82+
expectedInput.inputPrompt = new InputPrompt();
83+
expectedInput.inputPrompt.initialPrompts = Collections.singletonList(message);
6584

85+
if (noInputPrompts != null && noInputPrompts.size() > 0) {
86+
expectedInput.inputPrompt.noInputPrompts = noInputPrompts;
6687
}
6788

68-
expectedInput.possible_intents = new ArrayList<>();
69-
expectedInput.possible_intents.add(new ExpectedIntent(StandardIntents.TEXT));
89+
expectedInput.possibleIntents = new ArrayList<>();
90+
expectedInput.possibleIntents.add(new ExpectedIntent(StandardIntents.TEXT));
7091

71-
rootResponse.expected_inputs.add(expectedInput);
92+
rootResponse.expectedInputs.add(expectedInput);
7293
return rootResponse;
7394
}
7495

96+
public static RootResponse askResponse(String message, String conversationToken, String[] noInputPrompts) {
97+
List<SpeechResponse> noInputPromptsConverted = null;
98+
if (noInputPrompts != null && noInputPrompts.length > 0) {
99+
List<SpeechResponse> result = new ArrayList<>();
100+
for(String noInputPrompt : noInputPrompts) {
101+
noInputPromptsConverted.add(SpeechResponse.builder().textToSpeech(noInputPrompt).displayText(noInputPrompt).build());
102+
}
103+
}
104+
105+
return ResponseBuilder.askResponse(SpeechResponse.builder().textToSpeech(message).displayText(message).build(), conversationToken, noInputPromptsConverted);
106+
}
107+
75108
/**
76109
* @param permissionContext - Context why the permission is being asked; it's the TTS
77110
* prompt prefix (action phrase) we ask the user.
@@ -130,24 +163,24 @@ public static RootResponse askForPermissionResponse(String permissionContext, Co
130163
}
131164

132165
RootResponse rootResponse = new RootResponse();
133-
rootResponse.expect_user_response = true;
166+
rootResponse.expectUserResponse = true;
134167

135168
PermissionValueSpec permissionValueSpec = new PermissionValueSpec();
136-
permissionValueSpec.opt_context = permissionContext;
169+
permissionValueSpec.optContext = permissionContext;
137170
permissionValueSpec.permissions = new ArrayList<>(permissions);
138171

139172
InputValueSpec inputValueSpec = new InputValueSpec();
140173
inputValueSpec.permission_value_spec = permissionValueSpec;
141174

142175
ExpectedIntent expectedIntent = new ExpectedIntent(StandardIntents.PERMISSION);
143-
expectedIntent.input_value_spec = inputValueSpec;
176+
expectedIntent.inputValueSpec = inputValueSpec;
144177

145178
ExpectedInputs expectedInput = new ExpectedInputs();
146-
expectedInput.possible_intents = new ArrayList<>();
147-
expectedInput.possible_intents.add(expectedIntent);
179+
expectedInput.possibleIntents = new ArrayList<>();
180+
expectedInput.possibleIntents.add(expectedIntent);
148181

149-
rootResponse.expected_inputs = new ArrayList<>();
150-
rootResponse.expected_inputs.add(expectedInput);
182+
rootResponse.expectedInputs = new ArrayList<>();
183+
rootResponse.expectedInputs.add(expectedInput);
151184

152185
return rootResponse;
153186
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.frogermcs.gactions.api;
2+
3+
/**
4+
* Standard action intents handled by Google Assistant
5+
*/
6+
public class AssistantIntents {
7+
/**
8+
* Assistant fires MAIN intent for queries like [talk to $action].
9+
*/
10+
public static final String MAIN = "assistant.intent.action.MAIN";
11+
/**
12+
* Assistant fires TEXT intent when action issues ask intent.
13+
*/
14+
public static final String TEXT = "assistant.intent.action.TEXT";
15+
/**
16+
* Assistant fires PERMISSION intent when action invokes askForPermission.
17+
*/
18+
public static final String PERMISSION = "assistant.intent.action.PERMISSION";
19+
}

gactions/src/main/java/com/frogermcs/gactions/api/RequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public RootRequest getRootRequest() {
2626
* @return UserId from Google Actions API request
2727
*/
2828
public String getUserId() {
29-
return rootRequest.user.user_id;
29+
return rootRequest.user.userId;
3030
}
3131

3232
/**

gactions/src/main/java/com/frogermcs/gactions/api/StandardIntents.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ public class StandardIntents {
77
/**
88
* Assistant fires MAIN intent for queries like [talk to $action].
99
*/
10-
public static final String MAIN = "assistant.intent.action.MAIN";
10+
public static final String MAIN = "actions.intent.MAIN";
1111
/**
1212
* Assistant fires TEXT intent when action issues ask intent.
1313
*/
14-
public static final String TEXT = "assistant.intent.action.TEXT";
14+
public static final String TEXT = "actions.intent.TEXT";
1515
/**
1616
* Assistant fires PERMISSION intent when action invokes askForPermission.
1717
*/
18-
public static final String PERMISSION = "assistant.intent.action.PERMISSION";
18+
public static final String PERMISSION = "actions.intent.PERMISSION";
1919
}
Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.frogermcs.gactions.api.request;
22

3-
/**
4-
* Created by froger_mcs on 17/01/2017.
5-
*/
3+
import lombok.*;
4+
5+
@Builder
6+
@EqualsAndHashCode
7+
@ToString
8+
@AllArgsConstructor
9+
@NoArgsConstructor
610
public class Argument {
711
public String name;
812
public String raw_text;
@@ -13,52 +17,4 @@ public class Argument {
1317
public String time_value;
1418
public Location location_value;
1519
public String formatted_address;
16-
17-
@Override
18-
public boolean equals(Object o) {
19-
if (this == o) return true;
20-
if (o == null || getClass() != o.getClass()) return false;
21-
22-
Argument argument = (Argument) o;
23-
24-
if (name != null ? !name.equals(argument.name) : argument.name != null) return false;
25-
if (raw_text != null ? !raw_text.equals(argument.raw_text) : argument.raw_text != null) return false;
26-
if (int_value != null ? !int_value.equals(argument.int_value) : argument.int_value != null) return false;
27-
if (bool_value != null ? !bool_value.equals(argument.bool_value) : argument.bool_value != null) return false;
28-
if (text_value != null ? !text_value.equals(argument.text_value) : argument.text_value != null) return false;
29-
if (date_value != null ? !date_value.equals(argument.date_value) : argument.date_value != null) return false;
30-
if (time_value != null ? !time_value.equals(argument.time_value) : argument.time_value != null) return false;
31-
if (location_value != null ? !location_value.equals(argument.location_value) : argument.location_value != null)
32-
return false;
33-
return formatted_address != null ? formatted_address.equals(argument.formatted_address) : argument.formatted_address == null;
34-
}
35-
36-
@Override
37-
public int hashCode() {
38-
int result = name != null ? name.hashCode() : 0;
39-
result = 31 * result + (raw_text != null ? raw_text.hashCode() : 0);
40-
result = 31 * result + (int_value != null ? int_value.hashCode() : 0);
41-
result = 31 * result + (bool_value != null ? bool_value.hashCode() : 0);
42-
result = 31 * result + (text_value != null ? text_value.hashCode() : 0);
43-
result = 31 * result + (date_value != null ? date_value.hashCode() : 0);
44-
result = 31 * result + (time_value != null ? time_value.hashCode() : 0);
45-
result = 31 * result + (location_value != null ? location_value.hashCode() : 0);
46-
result = 31 * result + (formatted_address != null ? formatted_address.hashCode() : 0);
47-
return result;
48-
}
49-
50-
@Override
51-
public String toString() {
52-
return "Argument{" +
53-
"name='" + name + '\'' +
54-
", raw_text='" + raw_text + '\'' +
55-
", int_value='" + int_value + '\'' +
56-
", bool_value='" + bool_value + '\'' +
57-
", text_value='" + text_value + '\'' +
58-
", date_value='" + date_value + '\'' +
59-
", time_value='" + time_value + '\'' +
60-
", location_value=" + location_value +
61-
", formatted_address='" + formatted_address + '\'' +
62-
'}';
63-
}
6420
}
Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
11
package com.frogermcs.gactions.api.request;
22

3+
import lombok.*;
4+
35
/**
46
* Created by froger_mcs on 17/01/2017.
57
*/
8+
@Builder
9+
@EqualsAndHashCode
10+
@ToString
11+
@AllArgsConstructor
12+
@NoArgsConstructor
613
public class Conversation {
7-
public String conversation_id;
14+
public String conversationId;
815
public ConversationType type;
9-
public String conversation_token;
10-
11-
@Override
12-
public boolean equals(Object o) {
13-
if (this == o) return true;
14-
if (o == null || getClass() != o.getClass()) return false;
15-
16-
Conversation that = (Conversation) o;
17-
18-
if (conversation_id != null ? !conversation_id.equals(that.conversation_id) : that.conversation_id != null)
19-
return false;
20-
if (type != that.type) return false;
21-
return conversation_token != null ? conversation_token.equals(that.conversation_token) : that.conversation_token == null;
22-
}
23-
24-
@Override
25-
public int hashCode() {
26-
int result = conversation_id != null ? conversation_id.hashCode() : 0;
27-
result = 31 * result + (type != null ? type.hashCode() : 0);
28-
result = 31 * result + (conversation_token != null ? conversation_token.hashCode() : 0);
29-
return result;
30-
}
31-
32-
@Override
33-
public String toString() {
34-
return "Conversation{" +
35-
"conversation_id='" + conversation_id + '\'' +
36-
", type=" + type +
37-
", conversation_token='" + conversation_token + '\'' +
38-
'}';
39-
}
16+
public String conversationToken;
4017
}

0 commit comments

Comments
 (0)