-
Notifications
You must be signed in to change notification settings - Fork 1
How to create a plugin
A plugin is just a maven project compiled as a "fat jar", that means all external dependencies of the plugin must be contained in that jar.
The basic pom of a plugin looks like this:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>amy-plugin-example</artifactId>
<name>insert name here</name>
<description>Description here</description>
<parent>
<groupId>de.unistuttgart.iaas.amyassist</groupId>
<artifactId>amy-plugin</artifactId>
<version>0.2.0-Snapshot</version>
<relativePath>../pom.xml</relativePath>
</parent>
<!-- Optional blocks like dependencies here -->
</project>
For the plugin to be part of the Amy project, modify the pom.xml in the top level directory of the project.
In the block <modules>
add a line like <module>pathto/plugin</module>
.
The basic structure of the code for a plugin is as follows:
- a service class
- a speech class
optional components:
- a rest class
- (not jet) a console class
Due to restrictions in the plugin loader, currently all classes of a plugin must contain "amy" in their package name.
the service class is not only used internally in your plugin it can be used by other plugins.
its best practice to create a interface of the service.
Take note of the possible Annotations needed for Dependency Injection. Annotations Wiki Article
A complete example can be found here
This class is used by the core to extract the grammars needed to activate your plugin functionality.
The grammars have to be above the corresponding method in the form shown here .
Every method using the @Grammar annotation may be called by the core, thats why they have to be public
and need to return a String
. This String is the corresponding output (via speech or commandline) from Amy.
Example:
@Grammar(timer at # oh #)
public String setAlarm(String[] param){
return "Timer is set at " + param[2] + " " + param[4];
}
Note that String[] param
has to be used. It contains the input received via Speech or Commandline.
In this example param contains {"timer", "at", "13", "oh", "23"}
if the user said something like amy alarm set timer at 13 oh 23
. Where alarm is the keyword of the plugin.