froesmatheus / wit.net

C# library for Wit.ai https://wit.ai
MIT License
8 stars 6 forks source link
bot dotnet wit wit-converse-api witai

Wit.NET

Wit.NET is the C# SDK for Wit.ai.

Install

NuGet Package

Usage

See the examples folder for examples.

API

Versioning

The default API version is 20170107. You can target a specific version by setting the variable WIT_API_VERSION.

Overview

wit.net provides a Wit class with the following methods:

Wit class

The Wit constructor takes the following parameters:

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

.Message()

The Wit message API.

Takes the following parameters:

Example:

var response = client.Message("what is the weather in London?");
Console.WriteLine("Yay, got Wit.ai response: " + response)

.RunActions()

A higher-level method to the Wit converse API. RunActions resets the last turn on new messages and errors.

Takes the following parameters:

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

.Converse()

The low-level Wit converse API.

Takes the following parameters:

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)

.Interactive()

Starts an interactive conversation with your bot.

Example:

client.Interactive()

See the docs for more information.

Contribute

If you would like to contribute to this project, just send a pull request, open an issue or email me