... | ... | @@ -47,3 +47,70 @@ Everything related to API.ai questions is located in `be.maximvdw.qaplugin.api.* |
|
|
However if you are only interested in creating intents/entities and not responding to them
|
|
|
you will do with `be.maximvdw.qaplugin.api.ai.*`
|
|
|
|
|
|
### Creating an AIModule
|
|
|
An AIModule is basically the same as a dynamic response for a question. But instead for a local question it is for an API.ai question. When API.ai detects your question, it will extract the parameters and return them to the QAPlugin. The plugin will then call your AIModule with that information so you can do with it whatever you want.
|
|
|
|
|
|
To create a module the only thing you have to do is create a class and make it extend `be.maximvdw.qaplugin.api.AIModule`
|
|
|
|
|
|
```java
|
|
|
public class MyModule extends AIModule{
|
|
|
|
|
|
public MyModule() {
|
|
|
super("modulename","Maximvdw","Description here");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getResponse(AIQuestionEvent event) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
```
|
|
|
If you are creating a module the class will automatically be initialized, if you are adding this inside a plugin you will have to initialize the class in order for it to be registered. Make sure to do a check to see if the QAPlugin is installed before doing so.
|
|
|
|
|
|
The first argument of the constructor is the **action name**, this is the name of your action and has to be the same as the action you put in your intent response.
|
|
|
The second argument is the name of the author and the third argument is a simple description of the module.
|
|
|
|
|
|
The `getResponse` expects a string to be returned as the answer. It comes with an `AIQuestionEvent` containing everything you need ranging from the player who asked the question to the possible responses and parameters.
|
|
|
|
|
|
### Creating an entity
|
|
|
```java
|
|
|
// This is an entity
|
|
|
// An entity is a 'subject' you are talking about
|
|
|
// For example: When talking about "sapling's"
|
|
|
// you know it can be Birch, Normal, Spine,...
|
|
|
// This allows for better matching
|
|
|
Entity myTiers = new Entity("myTiersEntity")
|
|
|
.addEntry(new EntityEntry("Diamond Tier")
|
|
|
.addSynonym("diamond"))
|
|
|
.addEntry(new EntityEntry("Gold tier")
|
|
|
.addSynonym("gold"))
|
|
|
.addEntry(new EntityEntry("BlahBlah tier")
|
|
|
.addSynonym("blahblah"))
|
|
|
// Optional: Use machine learning to automatically expand this
|
|
|
.setAutomatedExpansion(false);
|
|
|
```
|
|
|
|
|
|
An entity consists of a entries with optional synonyms. An entry is a 'possibility' and a synonym is another way of wording that 'possibility'.
|
|
|
|
|
|
You have to upload the entity before you can use it. It is recommended to do this in the constructor of the AIModule.
|
|
|
Check out:
|
|
|
https://github.com/Maximvdw/QAPlugin-module-userdata/blob/master/src/main/java/be/maximvdw/qaplugin/modules/NameGetModule.java
|
|
|
for an example.
|
|
|
|
|
|
```java
|
|
|
try {
|
|
|
// Upload the entities
|
|
|
if (QAPluginAPI.findEntityByName(myTiers.getName()) == null) {
|
|
|
if (!QAPluginAPI.uploadEntity(myTiers)) {
|
|
|
warning("Unable to upload entity!");
|
|
|
}
|
|
|
}
|
|
|
} catch (FeatureNotEnabled ex) {
|
|
|
severe("You do not have a developer access token in your QAPlugin config!");
|
|
|
}
|
|
|
```
|
|
|
I am using the `findEntityByName` to check if the entity already exists. If you have an entity that can change depending on config settings, database ,... you do not have to do this check. A future feature will ensure that the entity is only uploaded upon a change.
|
|
|
|
|
|
Notice that a `FeatureNotEnabled` exception will be thrown when the user does not have his developer-access-token configured. This token is required in order for the plugin to upload the entity.
|
|
|
|