IBM Watson Chat Service error: Cannot convert from "method group" to "chat.onMessage"

I am trying to start IBM Watson Support in unity and following here is a code snippet

private Conversation m_Conversation = new Conversation();
    private string m_WrokspaceID = "xyz";
    private string m_input = "help";


    // Use this for initialization
    void Start () {
        Debug.Log("user : " + m_input);
        m_Conversation.Message(OnMessage, m_WrokspaceID, m_input);
    }

    void OnMessage(MessageResponse resp, string customData) {
        foreach (Intent mi in resp.intents)
        {
            Debug.Log("intent : " + mi.intent + ", confidence :" + mi.confidence);
        }

        Debug.Log("response :" + resp.output.text);
    }

      

But I am getting this error

cannot convert from 'method group' to 'conversation.onMessage'

      

What am I doing wrong? The snippet of code I get from the official github repository watson.

Returning an object as a response: enter image description here

+3


source to share


2 answers


You can reverse the answer as a dictionary and try to get the value from there. By using a shared object instead of a static data model you can walk through the answer.



private void OnMessage(object resp, string customData)
{
    Dictionary<string, object> respDict = resp as Dictionary<string, object>;
    object intents;
    respDict.TryGetValue("intents", out intents);

    foreach(var intentObj in (intents as List<object>))
    {
        Dictionary<string, object> intentDict = intentObj as Dictionary<string, object>;

        object intentString;
        intentDict.TryGetValue("intent", out intentString);

        object confidenceString;
        intentDict.TryGetValue("confidence", out confidenceString);

        Log.Debug("ExampleConversation", "intent: {0} | confidence {1}", intentString.ToString(), confidenceString.ToString());
    }
}

      

+3


source


As per line 32 in the original code Conversation

, the delegate has been changed to:

public delegate void OnMessage(object resp, string customData);

      



You will need to change your method OnMessage

to reflect this:

void OnMessage(object resp, string customData) {
    // ...
}

      

+3


source







All Articles