use of com.ibm.watson.assistant.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class Assistant method createDialogNode.
/**
* Create dialog node.
*
* Create a new dialog node. This operation is limited to 500 requests per 30 minutes. For more information, see
* **Rate limiting**.
*
* @param createDialogNodeOptions the {@link CreateDialogNodeOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link DialogNode}
*/
public ServiceCall<DialogNode> createDialogNode(CreateDialogNodeOptions createDialogNodeOptions) {
Validator.notNull(createDialogNodeOptions, "createDialogNodeOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
String[] pathParameters = { createDialogNodeOptions.workspaceId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("dialog_node", createDialogNodeOptions.dialogNode());
if (createDialogNodeOptions.description() != null) {
contentJson.addProperty("description", createDialogNodeOptions.description());
}
if (createDialogNodeOptions.conditions() != null) {
contentJson.addProperty("conditions", createDialogNodeOptions.conditions());
}
if (createDialogNodeOptions.parent() != null) {
contentJson.addProperty("parent", createDialogNodeOptions.parent());
}
if (createDialogNodeOptions.previousSibling() != null) {
contentJson.addProperty("previous_sibling", createDialogNodeOptions.previousSibling());
}
if (createDialogNodeOptions.output() != null) {
contentJson.add("output", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.output()));
}
if (createDialogNodeOptions.context() != null) {
contentJson.add("context", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.context()));
}
if (createDialogNodeOptions.metadata() != null) {
contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.metadata()));
}
if (createDialogNodeOptions.nextStep() != null) {
contentJson.add("next_step", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.nextStep()));
}
if (createDialogNodeOptions.actions() != null) {
contentJson.add("actions", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.actions()));
}
if (createDialogNodeOptions.title() != null) {
contentJson.addProperty("title", createDialogNodeOptions.title());
}
if (createDialogNodeOptions.nodeType() != null) {
contentJson.addProperty("type", createDialogNodeOptions.nodeType());
}
if (createDialogNodeOptions.eventName() != null) {
contentJson.addProperty("event_name", createDialogNodeOptions.eventName());
}
if (createDialogNodeOptions.variable() != null) {
contentJson.addProperty("variable", createDialogNodeOptions.variable());
}
if (createDialogNodeOptions.digressIn() != null) {
contentJson.addProperty("digress_in", createDialogNodeOptions.digressIn());
}
if (createDialogNodeOptions.digressOut() != null) {
contentJson.addProperty("digress_out", createDialogNodeOptions.digressOut());
}
if (createDialogNodeOptions.digressOutSlots() != null) {
contentJson.addProperty("digress_out_slots", createDialogNodeOptions.digressOutSlots());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNode.class));
}
use of com.ibm.watson.assistant.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class Assistant method updateDialogNode.
/**
* Update dialog node.
*
* Update an existing dialog node with new or modified data. This operation is limited to 500 requests per 30 minutes.
* For more information, see **Rate limiting**.
*
* @param updateDialogNodeOptions the {@link UpdateDialogNodeOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link DialogNode}
*/
public ServiceCall<DialogNode> updateDialogNode(UpdateDialogNodeOptions updateDialogNodeOptions) {
Validator.notNull(updateDialogNodeOptions, "updateDialogNodeOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
String[] pathParameters = { updateDialogNodeOptions.workspaceId(), updateDialogNodeOptions.dialogNode() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (updateDialogNodeOptions.nodeType() != null) {
contentJson.addProperty("type", updateDialogNodeOptions.nodeType());
}
if (updateDialogNodeOptions.newActions() != null) {
contentJson.add("actions", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newActions()));
}
if (updateDialogNodeOptions.newConditions() != null) {
contentJson.addProperty("conditions", updateDialogNodeOptions.newConditions());
}
if (updateDialogNodeOptions.newContext() != null) {
contentJson.add("context", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newContext()));
}
if (updateDialogNodeOptions.newPreviousSibling() != null) {
contentJson.addProperty("previous_sibling", updateDialogNodeOptions.newPreviousSibling());
}
if (updateDialogNodeOptions.newVariable() != null) {
contentJson.addProperty("variable", updateDialogNodeOptions.newVariable());
}
if (updateDialogNodeOptions.newMetadata() != null) {
contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newMetadata()));
}
if (updateDialogNodeOptions.newTitle() != null) {
contentJson.addProperty("title", updateDialogNodeOptions.newTitle());
}
if (updateDialogNodeOptions.newDescription() != null) {
contentJson.addProperty("description", updateDialogNodeOptions.newDescription());
}
if (updateDialogNodeOptions.newDigressOut() != null) {
contentJson.addProperty("digress_out", updateDialogNodeOptions.newDigressOut());
}
if (updateDialogNodeOptions.newEventName() != null) {
contentJson.addProperty("event_name", updateDialogNodeOptions.newEventName());
}
if (updateDialogNodeOptions.newDigressOutSlots() != null) {
contentJson.addProperty("digress_out_slots", updateDialogNodeOptions.newDigressOutSlots());
}
if (updateDialogNodeOptions.newNextStep() != null) {
contentJson.add("next_step", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newNextStep()));
}
if (updateDialogNodeOptions.newDigressIn() != null) {
contentJson.addProperty("digress_in", updateDialogNodeOptions.newDigressIn());
}
if (updateDialogNodeOptions.newOutput() != null) {
contentJson.add("output", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newOutput()));
}
if (updateDialogNodeOptions.newParent() != null) {
contentJson.addProperty("parent", updateDialogNodeOptions.newParent());
}
if (updateDialogNodeOptions.newDialogNode() != null) {
contentJson.addProperty("dialog_node", updateDialogNodeOptions.newDialogNode());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNode.class));
}
use of com.ibm.watson.assistant.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method testGetDialogNode.
/**
* Test getDialogNode.
*/
@Test
public void testGetDialogNode() {
String dialogNodeName = "Test" + UUID.randomUUID().toString();
String dialogNodeDescription = "Description of " + dialogNodeName;
Date start = new Date();
CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
service.createDialogNode(createOptions).execute();
try {
GetDialogNodeOptions getOptions = new GetDialogNodeOptions.Builder().workspaceId(workspaceId).dialogNode(dialogNodeName).includeAudit(true).build();
DialogNode response = service.getDialogNode(getOptions).execute();
assertNotNull(response);
assertNotNull(response.getDialogNodeId());
assertEquals(response.getDialogNodeId(), dialogNodeName);
assertNotNull(response.getDescription());
assertEquals(response.getDescription(), dialogNodeDescription);
assertNotNull(response.getCreated());
assertNotNull(response.getUpdated());
Date now = new Date();
assertTrue(fuzzyBefore(response.getCreated(), now));
assertTrue(fuzzyAfter(response.getCreated(), start));
assertTrue(fuzzyBefore(response.getUpdated(), now));
assertTrue(fuzzyAfter(response.getUpdated(), start));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName).build();
service.deleteDialogNode(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class AssistantTest method testUpdateDialogNodeWOptions.
// Test the updateDialogNode operation with a valid options model parameter
@Test
public void testUpdateDialogNodeWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"dialog_node\": \"dialogNode\", \"description\": \"description\", \"conditions\": \"conditions\", \"parent\": \"parent\", \"previous_sibling\": \"previousSibling\", \"output\": {\"generic\": [{\"response_type\": \"video\", \"source\": \"source\", \"title\": \"title\", \"description\": \"description\", \"channels\": [{\"channel\": \"chat\"}], \"channel_options\": {\"mapKey\": \"anyValue\"}, \"alt_text\": \"altText\"}], \"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}, \"modifiers\": {\"overwrite\": true}}, \"context\": {\"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}}, \"metadata\": {\"mapKey\": \"anyValue\"}, \"next_step\": {\"behavior\": \"get_user_input\", \"dialog_node\": \"dialogNode\", \"selector\": \"condition\"}, \"title\": \"title\", \"type\": \"standard\", \"event_name\": \"focus\", \"variable\": \"variable\", \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"digress_in\": \"not_available\", \"digress_out\": \"allow_returning\", \"digress_out_slots\": \"not_allowed\", \"user_label\": \"userLabel\", \"disambiguation_opt_out\": false, \"disabled\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
String updateDialogNodePath = "/v1/workspaces/testString/dialog_nodes/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ResponseGenericChannel model
ResponseGenericChannel responseGenericChannelModel = new ResponseGenericChannel.Builder().channel("chat").build();
// Construct an instance of the DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo model
DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo dialogNodeOutputGenericModel = new DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo.Builder().responseType("video").source("testString").title("testString").description("testString").channels(new java.util.ArrayList<ResponseGenericChannel>(java.util.Arrays.asList(responseGenericChannelModel))).channelOptions(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).altText("testString").build();
// Construct an instance of the DialogNodeOutputModifiers model
DialogNodeOutputModifiers dialogNodeOutputModifiersModel = new DialogNodeOutputModifiers.Builder().overwrite(true).build();
// Construct an instance of the DialogNodeOutput model
DialogNodeOutput dialogNodeOutputModel = new DialogNodeOutput.Builder().generic(new java.util.ArrayList<DialogNodeOutputGeneric>(java.util.Arrays.asList(dialogNodeOutputGenericModel))).integrations(new java.util.HashMap<String, Map<String, Object>>() {
{
put("foo", new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
}
}).modifiers(dialogNodeOutputModifiersModel).add("foo", "testString").build();
// Construct an instance of the DialogNodeContext model
DialogNodeContext dialogNodeContextModel = new DialogNodeContext.Builder().integrations(new java.util.HashMap<String, Map<String, Object>>() {
{
put("foo", new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
}
}).add("foo", "testString").build();
// Construct an instance of the DialogNodeNextStep model
DialogNodeNextStep dialogNodeNextStepModel = new DialogNodeNextStep.Builder().behavior("get_user_input").dialogNode("testString").selector("condition").build();
// Construct an instance of the DialogNodeAction model
DialogNodeAction dialogNodeActionModel = new DialogNodeAction.Builder().name("testString").type("client").parameters(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).resultVariable("testString").credentials("testString").build();
// Construct an instance of the UpdateDialogNodeOptions model
UpdateDialogNodeOptions updateDialogNodeOptionsModel = new UpdateDialogNodeOptions.Builder().workspaceId("testString").dialogNode("testString").newDialogNode("testString").newDescription("testString").newConditions("testString").newParent("testString").newPreviousSibling("testString").newOutput(dialogNodeOutputModel).newContext(dialogNodeContextModel).newMetadata(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).newNextStep(dialogNodeNextStepModel).newTitle("testString").newType("standard").newEventName("focus").newVariable("testString").newActions(new java.util.ArrayList<DialogNodeAction>(java.util.Arrays.asList(dialogNodeActionModel))).newDigressIn("not_available").newDigressOut("allow_returning").newDigressOutSlots("not_allowed").newUserLabel("testString").newDisambiguationOptOut(false).includeAudit(false).build();
// Invoke updateDialogNode() with a valid options model and verify the result
Response<DialogNode> response = assistantService.updateDialogNode(updateDialogNodeOptionsModel).execute();
assertNotNull(response);
DialogNode responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, updateDialogNodePath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
use of com.ibm.watson.assistant.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class AssistantTest method testGetWorkspaceWOptions.
// Test the getWorkspace operation with a valid options model parameter
@Test
public void testGetWorkspaceWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"name\": \"name\", \"description\": \"description\", \"language\": \"language\", \"workspace_id\": \"workspaceId\", \"dialog_nodes\": [{\"dialog_node\": \"dialogNode\", \"description\": \"description\", \"conditions\": \"conditions\", \"parent\": \"parent\", \"previous_sibling\": \"previousSibling\", \"output\": {\"generic\": [{\"response_type\": \"video\", \"source\": \"source\", \"title\": \"title\", \"description\": \"description\", \"channels\": [{\"channel\": \"chat\"}], \"channel_options\": {\"mapKey\": \"anyValue\"}, \"alt_text\": \"altText\"}], \"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}, \"modifiers\": {\"overwrite\": true}}, \"context\": {\"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}}, \"metadata\": {\"mapKey\": \"anyValue\"}, \"next_step\": {\"behavior\": \"get_user_input\", \"dialog_node\": \"dialogNode\", \"selector\": \"condition\"}, \"title\": \"title\", \"type\": \"standard\", \"event_name\": \"focus\", \"variable\": \"variable\", \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"digress_in\": \"not_available\", \"digress_out\": \"allow_returning\", \"digress_out_slots\": \"not_allowed\", \"user_label\": \"userLabel\", \"disambiguation_opt_out\": false, \"disabled\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"counterexamples\": [{\"text\": \"text\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"learning_opt_out\": false, \"system_settings\": {\"tooling\": {\"store_generic_responses\": false}, \"disambiguation\": {\"prompt\": \"prompt\", \"none_of_the_above_prompt\": \"noneOfTheAbovePrompt\", \"enabled\": false, \"sensitivity\": \"auto\", \"randomize\": false, \"max_suggestions\": 1, \"suggestion_text_policy\": \"suggestionTextPolicy\"}, \"human_agent_assist\": {\"mapKey\": \"anyValue\"}, \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"system_entities\": {\"enabled\": false}, \"off_topic\": {\"enabled\": false}}, \"status\": \"Non Existent\", \"webhooks\": [{\"url\": \"url\", \"name\": \"name\", \"headers\": [{\"name\": \"name\", \"value\": \"value\"}]}], \"intents\": [{\"intent\": \"intent\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"examples\": [{\"text\": \"text\", \"mentions\": [{\"entity\": \"entity\", \"location\": [8]}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}], \"entities\": [{\"entity\": \"entity\", \"description\": \"description\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"fuzzy_match\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"values\": [{\"value\": \"value\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"type\": \"synonyms\", \"synonyms\": [\"synonym\"], \"patterns\": [\"pattern\"], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}]}";
String getWorkspacePath = "/v1/workspaces/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the GetWorkspaceOptions model
GetWorkspaceOptions getWorkspaceOptionsModel = new GetWorkspaceOptions.Builder().workspaceId("testString").export(false).includeAudit(false).sort("stable").build();
// Invoke getWorkspace() with a valid options model and verify the result
Response<Workspace> response = assistantService.getWorkspace(getWorkspaceOptionsModel).execute();
assertNotNull(response);
Workspace responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getWorkspacePath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Boolean.valueOf(query.get("export")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
assertEquals(query.get("sort"), "stable");
}
Aggregations