简体   繁体   中英

.NET client library for Watson Assistant what is an _assistant object?

I am trying to communicate with my chatbot via a Windows Form App (using C#). I have installed the SDK into Visual Studio, but I am having trouble using it. I have read through all the documentation, including on GitHub, however, because this is my first time using the SDK, I am quite confused about how to get it to work. At this point, I simply want to be able to send a "Message" and read the chatbot's response. Which namespaces do I have to include (ie "using IBM.Watson..." )? Because I have tried authenticating but am getting the error: "namespace AssistantService could not be found" , as per the IAM authentication in dotnet guide on GitHub. Also, what is an "_assistant" object and how to I create one, the docs don't explain this so I keep getting the error "_assistant does not exist in the current context..."

This is the link that to the SDK I am following: https://github.com/watson-developer-cloud/dotnet-standard-sdk

I am trying to authenticate with the instructions at that link but am not succeeding. I am trying to use these instructions to call the Watson Assistant: https://github.com/watson-developer-cloud/dotnet-standard-sdk/tree/development/src/IBM.WatsonDeveloperCloud.Assistant.v1

****************UPDATE*****************

using System.Windows.Forms;
using IBM.WatsonDeveloperCloud.Assistant.v1.Model;
using IBM.WatsonDeveloperCloud.Assistant.v1;
using IBM.WatsonDeveloperCloud.Util;

namespace Watson_Assistant_Test
{
public partial class Form1 : Form
{
    AssistantService _assistant;
    string[] _questionArray = { "Hello there" };

    public Form1()
    {
        TokenOptions iamAssistantTokenOptions = new TokenOptions()
        {
            IamApiKey = "Y....H",
            IamUrl = "https://gateway-syd.watsonplatform.net/assistant/api"
        };
        _assistant = new AssistantService(iamAssistantTokenOptions, "2018-07-10");
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        MessageRequest messageRequest = new MessageRequest()
        {
            Input = new InputData()
            {
                Text = _questionArray[0]
            }
        };
        var result = _assistant.Message("d...5", messageRequest);
        label1.Text = result.ResponseJson.ToString();
    }
}
}

I think I am still not creating the AssistantObject correctly. I am getting this error: ServiceResponseException: The API query failed with status code NotFound: Not Found .

Thanks, Harry

[I am not a C# developer and have not used that SDK, but... :)]

There is a small sample as part of the SDK that works with the car dashboard example. Because of the renaming of Watson Conversation to Watson Assistant it is still using the old object names (both work).

The code uses this namespace:

using IBM.WatsonDeveloperCloud.Assistant.v1.Model

Based on the code itself it checks for the following parts of TokenOptions:

  • IamApiKey
  • IamAccessToken
  • ServiceUrl

My guess is that you have to rename IamUrl to ServiceUrl in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM