2 releases (1 stable)

Uses old Rust 2015

1.0.0 Nov 15, 2017
0.1.0 Feb 18, 2017

#1079 in Machine learning

Custom license

12KB
181 lines

Witty

Unofficial wit.ai client library for Rust.

Disclamer

This is an unofficial client implementation! It comes with no guarantees and Wit.ai can't be held responsible for any bugs that may occure from using this library in your project.

This is a port of Wit.ai's official Ruby client to Rust

Notice

Wit.ai decided to close down their chat bot / conversation API on 2018-01-01. This decision lead to the deprecation of the run_actions and converse methods.

In consequence, this library now only handles communication with Wit.ai servers.

Reference the change log for detailed explanations as to what has been done to facilitate the transition.

Installation

This project is available on Crates.io, and can be installed with cargo.

[dependencies]
witty = "1.0.0"

Usage

To create a client you will need to get a token from Wit.ai.

extern crate witty;
use witty::Value; # Serde JSON value struct

fn main() {
    let token = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
    let client = witty::client(token);
    let result = client.message("What's the weather like?");

    match result {
        Ok(response) => println!("The server returns: {:?}", response),
        Err(error) => println!("Something went wrong... {:?}", error)
    };
}

Methods

The Client exposes a single method:

message

Used to query the API for the meaning of an input message.

message(
  message: &str
) -> Result<Value, super::http::HttpError>
  • message - The input message which wit.ai will process.

The returned value is the context with which the API responded.

Errors

All error structs contain a message and a code field. The message field is human-readable and describes the reason why this error occured alongside with any additional information gathered from the environment. The code field indicates where the error spawned and the class of issue it represents.

The following is a list of errors with their possible codes and explanations:

  • ExeccutionError

    • 102 - The API responded with an error type response.
    • 105 - The API responded with an unknown type.
    • 106 - There was a problem connecting to the API.
  • HttpError

    • 100 - Unable to connect to server
    • 101 - Server responded with message

Note: The HttpError struct also has an additional status field which contains the response's HTTP status code. This code will also be displayed in the message alongside with the canonical explanation.

License

This project is licensed under the MIT license. It's in no way affiliated with Wit.ai.

Dependencies

~18–28MB
~504K SLoC