Skip to content

Commit 7d509f1

Browse files
authored
Merge pull request #171 from watson-developer-cloud/feature-conversationLoopFix
Issues with Conversation example code
2 parents 2dca2e4 + 5368be6 commit 7d509f1

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

Examples/ServiceExamples/Scripts/ExampleConversation.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ private void OnMessageWithOnlyInput(MessageResponse resp, string customData)
5151
if (resp != null)
5252
{
5353
foreach (Intent mi in resp.intents)
54-
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
54+
Debug.Log("Message Only intent: " + mi.intent + ", confidence: " + mi.confidence);
5555

5656
if (resp.output != null && resp.output.text.Length > 0)
5757
foreach (string txt in resp.output.text)
58-
Debug.Log("output: " + txt);
58+
Debug.Log("Message Only output: " + txt);
5959

6060
string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
6161
Debug.Log(string.Format("**********User: {0}", questionStr));
@@ -69,14 +69,39 @@ private void OnMessageWithOnlyInput(MessageResponse resp, string customData)
6969
}
7070
else
7171
{
72-
Debug.Log("Failed to invoke Message();");
72+
Debug.Log("Message Only: Failed to invoke Message();");
7373
}
7474
}
7575

7676
private void MessageWithFullMessageRequest(MessageRequest messageRequest)
7777
{
7878
if (messageRequest == null)
7979
throw new ArgumentNullException("messageRequest");
80-
m_Conversation.Message(OnMessageWithOnlyInput, m_WorkspaceID, messageRequest);
80+
m_Conversation.Message(OnMessageWithFullRequest, m_WorkspaceID, messageRequest);
81+
}
82+
83+
private void OnMessageWithFullRequest(MessageResponse resp, string customData)
84+
{
85+
if (resp != null)
86+
{
87+
foreach (Intent mi in resp.intents)
88+
Debug.Log("Full Request intent: " + mi.intent + ", confidence: " + mi.confidence);
89+
90+
if (resp.output != null && resp.output.text.Length > 0)
91+
foreach (string txt in resp.output.text)
92+
Debug.Log("Full Request output: " + txt);
93+
94+
string questionStr = questionArray[UnityEngine.Random.Range(0, questionArray.Length - 1)];
95+
Debug.Log(string.Format("**********User: {0}", questionStr));
96+
97+
MessageRequest messageRequest = new MessageRequest();
98+
messageRequest.InputText = questionStr;
99+
messageRequest.alternate_intents = m_UseAlternateIntents;
100+
messageRequest.ContextData = resp.context;
101+
}
102+
else
103+
{
104+
Debug.Log("Full Request: Failed to invoke Message();");
105+
}
81106
}
82107
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void Start () {
316316
```
317317

318318
### Conversation
319-
With the IBM Watson™ [Conversation][conversation] service you can create cognitive agents - virtual agents that combine machine learning, natural language understanding, and integrated dialog scripting tools to provide outstanding customer engagements. A workspace should be created using [Conversation tooling][conversation_tooling] and a variable `ConversationV1_ID` should be set in the Config Editor with the Workspace ID. This is required for the service status check in the `Config Editor`.
319+
With the IBM Watson™ [Conversation][conversation] service you can create cognitive agents - virtual agents that combine machine learning, natural language understanding, and integrated dialog scripting tools to provide outstanding customer engagements. A workspace should be created using [Conversation tooling][conversation_tooling] and a variable `ConversationV1_ID` should be set in the Config Editor with the Workspace ID (In the Config Editor, click `Advanced Mode` and click `Add Variable`). This is required for the service status check in the `Config Editor`.
320320

321321
```cs
322322
private Conversation m_Conversation = new Conversation();

0 commit comments

Comments
 (0)