This repository has been archived by the owner on Mar 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Example for a dialog xml with usage in Java
Legion2 edited this page Nov 25, 2018
·
9 revisions
On this page is a full example of dialog with all necessary files. This example base on the Spotify plugin, but some methods are deleted or simplified for better understanding.
File Name: SpotifySpeech.aim.xml
Location: resource folder of the plugin
<?xml version="1.0" encoding="utf-8"?>
<AmyInteractionModel>
<Intent
ref="io.github.amyassist.amy.plugin.spotify.SpotifySpeech.getCurrentSong">
<gram> get current [playing] (song|track) </gram>
</Intent>
<Intent
ref="io.github.amyassist.amy.plugin.spotify.SpotifySpeech.getPlaylists">
<gram> get [{number}] [{type}] playlists </gram>
<EntityTemplates>
<EntityTemplate id="type" required="true">
<gram>(own|featured)</gram>
</EntityTemplate>
<EntityTemplate id="number" required="false">
<gram>{amyinteger}</gram>
</EntityTemplate>
</EntityTemplates>
<Prompt entityTemplateId="type">
<text> what type of playlists would you search? </text>
<gram>{type} playlist</gram>
</Prompt>
</Intent>
<Intent
ref="io.github.amyassist.amy.plugin.spotify.SpotifySpeech.control">
<gram>[go] {type} [(a track|the music)]</gram>
<EntityTemplates>
<EntityTemplate id="type" required="true">
<gram>(back|skip|pause|pass|resume|stop)</gram>
</EntityTemplate>
</EntityTemplates>
</Intent>
<Intent
ref="io.github.amyassist.amy.plugin.spotify.SpotifySpeech.searchASong">
<gram>play this song {name}</gram>
<EntityTemplates>
<EntityTemplate id="name" required="true">
<gram>*</gram>
</EntityTemplate>
</EntityTemplates>
</Intent>
<Intent
ref="io.github.amyassist.amy.plugin.spotify.SpotifySpeech.volumePercent">
<gram> (set [music] volume [to] |spotify) {volume} percent
</gram>
<EntityTemplates>
<EntityTemplate id="volume" required="true">
<gram>{amyinteger}</gram>
</EntityTemplate>
</EntityTemplates>
</Intent>
<Intent
ref="io.github.amyassist.amy.plugin.spotify.SpotifySpeech.setDeviceName">
<gram> set (spotify|music) device by name</gram>
<EntityTemplates>
<EntityTemplate id="devicename" required="true">
<gram>name</gram>
</EntityTemplate>
</EntityTemplates>
<Prompt entityTemplateId="devicename">
<text>To which device should i switch? </text>
<gram>[to device] {devicename} </gram>
</Prompt>
</Intent>
</AmyInteractionModel>
File name: SpotifySpeech.java
Location: Source file directory of the plugin
@SpeechCommand
public class SpotifySpeech {
@Reference
private PlayerLogic playerLogic;
@Intent
public String getCurrentSong(Map<String, EntityData> entites) {
...
return currentSong;
}
@Intent
public String getPlaylists(Map<String, EntityData> entites) {
StringBuilder builder = new StringBuilder();
int amount;
if (entites.get("number") != null) {
amount = entites.get("number").getNumber();
}
if (entites.get("type").getString() != null) {
switch (entites.get("type").getString()) {
case "featured":
...
case "own":
...
default:
...
}
}
return stringWithPlaylistData;
}
@Intent
public String control(Map<String, EntityData> entites) {
switch (entites.get("type").getString()) {
case "back":
this.playerLogic.back();
break;
case "skip":
this.playerLogic.skip();
break;
case "pause":
this.playerLogic.pause();
break;
case "resume":
this.playerLogic.resume();
break;
default:
...
}
return "OK";
}
@Intent
public String searchASong(Map<String, EntityData> entites) {
playTrack(entities.get("name"));
}
@Intent
public String volumePercent(Map<String, EntityData> entites) {
int volume = this.playerLogic.setVolume(entites.get("volume").getNumber());
return (volume != -1) ? "Volume: " + volume + " percent" : "Wrong volume range";
}
@EntityProvider("devicename")
public List<String> getDeviceNames() {
List<String> deviceNames = getDeviceNames();
return deviceNames;
}
@Intent
public String setDeviceName(Map<String, EntityData> entites) {
for (DeviceEntity device : this.deviceLogic.getDevices()) {
if (device.getName().equalsIgnoreCase(entites.get("devicename").getString())) {
this.deviceLogic.setDevice(device.getID());
return device.getName();
}
}
return "Device not found";
}
}
File name: io.github.amyassist.amy-plugin-spotify.natlangMeta
Location:resources/META-INF
.aims:
SpotifySpeech.aim.xml