Skip to content

Commit 948bf3e

Browse files
authored
Merge pull request #89 from watson-developer-cloud/feature-87-conversationServiceStatus
Feature 87 conversation service status
2 parents 06acf37 + d0f0114 commit 948bf3e

File tree

5 files changed

+66
-14
lines changed

5 files changed

+66
-14
lines changed

Config.json.enc

128 Bytes
Binary file not shown.

Examples/ServiceExamples/Scripts/ExampleConversation.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
public class ExampleConversation : MonoBehaviour
2323
{
2424
private Conversation m_Conversation = new Conversation();
25-
private string m_WorkspaceID = "car_demo_1";
25+
private string m_WorkspaceID = "25dfa8a0-0263-471b-8980-317e68c30488";
2626
private string m_Input = "Can you unlock the door?";
2727

2828
void Start () {
@@ -32,9 +32,17 @@ void Start () {
3232

3333
void OnMessage (DataModels.MessageResponse resp)
3434
{
35-
foreach(DataModels.MessageIntent mi in resp.intents)
36-
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
37-
38-
Debug.Log("response: " + resp.output.text);
35+
if(resp != null)
36+
{
37+
foreach(DataModels.MessageIntent mi in resp.intents)
38+
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
39+
40+
if(resp.output != null && !string.IsNullOrEmpty(resp.output.text))
41+
Debug.Log("response: " + resp.output.text);
42+
}
43+
else
44+
{
45+
Debug.Log("Failed to invoke Message();");
46+
}
3947
}
4048
}

Examples/ServiceExamples/ServiceExamples.unity

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,45 @@ Transform:
249249
m_Children: []
250250
m_Father: {fileID: 0}
251251
m_RootOrder: 6
252+
--- !u!1 &748186939
253+
GameObject:
254+
m_ObjectHideFlags: 0
255+
m_PrefabParentObject: {fileID: 0}
256+
m_PrefabInternal: {fileID: 0}
257+
serializedVersion: 4
258+
m_Component:
259+
- 4: {fileID: 748186941}
260+
- 114: {fileID: 748186940}
261+
m_Layer: 0
262+
m_Name: ExampleAlchemyLanguage
263+
m_TagString: Untagged
264+
m_Icon: {fileID: 0}
265+
m_NavMeshLayer: 0
266+
m_StaticEditorFlags: 0
267+
m_IsActive: 1
268+
--- !u!114 &748186940
269+
MonoBehaviour:
270+
m_ObjectHideFlags: 0
271+
m_PrefabParentObject: {fileID: 0}
272+
m_PrefabInternal: {fileID: 0}
273+
m_GameObject: {fileID: 748186939}
274+
m_Enabled: 1
275+
m_EditorHideFlags: 0
276+
m_Script: {fileID: 11500000, guid: 9d5294a7b05214c5690d02420b87a821, type: 3}
277+
m_Name:
278+
m_EditorClassIdentifier:
279+
--- !u!4 &748186941
280+
Transform:
281+
m_ObjectHideFlags: 0
282+
m_PrefabParentObject: {fileID: 0}
283+
m_PrefabInternal: {fileID: 0}
284+
m_GameObject: {fileID: 748186939}
285+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
286+
m_LocalPosition: {x: 299.5, y: 291.5, z: 0}
287+
m_LocalScale: {x: 1, y: 1, z: 1}
288+
m_Children: []
289+
m_Father: {fileID: 0}
290+
m_RootOrder: 11
252291
--- !u!1 &859102722
253292
GameObject:
254293
m_ObjectHideFlags: 0
@@ -538,7 +577,7 @@ GameObject:
538577
m_Icon: {fileID: 0}
539578
m_NavMeshLayer: 0
540579
m_StaticEditorFlags: 0
541-
m_IsActive: 1
580+
m_IsActive: 0
542581
--- !u!114 &2004886372
543582
MonoBehaviour:
544583
m_ObjectHideFlags: 0

Scripts/Services/Conversation/Conversation.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class Conversation : IWatsonService
5757
private const string SERVICE_ID = "ConversationV1";
5858
private static fsSerializer sm_Serializer = new fsSerializer();
5959
#endregion
60-
60+
/*
6161
#region Workspaces
6262
/// <summary>
6363
/// Gets the available workspaces for the Conversation service
@@ -113,8 +113,9 @@ private void OnGetWorkspacesResp(RESTConnector.Request req, RESTConnector.Respon
113113
((GetWorkspacesReq)req).Callback(resp.Success ? workspaces : null);
114114
}
115115
#endregion
116-
116+
*/
117117
#region Message
118+
private const string SERVICE_MESSAGE = "/v1/workspaces";
118119
/// <summary>
119120
/// Message the specified workspaceId, input and callback.
120121
/// </summary>
@@ -130,7 +131,7 @@ public bool Message(string workspaceId, string input, OnMessage callback)
130131
if(callback == null)
131132
throw new ArgumentNullException("callback");
132133

133-
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v2/rest/workspaces");
134+
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE);
134135
if(connector == null)
135136
return false;
136137

@@ -140,6 +141,8 @@ public bool Message(string workspaceId, string input, OnMessage callback)
140141
MessageReq req = new MessageReq();
141142
req.Callback = callback;
142143
req.Headers["Content-Type"] = "application/json";
144+
req.Headers["Accept"] = "application/json";
145+
req.Parameters["version"] = DataModels.CONVERSATION_VERSION;
143146
req.Function = "/" + workspaceId + "/message";
144147
req.Send = Encoding.UTF8.GetBytes(reqString);
145148
req.OnResponse = MessageResp;
@@ -227,18 +230,19 @@ public CheckServiceStatus(Conversation service, ServiceStatus callback)
227230
if (!string.IsNullOrEmpty(customServiceID))
228231
{
229232

230-
if (!m_Service.Message(customServiceID, "Hello", OnMessage))
233+
if (!m_Service.Message(customServiceID, "Ping", OnMessage))
231234
OnFailure("Failed to invoke Converse().");
232235
else
233236
m_ConversationCount += 1;
234237
}
235238
else
236239
{
237-
if (!m_Service.GetWorkspaces(OnGetWorkspaces))
238-
OnFailure("Failed to invoke GetDialogs().");
240+
// if (!m_Service.GetWorkspaces(OnGetWorkspaces))
241+
// OnFailure("Failed to invoke GetDialogs().");
242+
OnFailure("Please define a workspace variable in config.json (" + SERVICE_ID + "_ID)");
239243
}
240244
}
241-
245+
/*
242246
private void OnGetWorkspaces(DataModels.Workspaces workspaces)
243247
{
244248
if (m_Callback != null)
@@ -254,7 +258,7 @@ private void OnGetWorkspaces(DataModels.Workspaces workspaces)
254258
else
255259
OnFailure("GetMessages() failed.");
256260
}
257-
261+
*/
258262
private void OnMessage(DataModels.MessageResponse resp)
259263
{
260264
if (m_ConversationCount > 0)

Scripts/Services/Conversation/DataModels.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace IBM.Watson.DeveloperCloud.Services.Conversation.v1
2020
{
2121
public class DataModels {
22+
public const string CONVERSATION_VERSION = "2016-05-19";
2223
#region Workspaces
2324
/// <summary>
2425
/// Workspaces.

0 commit comments

Comments
 (0)