Skip to content

Commit d7356d8

Browse files
committed
Fixing issue with error on sending message with conversation ID and empty system node
1 parent ac2e850 commit d7356d8

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

Examples/ServiceExamples/Scripts/ExampleConversation.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
2121
using IBM.Watson.DeveloperCloud.Utilities;
2222
using IBM.Watson.DeveloperCloud.Logging;
23+
using System;
2324

2425
public class ExampleConversation : MonoBehaviour
2526
{
2627
private Conversation m_Conversation = new Conversation();
2728
private string m_WorkspaceID;
2829
private string m_Input = "Can you unlock the door?";
30+
private string m_ConversationID;
2931

3032
void Start () {
3133
LogSystem.InstallDefaultReactors();
@@ -42,7 +44,9 @@ void Start () {
4244

4345
// Message by passing input, alternate intents and conversationID
4446
m_Conversation.Message(OnMessage, m_WorkspaceID, m_Input, false, null);
45-
}
47+
48+
Converse("is there traffic today?");
49+
}
4650

4751
void OnMessage (MessageResponse resp, string customData)
4852
{
@@ -54,10 +58,21 @@ void OnMessage (MessageResponse resp, string customData)
5458
if(resp.output != null && resp.output.text.Length > 0)
5559
foreach(string txt in resp.output.text)
5660
Debug.Log("output: " + txt);
61+
62+
m_ConversationID = resp.context.conversation_id;
63+
5764
}
5865
else
5966
{
6067
Debug.Log("Failed to invoke Message();");
6168
}
6269
}
70+
71+
private void Converse(string input)
72+
{
73+
if (string.IsNullOrEmpty(input))
74+
throw new ArgumentNullException("input");
75+
76+
m_Conversation.Message(OnMessage, m_WorkspaceID, input, true, m_ConversationID);
77+
}
6378
}

Examples/ServiceExamples/ServiceExamples.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ GameObject:
352352
m_Icon: {fileID: 0}
353353
m_NavMeshLayer: 0
354354
m_StaticEditorFlags: 0
355-
m_IsActive: 0
355+
m_IsActive: 1
356356
--- !u!114 &859102723
357357
MonoBehaviour:
358358
m_ObjectHideFlags: 0
@@ -593,7 +593,7 @@ GameObject:
593593
m_Icon: {fileID: 0}
594594
m_NavMeshLayer: 0
595595
m_StaticEditorFlags: 0
596-
m_IsActive: 1
596+
m_IsActive: 0
597597
--- !u!114 &1713392458
598598
MonoBehaviour:
599599
m_ObjectHideFlags: 0

Scripts/Services/Conversation/Conversation.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,29 +135,20 @@ public class Conversation : IWatsonService
135135
if (callback == null)
136136
throw new ArgumentNullException("callback");
137137

138-
MessageRequest messageRequest = new MessageRequest();
139-
messageRequest.inputText = input;
140-
messageRequest.alternate_intents = useAlternateIntents;
141-
if (conversationID != default(string))
142-
messageRequest.conversationID = conversationID;
143-
144138
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE);
145139
if (connector == null)
146140
return false;
147141

148-
fsData data;
149-
sm_Serializer.TrySerialize(messageRequest.GetType(), messageRequest, out data).AssertSuccessWithoutWarnings();
150-
string reqString = fsJsonPrinter.CompressedJson(data);
142+
string reqJson = "{\"input\":{\"text\":\"" + input + "\"},\"alternate_intents\":" + useAlternateIntents.ToString().ToLower() + ",\"context\":{\"conversation_id\":\"" + conversationID + "\"}}";
151143

152144
MessageReq req = new MessageReq();
153145
req.Callback = callback;
154-
req.MessageRequest = messageRequest;
155146
req.Headers["Content-Type"] = "application/json";
156147
req.Headers["Accept"] = "application/json";
157148
req.Parameters["version"] = Version.VERSION;
158149
req.Function = "/" + workspaceID + "/message";
159150
req.Data = customData;
160-
req.Send = Encoding.UTF8.GetBytes(reqString);
151+
req.Send = Encoding.UTF8.GetBytes(reqJson);
161152
req.OnResponse = MessageResp;
162153

163154
return connector.Send(req);

0 commit comments

Comments
 (0)