public class ResponseBuilder
Builder to assemble the response from the Actions webhook. Recommended way is to get the ResponseBuilder instance from the App instead of instantiating it directly.
Usage in an intent handler (class that extends DialogflowApp or ActionsSdkApp):
ActionRequest request = ...;
ResponseBuilder builder = getResponseBuilder(request);
ActionResponse response = builder
.add("some text")
.add(suggestions)
.build();
To end a conversation,
ActionRequest request = ...;
ResponseBuilder builder = getResponseBuilder(request);
ActionResponse response = builder
.add("some text")
.endConversation()
.build();
Alternatively, binding classes may be used directly to build a response. In this case, the appResponse may be used as follows:
ActionResponse response = builder.use(appResponse).build();
Modifier and Type | Method and Description |
---|---|
ResponseBuilder |
add(java.lang.String text)
Adds the specified text to the response. This is a short-cut to creating a
SimpleResponse
with the specified text as the display text and the text to speech.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.SimpleResponse simpleResponse)
Adds a SimpleResponse
to the response.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.BasicCard basicCard)
Adds a BasicCard
to the response.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.StructuredResponse structuredResponse)
Adds a StructuredResponse
to the response.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.MediaResponse mediaResponse)
Adds a MediaResponse
to the response.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.CarouselBrowse carousel)
Adds a CarouselBrowse
to the response.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.TableCard tableCard)
Adds a TableCard
to the response.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.RichResponse richResponse)
Adds a RichResponse
to the response.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.Suggestion suggestion)
Adds a Suggestion
to the response. A suggestion chip allows the user to tap to quickly
post a reply to the conversation.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.Image image)
Adds an Image
to the response. This is a short-cut to creating a basic card with just the
image.
|
ResponseBuilder |
add(HelperIntent helperIntent)
Adds a HelperIntent to the response.
|
ResponseBuilder |
add(com.google.api.services.actions_fulfillment.v2.model.LinkOutSuggestion linkOutSuggestion)
Adds a LinkOutSuggestion
to the response. A LinkOutSuggestion creates a suggestion chip that allows
the user to jump out to the App or Website associated with this agent.
|
ResponseBuilder |
add(NonExistentClass htmlResponse)
Adds a HtmlResponse
to the response. A HtmlResponse creates a visual, immersive experience to conversational
Actions.
|
ResponseBuilder |
add(ActionContext context)
Helper method to add an ActionContext to the response. Contexts are supported only on
Dialogflow.
|
ResponseBuilder |
addAll(java.util.List<com.google.api.services.actions_fulfillment.v2.model.Suggestion> suggestions)
Helper method to add multiple suggestions to the response.
|
ResponseBuilder |
addSuggestions(java.lang.String[] suggestions)
Helper method to add multiple suggestions to the response.
|
ActionResponse |
build()
Builds the ActionResponse based on the added artifacts.
Usage:
|
ResponseBuilder |
endConversation()
Marks the response as being the end of the conversation.
|
java.util.Map<java.lang.String,java.lang.Object> |
getConversationData() |
java.lang.String |
getSessionId() |
java.util.Map<java.lang.String,java.lang.Object> |
getUserStorage() |
boolean |
getUsesDialogflow() |
ResponseBuilder |
removeContext(java.lang.String name)
Helper method to remove an existing context. Contexts are supported only on Dialogflow.
|
ResponseBuilder |
use(com.google.api.services.actions_fulfillment.v2.model.AppResponse appResponse)
Uses the specified AppResponse instance to build a response.
|
ResponseBuilder |
use(com.google.api.services.dialogflow_fulfillment.v2.model.WebhookResponse webhookResponse)
Uses the specified WebhookResponse for the Dialogflow response.
For instance, this may be used to set the fulfillmentText part of the
Dialogflow response.
|
public ActionResponse build()
Builds the ActionResponse based on the added artifacts. Usage:
ActionResponse response = builder
.add("some text")
.add(basicCard)
.endConversation()
.build();
public ResponseBuilder use(com.google.api.services.actions_fulfillment.v2.model.AppResponse appResponse)
Uses the specified AppResponse instance to build a response.
Note that if AppResponse is provided, all other response items added using one of the add* methods are ignored when the output response is constructed.
Usage:
AppResponse appResponse = new AppResponse();
SimpleResponse simpleResponse = new SimpleResponse();
simpleResponse.setTextToSpeech(text);
simpleResponse.setDisplayText(displayText);
List items = new ArrayList();
items.add(new RichResponseItem().setSimpleResponse(simpleResponse));
RichResponse richResponse = new RichResponse();
richResponse.setItems(items);
appResponse.setFinalResponse(new FinalResponse()
.setRichResponse(richResponse));
var response = responseBuilder.use(appResponse).build();
public ResponseBuilder use(com.google.api.services.dialogflow_fulfillment.v2.model.WebhookResponse webhookResponse)
Uses the specified WebhookResponse for the Dialogflow response. For instance, this may be used to set the fulfillmentText part of the Dialogflow response.
Usage:
ActionRequest request = ...;
ResponseBuilder builder = getResponseBuilder(request);
WebhookResponse webhookResponse = new WebhookResponse();
webhookResponse.setFulfillmentText("Dialogflow fulfillment text");
builder.use(webhookResponse);
builder.add("some response");
public ResponseBuilder add(java.lang.String text)
Adds the specified text to the response. This is a short-cut to creating a SimpleResponse with the specified text as the display text and the text to speech.
text
- The text to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.SimpleResponse simpleResponse)
Adds a SimpleResponse to the response.
simpleResponse
- The SimpleResponse to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.BasicCard basicCard)
Adds a BasicCard to the response.
basicCard
- The BasicCard to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.StructuredResponse structuredResponse)
Adds a StructuredResponse to the response.
structuredResponse
- The StructuredResponse to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.MediaResponse mediaResponse)
Adds a MediaResponse to the response.
mediaResponse
- The MediaResponse to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.CarouselBrowse carousel)
Adds a CarouselBrowse to the response.
carousel
- The CarouselBrowse to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.TableCard tableCard)
Adds a TableCard to the response.
tableCard
- The TableCard to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.RichResponse richResponse)
Adds a RichResponse to the response.
richResponse
- The RichResponse to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.Suggestion suggestion)
Adds a Suggestion to the response. A suggestion chip allows the user to tap to quickly post a reply to the conversation.
suggestion
- The Suggestion to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.Image image)
Adds an Image to the response. This is a short-cut to creating a basic card with just the image.
image
- The Image to add.public ResponseBuilder add(HelperIntent helperIntent)
Adds a HelperIntent to the response.
helperIntent
- The HelperIntent to add.public ResponseBuilder add(com.google.api.services.actions_fulfillment.v2.model.LinkOutSuggestion linkOutSuggestion)
Adds a LinkOutSuggestion to the response. A LinkOutSuggestion creates a suggestion chip that allows the user to jump out to the App or Website associated with this agent.
linkOutSuggestion
- The LinkOutSuggestion to add.public ResponseBuilder add(NonExistentClass htmlResponse)
Adds a HtmlResponse to the response. A HtmlResponse creates a visual, immersive experience to conversational Actions.
htmlResponse
- The HtmlResponse to add.public ResponseBuilder addSuggestions(java.lang.String[] suggestions)
Helper method to add multiple suggestions to the response.
suggestions
- The suggestions to add.public ResponseBuilder addAll(java.util.List<com.google.api.services.actions_fulfillment.v2.model.Suggestion> suggestions)
Helper method to add multiple suggestions to the response.
suggestions
- The suggestions to add.public ResponseBuilder add(ActionContext context)
Helper method to add an ActionContext to the response. Contexts are supported only on Dialogflow.
context
- The ActionContext to add.public ResponseBuilder removeContext(java.lang.String name)
Helper method to remove an existing context. Contexts are supported only on Dialogflow.
name
- Name of the context to remove. Note that the name of the context must not be
prefixed with the sessionId.public ResponseBuilder endConversation()
Marks the response as being the end of the conversation.
public boolean getUsesDialogflow()
public java.lang.String getSessionId()
public java.util.Map<java.lang.String,java.lang.Object> getConversationData()
public java.util.Map<java.lang.String,java.lang.Object> getUserStorage()