2020import java .lang .reflect .Type ;
2121import java .text .SimpleDateFormat ;
2222import java .util .Date ;
23+ import java .util .HashMap ;
2324import java .util .List ;
25+ import java .util .Map ;
2426import java .util .logging .Logger ;
2527
2628import org .apache .http .HttpResponse ;
@@ -61,6 +63,14 @@ public class DialogService extends WatsonService {
6163 private static final Logger log = Logger .getLogger (DialogService .class
6264 .getName ());
6365
66+ public static final String DIALOG_ID = "dialog_id" ;
67+
68+ public static final String CLIENT_ID = "client_id" ;
69+
70+ public static final String CONVERSATION_ID = "conversation_id" ;
71+
72+ public static final String INPUT = "input" ;
73+
6474 /** The url. */
6575 private static String URL = "https://gateway.watsonplatform.net/dialog-experimental/api" ;
6676
@@ -91,23 +101,6 @@ public DialogService() {
91101 setEndPoint (URL );
92102 }
93103
94- /**
95- * Starts or continue conversations.
96- *
97- * @param dialogId
98- * the dialog id
99- * @param conversation
100- * the conversation
101- * @param input
102- * the user input message
103- * @return the conversation
104- */
105- public Conversation converse (String dialogId , Conversation conversation ,
106- String input ) {
107- return converse (dialogId , conversation .getClientId (),
108- conversation .getId (), input );
109- }
110-
111104 /**
112105 * Starts or continue conversations.
113106 *
@@ -123,15 +116,17 @@ public Conversation converse(String dialogId, Conversation conversation,
123116 * the user input message
124117 * @return the conversation with the response
125118 */
126- public Conversation converse (final String dialogId , final Integer clientId ,
127- final Integer conversationId , final String input ) {
128- if (dialogId == null || dialogId .isEmpty ())
129- throw new IllegalArgumentException (
130- "dialogId can not be null or empty" );
131-
132- if (conversationId == null ) {
119+ public Conversation converse (Map <String , Object > params ) {
120+ final String dialogId = (String ) params .get ("dialog_id" );
121+ final String input = (String ) params .get ("input" );
122+ final Integer clientId = (Integer ) params .get ("client_id" );
123+ final Integer conversationId = (Integer ) params .get ("conversation_id" );
124+
125+ if (dialogId == null )
126+ throw new IllegalArgumentException ("dialog_id can not be null" );
127+
128+ if (conversationId == null )
133129 log .info ("Creating a new conversation with for dialog: " + dialogId );
134- }
135130
136131 if (clientId == null ) {
137132 log .info ("Creating a new client id with for dialog: " + dialogId );
@@ -147,8 +142,7 @@ public Conversation converse(final String dialogId, final Integer clientId,
147142 try {
148143 HttpResponse response = execute (request );
149144 String conversationAsJson = ResponseUtil .getString (response );
150- Conversation conversation = getGson ().fromJson (conversationAsJson ,
151- Conversation .class );
145+ Conversation conversation = getGson ().fromJson (conversationAsJson , Conversation .class );
152146 return conversation ;
153147 } catch (IOException e ) {
154148 throw new RuntimeException (e );
@@ -163,7 +157,9 @@ public Conversation converse(final String dialogId, final Integer clientId,
163157 * @return a new conversation
164158 */
165159 public Conversation createConversation (final String dialogId ) {
166- return converse (dialogId , null , null , null );
160+ Map <String , Object > params = new HashMap <String ,Object >();
161+ params .put (DIALOG_ID , dialogId );
162+ return converse (params );
167163 }
168164
169165 /**
0 commit comments