This is a .NET implementation of Wit.ai client library powered by .net standard 2.0
The default API version is 20170307.
You can target a specific version by setting the variable WIT_API_VERSION.
wit.net provides a Wit class with the following methods:
Message- the Wit message APIConverse- the low-level Wit converse APIRunActions- a higher-level method to the Wit converse APIInteractive- starts an interactive conversation with your botSendVoice- sends a voice message to wit.ai and gets an accurate response. It supports many languages.
The Wit constructor takes the following parameters:
accessToken- the access token of your Wit instanceactions- (optional if you only useMessage()) the dictionary with your actions
actions has action names as keys and action implementations as values.
A minimal example looks like this:
static void Main(string[] args)
{
var actions = new WitActions();
actions["send"] = Send;
Wit client = new Wit(accessToken: accessToken, actions: actions);
}
private static WitContext Send(ConverseRequest request, ConverseResponse response)
{
// Do something with the Context
return request.Context;
}The Wit message API.
Takes the following parameters:
msg- the text you want Wit.ai to extract the information fromverbose- (optional) if set, calls the API withverbose=true
Example:
var response = client.Message("what is the weather in London?");
Console.WriteLine("Yay, got Wit.ai response: " + response)The Wit Speech API.
Takes the following parameter:
soundLocation- the location of the voice message or audio file that you want to send to wit.ai. It can be eitherMP3,WAV,ulaworRaw.
A higher-level method to the Wit converse API.
RunActions resets the last turn on new messages and errors.
Takes the following parameters:
sessionId- a unique identifier describing the user sessionmessage- the text received from the usercontext- the dict representing the session statemaxSteps- (optional) the maximum number of actions to execute (defaults to 5)verbose- (optional) if set, calls the API withverbose=true
Example:
string sessionId = "my-user-session-42";
var context0 = new WitContext();
var context1 = client.RunActions(sessionId, "what is the weather in London?", context0);
Console.WriteLine("The session state is now: " + context1);
var context2 = client.RunActions(sessionId, "and in Brussels?", context1);
Console.WriteLine("The session state is now: ' + context2);The low-level Wit converse API.
Takes the following parameters:
sessionId- a unique identifier describing the user sessionmessage- the text received from the usercontext- the dict representing the session statereset- (optional) whether to reset the last turnverbose- (optional) if set, sets the API parameterverbosetotrue
Example:
var response = client.Converse("my-user-session-42", "what is the weather in London?", new WitContext());
Console.WriteLine("Yay, got Wit.ai response: " + resp)Starts an interactive conversation with your bot.
Example:
client.Interactive()See the docs for more information.