本文整理汇总了Java中io.klerch.alexa.tellask.model.AlexaOutputSlot类的典型用法代码示例。如果您正苦于以下问题:Java AlexaOutputSlot类的具体用法?Java AlexaOutputSlot怎么用?Java AlexaOutputSlot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AlexaOutputSlot类属于io.klerch.alexa.tellask.model包,在下文中一共展示了AlexaOutputSlot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveSlotsInUtterance
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
private String resolveSlotsInUtterance(final String utterance) {
final StringBuffer buffer = new StringBuffer();
// extract all the placeholders found in the utterance
final Matcher slotsInUtterance = Pattern.compile("\\{(.*?)\\}").matcher(utterance);
// for any of the placeholders ...
while (slotsInUtterance.find()) {
// ... placeholder-name is the slotName to look after in two places of the output
final String slotName = slotsInUtterance.group(1);
final AlexaOutputSlot outputSlot = output
// prefer directly set output slots
.getSlots().stream()
// which do have the same name as what is found in the utterance
.filter(slot -> slot.getName().equals(slotName))
.findFirst()
// if not directly applied look in provided models for AlexaSlotSave fields
.orElse(getSavedSlot(slotName));
Validate.notNull(outputSlot, "Could not replace placeholder with name {" + slotName + "} because no corresponding slot was set in the output.");
// RJH - FEB 2017 - Matcher.quoteReplacement on slot input to fix bug
// ~ https://github.com/KayLerch/alexa-skills-kit-tellask-java/issues/1
slotsInUtterance.appendReplacement(buffer, Matcher.quoteReplacement(outputSlot.getSsml()));
}
slotsInUtterance.appendTail(buffer);
return "<speak>" + buffer.toString() + "</speak>";
}
示例2: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput alexaInput) throws AlexaRequestHandlerException {
final String name = alexaInput.getSlotValue("name");
if (!alexaInput.hasSlotIsNumber("credits")) {
throw new AlexaRequestHandlerException("Credits is no number.", alexaInput);
}
final String credits = alexaInput.getSlotValue("credits");
final AlexaStateModelSample model = new AlexaStateModelSample();
model.setName(name);
return AlexaOutput.ask("IntentWithOneUtteranceAndOneReprompt")
.putState(model)
.putSlot(new AlexaOutputSlot("credits", credits).formatAs(AlexaOutputFormat.NUMBER))
.withReprompt(true)
.build();
}
示例3: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
final AWSDynamoStateHandler dynamoHandler = new AWSDynamoStateHandler(input.getSessionStateHandler().getSession());
final TreeState treeState = dynamoHandler.readModel(TreeState.class).orElse(new TreeState(input.getLocale(), TreeState.MODE.ON));
// set state on
treeState.setState(TreeState.MODE.ON);
// send state of tree to AWS IoT thing shadow
sendIotHook(input, treeState);
return AlexaOutput.ask("SayWelcome")
.putState(treeState.withHandler(dynamoHandler))
.putSlot(new AlexaOutputSlot("mp3", SkillConfig.getMp3IntroUrl()).formatAs(AlexaOutputFormat.AUDIO))
.withReprompt(true)
.build();
}
示例4: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
final AWSDynamoStateHandler dynamoHandler = new AWSDynamoStateHandler(input.getSessionStateHandler().getSession());
final TreeState treeState = dynamoHandler.readModel(TreeState.class).orElse(new TreeState(input.getLocale(), TreeState.MODE.ON));
// set state on
treeState.setState(TreeState.MODE.ON);
// send state of tree to AWS IoT thing shadow
sendIotHook(input, treeState);
return AlexaOutput.tell("SayTreeOn")
.putState(treeState.withHandler(dynamoHandler))
.putSlot(new AlexaOutputSlot("mp3", SkillConfig.getMp3IntroUrl()).formatAs(AlexaOutputFormat.AUDIO))
.build();
}
示例5: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
final AWSDynamoStateHandler dynamoHandler = new AWSDynamoStateHandler(input.getSessionStateHandler().getSession());
// get last set color in order to reset it once the show is done
final TreeState treeState = dynamoHandler.readModel(TreeState.class).orElse(new TreeState(input.getLocale(), TreeState.MODE.ON));
// set state show
treeState.setState(TreeState.MODE.SHOW);
// send state of tree to AWS IoT thing shadow
sendIotHook(input, treeState);
return AlexaOutput.tell("SayXmasShow")
.putState(treeState.withHandler(dynamoHandler))
.putSlot(new AlexaOutputSlot("mp3", SkillConfig.getMp3ShowUrl()).formatAs(AlexaOutputFormat.AUDIO))
.build();
}
示例6: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
return AlexaOutput.ask("SayWelcome")
.putSlot(new AlexaOutputSlot("hi-mp3", SkillConfig.getMp3HiFileUrl()).formatAs(AlexaOutputFormat.AUDIO))
.withReprompt(true)
.build();
}
示例7: getSavedSlot
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
private AlexaOutputSlot getSavedSlot(String slotName) {
return output.getModels()
.stream()
// for those having that AlexaSlotSave field
.filter(model -> model.hasOutputSlot(slotName))
// create a AlexaOutputSlot from attributes in annotation + the field value itself
.map(model -> model.getOutputSlot(slotName).orElse(null))
.findFirst().orElse(null);
}
示例8: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
// get state handlers for session and dynamoDB of States SDK
final AlexaStateHandler sessionHandler = input.getSessionStateHandler();
final AlexaStateHandler dynamoHandler = new AWSDynamoStateHandler(sessionHandler.getSession());
// try get calculation from session first, if not there read or create in dynamo
// cause we permanently save the precision a user can set
final Calculation calc = sessionHandler.readModel(Calculation.class)
.orElse(dynamoHandler.readModel(Calculation.class)
.orElse(dynamoHandler.createModel(Calculation.class)));
// factor from slot (already ensured is a number in verfiy
final Integer a = Integer.valueOf(input.getSlotValue("a"));
// former result will be the other factor
final double lastResult = calc.getResult();
// multiply number with former result
calc.multiply(a);
final SimpleCard formulaCard = new SimpleCard();
formulaCard.setContent(lastResult + " x " + a + " = " + calc.getResult());
// ensure model is written back to session only (in case it was read out from dynamo)
// we'd like to avoid unnecessary roundtrips to dynamo at this point cause we'd only
// change the result which is not saved permanently
calc.setHandler(sessionHandler);
return AlexaOutput.ask("SayMultiplyResult")
.withCard(formulaCard)
.putSlot(new AlexaOutputSlot("a", lastResult).formatAs(AlexaOutputFormat.NUMBER))
.putSlot(new AlexaOutputSlot("b", a).formatAs(AlexaOutputFormat.NUMBER))
.putState(calc)
.withReprompt(true)
.build();
}
示例9: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
// get state handlers for session and dynamoDB of States SDK
final AlexaStateHandler sessionHandler = input.getSessionStateHandler();
final AlexaStateHandler dynamoHandler = new AWSDynamoStateHandler(sessionHandler.getSession());
// try get calculation from session first, if not there read or create in dynamo
// cause we permanently save the precision a user can set
final Calculation calc = sessionHandler.readModel(Calculation.class)
.orElse(dynamoHandler.readModel(Calculation.class)
.orElse(dynamoHandler.createModel(Calculation.class)));
// factor from slot (already ensured is a number in verfiy
final Integer a = Integer.valueOf(input.getSlotValue("a"));
// factor from slot (already ensured is a number in verfiy
final Integer b = Integer.valueOf(input.getSlotValue("b"));
calc.multiply(a, b);
final SimpleCard formulaCard = new SimpleCard();
formulaCard.setContent(a + " x " + b + " = " + calc.getResult());
// ensure model is written back to session only (in case it was read out from dynamo)
// we'd like to avoid unnecessary roundtrips to dynamo at this point cause we'd only
// change the result which is not saved permanently
calc.setHandler(sessionHandler);
return AlexaOutput.ask("SayMultiplyResult")
.withCard(formulaCard)
.putSlot(new AlexaOutputSlot("a", a).formatAs(AlexaOutputFormat.NUMBER))
.putSlot(new AlexaOutputSlot("b", b).formatAs(AlexaOutputFormat.NUMBER))
.putState(calc)
.withReprompt(true)
.build();
}
示例10: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
// get state handlers for session and dynamoDB of States SDK
final AlexaStateHandler sessionHandler = input.getSessionStateHandler();
final AlexaStateHandler dynamoHandler = new AWSDynamoStateHandler(sessionHandler.getSession());
// try get calculation from session first, if not there read or create in dynamo
// cause we permanently save the precision a user can set
final Calculation calc = sessionHandler.readModel(Calculation.class)
.orElse(dynamoHandler.readModel(Calculation.class)
.orElse(dynamoHandler.createModel(Calculation.class)));
// number from slot (already ensured is a number in verfiy
final Integer a = Integer.valueOf(input.getSlotValue("a"));
// number from slot (already ensured is a number in verfiy
final Integer b = Integer.valueOf(input.getSlotValue("b"));
calc.subtract(a, b);
final SimpleCard formulaCard = new SimpleCard();
formulaCard.setContent(a + " - " + b + " = " + calc.getResult());
// ensure model is written back to session only (in case it was read out from dynamo)
// we'd like to avoid unnecessary roundtrips to dynamo at this point cause we'd only
// change the result which is not saved permanently
calc.setHandler(sessionHandler);
return AlexaOutput.ask("SaySubtractResult")
.withCard(formulaCard)
.putSlot(new AlexaOutputSlot("a", a).formatAs(AlexaOutputFormat.NUMBER))
.putSlot(new AlexaOutputSlot("b", b).formatAs(AlexaOutputFormat.NUMBER))
.putState(calc)
.withReprompt(true)
.build();
}
示例11: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
// get state handlers for session and dynamoDB of States SDK
final AlexaStateHandler sessionHandler = input.getSessionStateHandler();
final AlexaStateHandler dynamoHandler = new AWSDynamoStateHandler(sessionHandler.getSession());
// try get calculation from session first, if not there read or create in dynamo
// cause we permanently save the precision a user can set
final Calculation calc = sessionHandler.readModel(Calculation.class)
.orElse(dynamoHandler.readModel(Calculation.class)
.orElse(dynamoHandler.createModel(Calculation.class)));
// number from slot (already ensured is a number in verfiy
final Integer a = Integer.valueOf(input.getSlotValue("a"));
// former result will be the number to subtract from
final double lastResult = calc.getResult();
// subtract number from result
calc.subtract(a);
final SimpleCard formulaCard = new SimpleCard();
formulaCard.setContent(lastResult + " - " + a + " = " + calc.getResult());
// ensure model is written back to session only (in case it was read out from dynamo)
// we'd like to avoid unnecessary roundtrips to dynamo at this point cause we'd only
// change the result which is not saved permanently
calc.setHandler(sessionHandler);
return AlexaOutput.ask("SaySubtractResult")
.withCard(formulaCard)
.putSlot(new AlexaOutputSlot("a", lastResult).formatAs(AlexaOutputFormat.NUMBER))
.putSlot(new AlexaOutputSlot("b", a).formatAs(AlexaOutputFormat.NUMBER))
.putState(calc)
.withReprompt(true)
.build();
}
示例12: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
// get state handlers for session and dynamoDB of States SDK
final AlexaStateHandler sessionHandler = input.getSessionStateHandler();
final AlexaStateHandler dynamoHandler = new AWSDynamoStateHandler(sessionHandler.getSession());
// try get calculation from session first, if not there read or create in dynamo
// cause we permanently save the precision a user can set
final Calculation calc = sessionHandler.readModel(Calculation.class)
.orElse(dynamoHandler.readModel(Calculation.class)
.orElse(dynamoHandler.createModel(Calculation.class)));
// number from slot (already ensured is a number in verfiy
final Integer a = Integer.valueOf(input.getSlotValue("a"));
// number from slot (already ensured is a number in verfiy
final Integer b = Integer.valueOf(input.getSlotValue("b"));
if (b == 0) {
throw new AlexaRequestHandlerException("Division by 0 not allowed.", input, "SaySorryOnDivideBy0");
}
calc.divide(a, b);
final SimpleCard formulaCard = new SimpleCard();
formulaCard.setContent(a + " / " + b + " = " + calc.getResult());
// ensure model is written back to session only (in case it was read out from dynamo)
// we'd like to avoid unnecessary roundtrips to dynamo at this point cause we'd only
// change the result which is not saved permanently
calc.setHandler(sessionHandler);
return AlexaOutput.ask("SayDivideResult")
.withCard(formulaCard)
.putSlot(new AlexaOutputSlot("a", a).formatAs(AlexaOutputFormat.NUMBER))
.putSlot(new AlexaOutputSlot("b", b).formatAs(AlexaOutputFormat.NUMBER))
.putState(calc)
.withReprompt(true)
.build();
}
示例13: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
// get state handlers for session and dynamoDB of States SDK
final AlexaStateHandler sessionHandler = input.getSessionStateHandler();
final AlexaStateHandler dynamoHandler = new AWSDynamoStateHandler(sessionHandler.getSession());
// try get calculation from session first, if not there read or create in dynamo
// cause we permanently save the precision a user can set
final Calculation calc = sessionHandler.readModel(Calculation.class)
.orElse(dynamoHandler.readModel(Calculation.class)
.orElse(dynamoHandler.createModel(Calculation.class)));
// number from slot (already ensured is a number in verfiy
final Integer a = Integer.valueOf(input.getSlotValue("a"));
if (a == 0) {
throw new AlexaRequestHandlerException("Division by 0 not allowed.", input, "SaySorryOnDivideBy0");
}
// former result will be the other addend
final double lastResult = calc.getResult();
// divide result by number
calc.divide(a);
final SimpleCard formulaCard = new SimpleCard();
formulaCard.setContent(lastResult + " / " + a + " = " + calc.getResult());
// ensure model is written back to session only (in case it was read out from dynamo)
// we'd like to avoid unnecessary roundtrips to dynamo at this point cause we'd only
// change the result which is not saved permanently
calc.setHandler(sessionHandler);
return AlexaOutput.ask("SayDivideResult")
.putSlot(new AlexaOutputSlot("a", lastResult).formatAs(AlexaOutputFormat.NUMBER))
.putSlot(new AlexaOutputSlot("b", a).formatAs(AlexaOutputFormat.NUMBER))
.putState(calc)
.withReprompt(true)
.build();
}
示例14: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
// get state handlers for session and dynamoDB of States SDK
final AlexaStateHandler sessionHandler = input.getSessionStateHandler();
final AlexaStateHandler dynamoHandler = new AWSDynamoStateHandler(sessionHandler.getSession());
// try get calculation from session first, if not there read or create in dynamo
// cause we permanently save the precision a user can set
final Calculation calc = sessionHandler.readModel(Calculation.class)
.orElse(dynamoHandler.readModel(Calculation.class)
.orElse(dynamoHandler.createModel(Calculation.class)));
// addend from slot (already ensured is a number in verfiy
final Integer a = Integer.valueOf(input.getSlotValue("a"));
// get or create calculation from session object
// former result will be the other addend
final double lastResult = calc.getResult();
// add number to result
calc.add(a);
final SimpleCard formulaCard = new SimpleCard();
formulaCard.setContent(lastResult + " + " + a + " = " + calc.getResult());
// ensure model is written back to session only (in case it was read out from dynamo)
// we'd like to avoid unnecessary roundtrips to dynamo at this point cause we'd only
// change the result which is not saved permanently
calc.setHandler(sessionHandler);
return AlexaOutput.ask("SayAddResult")
.withCard(formulaCard)
.putSlot(new AlexaOutputSlot("a", lastResult).formatAs(AlexaOutputFormat.NUMBER))
.putSlot(new AlexaOutputSlot("b", a).formatAs(AlexaOutputFormat.NUMBER))
.putState(calc)
.withReprompt(true)
.build();
}
示例15: handleRequest
import io.klerch.alexa.tellask.model.AlexaOutputSlot; //导入依赖的package包/类
@Override
public AlexaOutput handleRequest(final AlexaInput input) throws AlexaRequestHandlerException, AlexaStateException {
// get state handlers for session and dynamoDB of States SDK
final AlexaStateHandler sessionHandler = input.getSessionStateHandler();
final AlexaStateHandler dynamoHandler = new AWSDynamoStateHandler(sessionHandler.getSession());
// try get calculation from session first, if not there read or create in dynamo
// cause we permanently save the precision a user can set
final Calculation calc = sessionHandler.readModel(Calculation.class)
.orElse(dynamoHandler.readModel(Calculation.class)
.orElse(dynamoHandler.createModel(Calculation.class)));
// addend from slot (already ensured is a number in verfiy
final Integer a = Integer.valueOf(input.getSlotValue("a"));
// addend from slot (already ensured is a number in verfiy
final Integer b = Integer.valueOf(input.getSlotValue("b"));
calc.add(a, b);
final SimpleCard formulaCard = new SimpleCard();
formulaCard.setContent(a + " + " + b + " = " + calc.getResult());
// ensure model is written back to session only (in case it was read out from dynamo)
// we'd like to avoid unnecessary roundtrips to dynamo at this point cause we'd only
// change the result which is not saved permanently
calc.setHandler(sessionHandler);
return AlexaOutput.ask("SayAddResult")
.withCard(formulaCard)
.putSlot(new AlexaOutputSlot("a", a).formatAs(AlexaOutputFormat.NUMBER))
.putSlot(new AlexaOutputSlot("b", b).formatAs(AlexaOutputFormat.NUMBER))
.putState(calc)
.withReprompt(true)
.build();
}