本文整理汇总了Java中com.amazon.speech.speechlet.Session.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Session.setAttribute方法的具体用法?Java Session.setAttribute怎么用?Java Session.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazon.speech.speechlet.Session
的用法示例。
在下文中一共展示了Session.setAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleProgress
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
private SpeechletResponse handleProgress(IntentRequest request, Session session) {
checkCalendarName(request, session);
if(allSlotsFilled(request)) {
final String title = collectSummary(request);
final DateTime from = DateTime.parse(
sv(request, SLOT_DATE_FROM) + "T" + sv(request, SLOT_TIME_FROM));
final DateTime to = getTimeTo(request, from);
final String dateFormat = messageService.de("event.new.card.content.time.format");
session.setAttribute(SESSION_DATE_FORMAT, dateFormat);
session.setAttribute(SESSION_FROM, from.toString(dateFormat));
session.setAttribute(SESSION_TO, to.toString(dateFormat));
final OutputSpeech speech = speechService.confirmNewEvent(title, from, to, request.getLocale());
return SpeechletResponse.newDialogConfirmIntentResponse(speech);
}
//normally we want to delegate because we have defined the dialog into the model on alexa
if( request.getDialogState() != DialogState.COMPLETED) {
Intent updatedIntent = updateIntent(request.getIntent());
return SpeechletResponse.newDialogDelegateResponse(updatedIntent);
}
return SpeechletResponse.newTellResponse(speechService.speechCancelNewEvent(request.getLocale()));
}
示例2: handleDialogAction
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
@OnIntent("NewEvent")
public SpeechletResponse handleDialogAction(final IntentRequest request, final Session session) throws CalendarWriteException {
session.setAttribute(BasicSpeechlet.KEY_DIALOG_TYPE, BasicSpeechlet.DIALOG_TYPE_NEW_EVENT);
final SpeechletResponse response;
try {
switch (request.getIntent().getConfirmationStatus()) {
default:
case NONE: response = handleProgress(request, session);
break;
case CONFIRMED: response = handleConfirmed(request, session);
break;
case DENIED: response = handleDenied(request, session);
break;
}
} catch (CalendarWriteException e) {
return SpeechletResponse.newTellResponse(speechService.speechError(e));
}
response.setShouldEndSession(false);
return response;
}
示例3: getSpellResponse
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* This one handles a spell out request by the user.
* @param intent the intent given (should include the word to spell out by Alexa)
* @param session the current session
* @return the corresponding speechlet response to the spell out request
*/
public static SpeechletResponse getSpellResponse(Intent intent, Session session) {
String SlotName = SkillConfig.getAlexaSlotName();
String text = (intent.getSlots().containsKey(SlotName) ? intent.getSlot(SlotName).getValue() : null);
String strContent = MorseUtils.getSsmlSpellout(text) + "<p>" + text + "</p><p>Do you want me to spell another name?</p>";
SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
outputSpeech.setSsml("<speak>" + strContent + "</speak>");
Card card = getExerciseCard(text.trim(), false);
SpeechletResponse response = SpeechletResponse.newTellResponse(outputSpeech, card);
response.setShouldEndSession(false);
session.setAttribute(SkillConfig.SessionAttributeYesNoQuestion, SkillConfig.YesNoQuestions.WantAnotherSpell);
return response;
}
示例4: getExerciseAskResponse
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* This one handles the user's request for a new exercise word
* @param intent the intent given by the user
* @param session current session with some exercise data
* @return corresponding speechlet response to an exercise request (including the playback of morse code of a randomly picked word)
*/
public static SpeechletResponse getExerciseAskResponse(Intent intent, Session session) {
String word = getRandomExerciseWord(SkillLogic.getExerciseLevel(session));
// keep this word in mind in order to evaluate it against the users answer
session.setAttribute(SkillConfig.SessionAttributeExercisedWord, word);
// increment exercise counter
SkillLogic.incrementExercisesTotal(session);
OutputSpeech outputSpeech = SkillResponses.getExerciseAskSpeech(word);
Reprompt reprompt = SkillResponses.getExerciseAskReprompt(word);
Card card = SkillResponses.getExerciseCard(word, true);
SpeechletResponse response = SpeechletResponse.newTellResponse(outputSpeech, card);
response.setShouldEndSession(false);
response.setReprompt(reprompt);
return response;
}
示例5: getExerciseCorrectResponse
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* This one reacts on a user given a correct answer in an exercise
* @param intent the intent given by the user
* @param session the current session with some exercise data
* @return the corresponding speechlet response to the given answer
*/
public static SpeechletResponse getExerciseCorrectResponse(Intent intent, Session session) {
String sessionWord = session.getAttributes().containsKey(SkillConfig.SessionAttributeExercisedWord) ? session.getAttribute(SkillConfig.SessionAttributeExercisedWord).toString() : null;
SkillLogic.incrementExercisesCorrect(session);
SkillLogic.getExercisesRetries(session);
// add score depending on length of the word
SkillLogic.increaseScore(session, sessionWord.length());
// increase length of exercise word
SkillLogic.increaseExercisesLevel(session);
String strContent = ResponsePhrases.getSuperlative() + "! " +
ResponsePhrases.getAnswerCorrect() + "." +
"<p>" + ResponsePhrases.getScoreIs() + SkillLogic.getScore(session) + "</p>" +
"<p>" + ResponsePhrases.getWantAnotherCode() + "</p>";
SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
outputSpeech.setSsml("<speak>" + strContent + "</speak>");
Card card = getExerciseCard(sessionWord, false);
SpeechletResponse response = SpeechletResponse.newTellResponse(outputSpeech, card);
response.setShouldEndSession(false);
session.removeAttribute(SkillConfig.SessionAttributeExercisedWord);
session.setAttribute(SkillConfig.SessionAttributeYesNoQuestion, SkillConfig.YesNoQuestions.WantAnotherExercise);
return response;
}
示例6: onRequest
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
IntentContext<BaseOperation<Namespace, NamespaceList, ?, ?>> ctx = createContext(request.getIntent(), session);
//The namespace as Alexa heard it.
String namespace = ctx.getVariable(Variable.Namespace, null);
if (Utils.isNullOrEmpty(namespace)) {
return newFailureNotice("Sorry, didn't understand which namespace you want me to use.");
}
//The namespace as matched in kubernetes
namespace = IntentContext.selectNamespace(getKubernetesClient(), namespace);
LOGGER.info("Switching to namespace:" + ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace()));
try {
Namespace ns = get(ctx);
if (ns == null) {
return newResponse("No namespaces found.");
} else {
namespace = ns.getMetadata().getName();
session.setAttribute(Namespace.name(), namespace);
return newResponse("Now using namespace " + namespace);
}
} catch (KubernetesClientException e) {
return newFailureNotice(e.getStatus().getMessage());
}
}
示例7: checkCalendarName
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
private String checkCalendarName(IntentRequest request, Session session) {
if(sv(request, SLOT_CALENDAR) == null) {
return null;
}
final String givenName = sv(request, SLOT_CALENDAR);
if(givenName == null) {
return null;
}
final String foundName = findCalendarName(givenName);
session.setAttribute(SESSION_CALENDAR, foundName);
return foundName;
}
示例8: getEncodeResponse
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* This one handles an encode request by the user
* @param intent the intent given (should include the word to encode)
* @param session the current session
* @return the corresponding speechlet response to the encoding request
*/
public static SpeechletResponse getEncodeResponse(Intent intent, Session session) {
String SlotName = SkillConfig.getAlexaSlotName();
String text = (intent.getSlots().containsKey(SlotName) ? intent.getSlot(SlotName).getValue() : null);
String strContent = "Morse code of " + text + " is as follows: " + MorseUtils.getSsml(text) + "<p>Do you want me to encode another name?</p>";
SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
outputSpeech.setSsml("<speak>" + strContent + "</speak>");
Card card = getExerciseCard(text.trim(), false);
SpeechletResponse response = SpeechletResponse.newTellResponse(outputSpeech, card);
session.setAttribute(SkillConfig.SessionAttributeYesNoQuestion, SkillConfig.YesNoQuestions.WantAnotherEncode);
response.setShouldEndSession(false);
return response;
}
示例9: help
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
private SpeechletResponse help(Intent intent, Session session) {
session.setAttribute(Constants.ATTR_PREVIOUS_STATE, "NATO");
return responseText("You can ask me New York City subway status like this: " +
"What is the status of seven? " +
"For alphabetical trains, like A, C, E trains, use a word that begins with that letter of the alphabet instead. " +
"For example, for A train, say: What is the status of Alpha? NATO phonetic alphabets are recommended. " +
"Do you want to hear a list of NATO phonetic alphabets?"
, false);
}
示例10: getScore
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* @param session session data
* @return current score based on given answers, processed exercises and reattempts
*/
public static Integer getScore(Session session) {
if (!session.getAttributes().containsKey(SkillConfig.SessionAttributeExerciseScore)) {
session.setAttribute(SkillConfig.SessionAttributeExerciseScore, 0);
return 0;
}
else {
return Integer.valueOf(session.getAttribute(SkillConfig.SessionAttributeExerciseScore).toString());
}
}
示例11: decreaseExercisesLevel
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* Decrease the level by one. The value of the level corresponds to the length of words
* given by Alexa in exercises
* @param session session data
* @return the new value of the level
*/
public static Integer decreaseExercisesLevel(Session session) {
Integer val = getExerciseLevel(session);
if (val > SkillConfig.ExerciseWordMinLength) {
session.setAttribute(SkillConfig.SessionAttributeExerciseLevel, --val);
}
return val;
}
示例12: increaseExercisesLevel
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* Increase the level by one. The value of the level corresponds to the length of words
* given by Alexa in exercises
* @param session session data
* @return the new value of the level after incrementing it
*/
public static Integer increaseExercisesLevel(Session session) {
Integer val = getExerciseLevel(session);
if (val < SkillConfig.ExerciseWordMaxLength) {
session.setAttribute(SkillConfig.SessionAttributeExerciseLevel, ++val);
}
return val;
}
示例13: getExerciseLevel
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* gets the current exercise level. The value of the level corresponds to the length of words
* given by Alexa in exercises
* @param session session data
* @return the current value of the level
*/
public static Integer getExerciseLevel(Session session) {
if (!session.getAttributes().containsKey(SkillConfig.SessionAttributeExerciseLevel)) {
session.setAttribute(SkillConfig.SessionAttributeExerciseLevel, SkillConfig.ExerciseLevelDefault);
return SkillConfig.ExerciseLevelDefault;
}
else {
return Integer.valueOf(session.getAttribute(SkillConfig.SessionAttributeExerciseLevel).toString());
}
}
示例14: getExercisesTotal
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* Returns the total of exercises processed in the current session
* @param session session data (should contain the value to return, otherwise set to 0)
* @return the current total of processed exercises
*/
public static Integer getExercisesTotal(Session session) {
if (!session.getAttributes().containsKey(SkillConfig.SessionAttributeExercisesTotal)) {
session.setAttribute(SkillConfig.SessionAttributeExercisesTotal, 0);
return 0;
}
else {
return Integer.valueOf(session.getAttribute(SkillConfig.SessionAttributeExercisesTotal).toString());
}
}
示例15: getExercisesCorrect
import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
* Returns the number of correct answers given by the user in the current session
* @param session session data (should contain the value to return, otherwise set to 0)
* @return the current number of correct answers
*/
public static Integer getExercisesCorrect(Session session) {
if (!session.getAttributes().containsKey(SkillConfig.SessionAttributeExercisesCorrect)) {
session.setAttribute(SkillConfig.SessionAttributeExercisesCorrect, 0);
return 0;
}
else {
return Integer.valueOf(session.getAttribute(SkillConfig.SessionAttributeExercisesCorrect).toString());
}
}