Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Config.json.enc
Binary file not shown.
18 changes: 13 additions & 5 deletions Examples/ServiceExamples/Scripts/ExampleConversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class ExampleConversation : MonoBehaviour
{
private Conversation m_Conversation = new Conversation();
private string m_WorkspaceID = "car_demo_1";
private string m_WorkspaceID = "25dfa8a0-0263-471b-8980-317e68c30488";
private string m_Input = "Can you unlock the door?";

void Start () {
Expand All @@ -32,9 +32,17 @@ void Start () {

void OnMessage (DataModels.MessageResponse resp)
{
foreach(DataModels.MessageIntent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);

Debug.Log("response: " + resp.output.text);
if(resp != null)
{
foreach(DataModels.MessageIntent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);

if(resp.output != null && !string.IsNullOrEmpty(resp.output.text))
Debug.Log("response: " + resp.output.text);
}
else
{
Debug.Log("Failed to invoke Message();");
}
}
}
41 changes: 40 additions & 1 deletion Examples/ServiceExamples/ServiceExamples.unity
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,45 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
--- !u!1 &748186939
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 748186941}
- 114: {fileID: 748186940}
m_Layer: 0
m_Name: ExampleAlchemyLanguage
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &748186940
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 748186939}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9d5294a7b05214c5690d02420b87a821, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &748186941
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 748186939}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 299.5, y: 291.5, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
--- !u!1 &859102722
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -538,7 +577,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!114 &2004886372
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
20 changes: 12 additions & 8 deletions Scripts/Services/Conversation/Conversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class Conversation : IWatsonService
private const string SERVICE_ID = "ConversationV1";
private static fsSerializer sm_Serializer = new fsSerializer();
#endregion

/*
#region Workspaces
/// <summary>
/// Gets the available workspaces for the Conversation service
Expand Down Expand Up @@ -113,8 +113,9 @@ private void OnGetWorkspacesResp(RESTConnector.Request req, RESTConnector.Respon
((GetWorkspacesReq)req).Callback(resp.Success ? workspaces : null);
}
#endregion

*/
#region Message
private const string SERVICE_MESSAGE = "/v1/workspaces";
/// <summary>
/// Message the specified workspaceId, input and callback.
/// </summary>
Expand All @@ -130,7 +131,7 @@ public bool Message(string workspaceId, string input, OnMessage callback)
if(callback == null)
throw new ArgumentNullException("callback");

RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v2/rest/workspaces");
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE);
if(connector == null)
return false;

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

if (!m_Service.Message(customServiceID, "Hello", OnMessage))
if (!m_Service.Message(customServiceID, "Ping", OnMessage))
OnFailure("Failed to invoke Converse().");
else
m_ConversationCount += 1;
}
else
{
if (!m_Service.GetWorkspaces(OnGetWorkspaces))
OnFailure("Failed to invoke GetDialogs().");
// if (!m_Service.GetWorkspaces(OnGetWorkspaces))
// OnFailure("Failed to invoke GetDialogs().");
OnFailure("Please define a workspace variable in config.json (" + SERVICE_ID + "_ID)");
}
}

/*
private void OnGetWorkspaces(DataModels.Workspaces workspaces)
{
if (m_Callback != null)
Expand All @@ -254,7 +258,7 @@ private void OnGetWorkspaces(DataModels.Workspaces workspaces)
else
OnFailure("GetMessages() failed.");
}

*/
private void OnMessage(DataModels.MessageResponse resp)
{
if (m_ConversationCount > 0)
Expand Down
1 change: 1 addition & 0 deletions Scripts/Services/Conversation/DataModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace IBM.Watson.DeveloperCloud.Services.Conversation.v1
{
public class DataModels {
public const string CONVERSATION_VERSION = "2016-05-19";
#region Workspaces
/// <summary>
/// Workspaces.
Expand Down