Giter VIP home page Giter VIP logo

witty's Introduction

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.

witty's People

Contributors

jordonsc avatar monorkin avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

jordonsc kappa

witty's Issues

`client` module is private

I'm new to Rust so apologies if I'm a retard and this is just me.

Because the client module is private, it is impossible to define a Client instance without type inference, ie:

let foo: witty::client::Client = witty::client(...);

This is fine under normal circumstances as you can omit the type and let the compiler work it's magic, unless you're working in a data-structure -

struct foo {
    bar: witty::client::Client,
}

Therefore, to store a Client in a data-structure either the module client needs to be public or a pub use client::Client; line needs to be added at the lib level.

Again - if this is just my inexperience, my apologies.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.