c# - IBM Watson 对话服务错误 : cannot convert from 'method group' to 'conversation.onMessage'

标签 c# unity3d ibm-cloud chatbot watson-conversation

我正在尝试统一运行 IBM Watson 对话服务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);
    }

但是我收到了这个错误

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

我做错了什么?我从 watson 官方 github repo 获得的代码片段。

作为建议的答案返回的对象: enter image description here

最佳答案

您可以将响应转换为字典并尝试从那里获取值。使用通用对象而不是静态数据模型,您可以通过响应传递更多信息。

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

关于c# - IBM Watson 对话服务错误 : cannot convert from 'method group' to 'conversation.onMessage' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45953300/

相关文章:

c# - 如何在 Unity3D ARToolKit 6 中为 OnMarkerFound 注册事件?

c# - Unity3D C# 中的相机旋转问题(可能很容易修复)

python - 如何使用 Watson Studio 获取 IBM COS Bucket 中的文件列表

c# - 这些获取当前目录的方式有什么区别?

c# - 如何使游戏中的物体更好地移动

c# - 在c#中提取以某物开头和结尾的字符串

crash - 我应该如何调查导致 Bluemix 崩溃的原因?

node.js - 迭戈迁移 : 502 Bad Gateway

c# - 使用 Activator.CreateInstance 后转换为正确的类型

c# - OpenCL 内核问题