Skip to content

Commit acc86bc

Browse files
authored
Merge pull request #1 from SEPIA-Framework/dev
First release package for SEPIA-Home v2.2.0
2 parents 0127c52 + f955477 commit acc86bc

File tree

8 files changed

+481
-0
lines changed

8 files changed

+481
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# sepia-extensions
22
Extensions (the "E" in SEPIA) are plugins and smart services that enhance SEPIA's capabilities.
3+
4+
## Contribute
5+
Feel free to clone this repository, build your own extension and create a pull request to submit it. We will review your submission and consider adding it to the master branch.

mesh-plugins/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Mesh-Plugins
2+
Mesh-Plugins are extensions for [SEPIA Mesh-Nodes](https://github.com/SEPIA-Framework/sepia-mesh-nodes) that run specific tasks or programs.
3+
Using the Teach-UI included in the [SEPIA cross-platform app](https://github.com/SEPIA-Framework/sepia-html-client-app) you can create your own voice-commands that trigger these plugins.
4+
A popular example is the 'RuntimePlugin' (included by default in a Mesh-Node) that you can use to execute terminal commands, e.g. to run scripts written in other programming languages or simply to shutdown your PC (possibilities are endless) ;-)

mesh-plugins/java/HelloPlugin.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.b07z.sepia.server.mesh.plugins;
2+
3+
import org.json.simple.JSONObject;
4+
5+
import net.b07z.sepia.server.core.tools.JSON;
6+
7+
/**
8+
* The simplest plugin possible. Uses the 'name' field from the request data and returns hello 'name'.
9+
*
10+
* @author Florian Quirin
11+
*/
12+
public class HelloPlugin implements Plugin {
13+
14+
@Override
15+
public PluginResult execute(JSONObject data) {
16+
//Get name and return hello
17+
String name = JSON.getString(data, "name");
18+
PluginResult result = new PluginResult(JSON.make(
19+
"status", "success",
20+
"hello", name
21+
));
22+
return result;
23+
}
24+
25+
}

mesh-plugins/mesh-plugins.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"plugins" : [
3+
{
4+
"name": "HelloPlugin",
5+
"path": "java/HelloPlugin.java",
6+
"version": "0.9.0"
7+
}
8+
]
9+
}

