Found in service examples, a working conversation script. Thanks again to @Taj!
I feel like I am very very close to get it to work. I have done the samething on Raspberry Pi with TJBot, so I have all the accounts, and I linked all the credentials correctly including the workplace ID from Conversation tooling. I am using Unity 3D 5.5.1f1 and the latest SDK, the one that was updated 13 days ago.
I copied and pasted the sample code for conversation on SDK's github page into a brand new C# file:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
public class test : MonoBehaviour {
private Conversation m_Conversation = new Conversation();
private string m_WorkspaceID = "my ID on the conversation tooling site";
private string m_Input = "Hi Alex";
// Use this for initialization
void Start () {
Debug.Log("User: " + m_Input);
m_Conversation.Message(OnMessage, m_WorkspaceID, m_Input);
}
// Update is called once per frame
void Update () {
}
void OnMessage(MessageResponse resp, string customData)
{
//Parsing resp here
//foreach (Intent mi in resp.intents)
//Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
//resp.output.text causes an error
}
}
In the process of figuring out, I realized the onMessage function is missing a parameter (string customData), I added that with help from my friends.
Question Part II:
Thanks Taj for single handed answered all my questions! This helps me get to the core of my problem and here it is. I have updated the code above to reflect what I have in my implementation of the conversation service based on the sample code block provided on IBM's github page. https://github.com/watson-developer-cloud/unity-sdk#conversation
And this is what the Message function looks like in Watson/Scripts/Services/conversation.cs file:
/// <summary>
/// Message the specified workspaceId, input and callback.
/// </summary>
/// <param name="workspaceID">Workspace identifier.</param>
/// <param name="input">Input.</param>
/// <param name="callback">Callback.</param>
/// <param name="customData">Custom data.</param>
public bool Message(OnMessage callback, string workspaceID, string input, string customData = default(string))
{
if (string.IsNullOrEmpty(workspaceID))
throw new ArgumentNullException("workspaceId");
if (string.IsNullOrEmpty(input))
throw new ArgumentNullException("input");
if (callback == null)
throw new ArgumentNullException("callback");
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_MESSAGE);
if (connector == null)
return false;
string reqJson = "{{\"input\": {{\"text\": \"{0}\"}}}}";
string reqString = string.Format(reqJson, input);
MessageReq req = new MessageReq();
req.Callback = callback;
req.Headers["Content-Type"] = "application/json";
req.Headers["Accept"] = "application/json";
req.Parameters["version"] = Version.VERSION;
req.Function = "/" + workspaceID + "/message";
req.Data = customData;
req.Send = Encoding.UTF8.GetBytes(reqString);
req.OnResponse = MessageResp;
return connector.Send(req);
}
When I called and it returned true, however nothing happened afterward, no callback =/.
Thanks so much for any tips! Please help!
The response strings are an array in the resp object.
void OnMessage(MessageResponse resp, string customData)
{
foreach (Intent mi in resp.intents)
Debug.Log("intent: " + mi.intent + ", confidence: " + mi.confidence);
if (resp.output != null && resp.output.text.Length > 0)
foreach (string txt in resp.output.text)
Debug.Log("Output: " + txt);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With