Java client library for Wit.ai
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
com.featurefactory.wit-java-example
com.featurefactory.wit-java
gradle/wrapper
.gitignore
.travis.yml
README.md
build.gradle
gradlew
gradlew.bat
settings.gradle

README.md

wit-java

Java client library for Wit.ai

Build Status

The library is under development so you are welcome to do pull requests

Getting started with library

Init client

WitClient client = new WitClientBuilder(config.getWitToken())
                       .addActionHandler("getJoke", new JokeAction())
                       .setMessageHandler(new BotMessageHandler(this)).build();

Implement handlers

public class BotMessageHandler implements MessageHandler {

    @Override
    public void sendMessage(String message, Map<String, Object> chatMetadata) {
        Bot.sentMessage(message);
    }
}

public class JokeAction implements ActionHandler{

    @Override
    public ChatContext run(Map<String, List<Map<String, Object>>> entities, ChatContext context) {

        if(entities.containsKey("joke")){
            String joke = JokeDAO.getRandomJoke();
            context.setValue("joke", joke);
        }
        return context;
    }
}

Process incoming messages

            String session = sessions.containsKey(getChatId())? sessions.get(getChatId()):UUID.randomUUID().toString();
            boolean isContinue = client.converse(message, session, context);

            if(isContinue){
                sessions.put(getChatId(), session);
            } else {
                sessions.remove(getChatId());
            }