smart-services/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Smart-Services
2+
Smart-Services are the bread and butter of SEPIA. After SEPIA has recognized the user-intent (e.g. how is the weather?) a Smart-Service will manage the dialog to get missing information (e.g. location), fulfill the request (e.g. call a third-party API) and build the result for the SEPIA client (e.g. cards for the app).
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package net.b07z.sepia.sdk.services.uid1007;
2+
3+
import java.util.TreeSet;
4+
5+
import org.json.simple.JSONObject;
6+
7+
import net.b07z.sepia.server.assist.data.Card;
8+
import net.b07z.sepia.server.assist.data.Card.ElementType;
9+
import net.b07z.sepia.server.assist.interpreters.NluResult;
10+
import net.b07z.sepia.server.assist.services.ServiceBuilder;
11+
import net.b07z.sepia.server.assist.services.ServiceInfo;
12+
import net.b07z.sepia.server.assist.services.ServiceInterface;
13+
import net.b07z.sepia.server.assist.services.ServiceResult;
14+
import net.b07z.sepia.server.assist.services.ServiceInfo.Content;
15+
import net.b07z.sepia.server.assist.services.ServiceInfo.Type;
16+
import net.b07z.sepia.server.core.assistant.ACTIONS;
17+
import net.b07z.sepia.server.core.data.Language;
18+
import net.b07z.sepia.server.core.tools.JSON;
19+
import net.b07z.sepia.server.core.tools.Sdk;
20+
21+
/**
22+
* "Hello World" custom service that just returns a "Hello" answer,
23+
* a demo button that links to the SDK and a demo card that links to SEPIA website.
24+
*
25+
* @author Florian Quirin
26+
*
27+
*/
28+
public class HelloWorld implements ServiceInterface{
29+
30+
//Command name
31+
private static final String CMD_NAME = "hello_world"; //Name tag of your service (will be combined with userId to be unique)
32+
//Answers used:
33+
private static final String successAnswer = "chat_hello_0a"; //successful answer
34+
private static final String okAnswer = "default_not_possible_0a"; //service ran properly but can't generate desired result (e.g. a search term was not found)
35+
private static final String failAnswer = "error_0a"; //fallback if service or some part of it crashed
36+
37+
//Define some sentences for testing:
38+
39+
@Override
40+
public TreeSet<String> getSampleSentences(String lang){
41+
TreeSet<String> samples = new TreeSet<>();
42+
//GERMAN
43+
if (lang.equals(Language.DE.toValue())){
44+
samples.add("Hallo Welt!");
45+
46+
//OTHER
47+
}else{
48+
samples.add("Hello world!");
49+
}
50+
return samples;
51+
}
52+
53+
//Basic service setup:
54+
55+
@Override
56+
public ServiceInfo getInfo(String language) {
57+
//Type of service (for descriptions, choose what you think fits best)
58+
ServiceInfo info = new ServiceInfo(Type.plain, Content.data, false);
59+
60+
//Should be available publicly or only for the developer? Set this when you are done with testing and want to release
61+
//info.makePublic();
62+
63+
//Command
64+
info.setIntendedCommand(Sdk.getMyCommandName(this, CMD_NAME));
65+
66+
//Direct-match trigger sentences in different languages:
67+
String DE = Language.DE.toValue();
68+
info.addCustomTriggerSentence("Hallo Welt!", DE)
69+
.addCustomTriggerSentence("Hello world!", DE)
70+
.addCustomTriggerSentence("Teste meinen hallo Welt service.", DE);
71+
String EN = Language.EN.toValue();
72+
info.addCustomTriggerSentence("Hello world!", EN)
73+
.addCustomTriggerSentence("Test my hello world service.", EN);
74+
75+
//Parameters:
76+
//This service has no parameters
77+
78+
//Answers (these are the default answers, you can trigger a custom answer at any point in the module with api.setCustomAnswer(..)):
79+
info.addSuccessAnswer(successAnswer)
80+
.addFailAnswer(failAnswer)
81+
.addOkayAnswer(okAnswer);
82+
83+
return info;
84+
}
85+
86+
@Override
87+
public ServiceResult getResult(NluResult nluResult) {
88+
//initialize result
89+
ServiceBuilder api = new ServiceBuilder(nluResult,
90+
getInfoFreshOrCache(nluResult.input, this.getClass().getCanonicalName()));
91+
92+
//get required parameters
93+
//NONE
94+
//get optional parameters
95+
//NONE
96+
97+
//This service basically cannot fail ... ;-)
98+
99+
//Just for demo purposes we add a button-action with a link to the SDK
100+
api.addAction(ACTIONS.BUTTON_IN_APP_BROWSER);
101+
api.putActionInfo("url", "https://github.com/SEPIA-Framework/sepia-sdk-java");
102+
api.putActionInfo("title", "SDK info");
103+
104+
//... and we also add a demo card
105+
Card card = new Card(Card.TYPE_SINGLE);
106+
JSONObject linkCard = card.addElement(
107+
ElementType.link,
108+
JSON.make("title", "S.E.P.I.A." + ":", "desc", "Hello World!"),
109+
null, null, "",
110+
"https://sepia-framework.github.io/",
111+
"https://sepia-framework.github.io/img/icon.png",
112+
null, null
113+
);
114+
JSON.put(linkCard, "imageBackground", "#000"); //more options like CSS background
115+
api.addCard(card.getJSON());
116+
117+
//all good
118+
api.setStatusSuccess();
119+
120+
//build the API_Result
121+
ServiceResult result = api.buildResult();
122+
return result;
123+
}
124+
125+
}

0 commit comments

Comments
 (0)