IBM Watson Unity 3D SDK Conservation Service (almost works!)

Found in the service examples working script dialog. Thanks again @Taj!

I feel very close to make it work. I did the same on Raspberry Pi with TJBot, so I have all the accounts, and I correctly linked all the credentials, including the workstation ID, from the Conversation tool. I am using Unity 3D 5.5.1f1 and the latest SDK, the one that was updated 13 days ago.

I copied and pasted a sample conversation code on the gigub page on the SDK into a 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 finding out, I realized that the onMessage function does not have a parameter (string customData), I added this with the help of my friends.

Question Part II:

! , . , , , , IBM github. https://github.com/watson-developer-cloud/unity-sdk#conversation

Message Watson/Scripts/Services/convers.cs:

/// <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);
}

, , , callback =/.

! , !

+4
1

.

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);
}
+8

Source: https://habr.com/ru/post/1669194/


All Articles