Muhammad Faizan Khan
Muhammad Faizan Khan

Reputation: 10551

IBM Watson conversation service error : cannot convert from 'method group' to 'conversation.onMessage'

I am trying to running IBM Watson conversation service in unity and following here, 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 i am doing wrong? The code snippet i get from watson official github repo.

Object returning as answer suggested: enter image description here

Upvotes: 3

Views: 263

Answers (2)

taj
taj

Reputation: 1138

You can cast the response as a dictionary and try to get the value from there. Using a generic object instead of a static data model, you are able to pass more through the response.

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

Upvotes: 3

haim770
haim770

Reputation: 49095

According to line 32 in the source code of Conversation, the delegate was changed to:

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

You'll have to change your OnMessage method to reflect that:

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

Upvotes: 3

Related Questions