|
12 | 12 | */
|
13 | 13 | public class ResponseBuilder {
|
14 | 14 |
|
15 |
| - /** |
16 |
| - * @param message - speech response for Google Actions request |
17 |
| - * @return {@link RootResponse} object that contains speech response for Google Actions request |
18 |
| - */ |
19 | 15 | 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) { |
20 | 20 | 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; |
24 | 24 | return rootResponse;
|
25 | 25 | }
|
26 | 26 |
|
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 |
| - */ |
31 | 27 | 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) { |
32 | 32 | return askResponse(message, null, null);
|
33 | 33 | }
|
34 | 34 |
|
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 |
| - */ |
40 | 35 | public static RootResponse askResponse(String message, String[] noInputPrompts) {
|
41 | 36 | return askResponse(message, null, noInputPrompts);
|
42 | 37 | }
|
43 | 38 |
|
| 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 | + |
44 | 69 | /**
|
45 | 70 | * @param message - speech response for Google Actions request
|
46 | 71 | * @param conversationToken
|
47 | 72 | * @param noInputPrompts
|
48 | 73 | * @return {@link RootResponse} object that uses speech response to ask user for additional data
|
49 | 74 | */
|
50 |
| - public static RootResponse askResponse(String message, String conversationToken, String[] noInputPrompts) { |
| 75 | + public static RootResponse askResponse(SpeechResponse message, String conversationToken, List<SpeechResponse> noInputPrompts ) { |
51 | 76 | 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<>(); |
55 | 80 |
|
56 | 81 | 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); |
65 | 84 |
|
| 85 | + if (noInputPrompts != null && noInputPrompts.size() > 0) { |
| 86 | + expectedInput.inputPrompt.noInputPrompts = noInputPrompts; |
66 | 87 | }
|
67 | 88 |
|
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)); |
70 | 91 |
|
71 |
| - rootResponse.expected_inputs.add(expectedInput); |
| 92 | + rootResponse.expectedInputs.add(expectedInput); |
72 | 93 | return rootResponse;
|
73 | 94 | }
|
74 | 95 |
|
| 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 | + |
75 | 108 | /**
|
76 | 109 | * @param permissionContext - Context why the permission is being asked; it's the TTS
|
77 | 110 | * prompt prefix (action phrase) we ask the user.
|
@@ -130,24 +163,24 @@ public static RootResponse askForPermissionResponse(String permissionContext, Co
|
130 | 163 | }
|
131 | 164 |
|
132 | 165 | RootResponse rootResponse = new RootResponse();
|
133 |
| - rootResponse.expect_user_response = true; |
| 166 | + rootResponse.expectUserResponse = true; |
134 | 167 |
|
135 | 168 | PermissionValueSpec permissionValueSpec = new PermissionValueSpec();
|
136 |
| - permissionValueSpec.opt_context = permissionContext; |
| 169 | + permissionValueSpec.optContext = permissionContext; |
137 | 170 | permissionValueSpec.permissions = new ArrayList<>(permissions);
|
138 | 171 |
|
139 | 172 | InputValueSpec inputValueSpec = new InputValueSpec();
|
140 | 173 | inputValueSpec.permission_value_spec = permissionValueSpec;
|
141 | 174 |
|
142 | 175 | ExpectedIntent expectedIntent = new ExpectedIntent(StandardIntents.PERMISSION);
|
143 |
| - expectedIntent.input_value_spec = inputValueSpec; |
| 176 | + expectedIntent.inputValueSpec = inputValueSpec; |
144 | 177 |
|
145 | 178 | 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); |
148 | 181 |
|
149 |
| - rootResponse.expected_inputs = new ArrayList<>(); |
150 |
| - rootResponse.expected_inputs.add(expectedInput); |
| 182 | + rootResponse.expectedInputs = new ArrayList<>(); |
| 183 | + rootResponse.expectedInputs.add(expectedInput); |
151 | 184 |
|
152 | 185 | return rootResponse;
|
153 | 186 | }
|
|
0 commit comments