当前位置: 首页>>代码示例>>Java>>正文


Java Session.removeAttribute方法代码示例

本文整理汇总了Java中com.amazon.speech.speechlet.Session.removeAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Session.removeAttribute方法的具体用法?Java Session.removeAttribute怎么用?Java Session.removeAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazon.speech.speechlet.Session的用法示例。


在下文中一共展示了Session.removeAttribute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleConfirmed

import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
private SpeechletResponse handleConfirmed(IntentRequest request, Session session)
    throws CalendarWriteException {
  final String dateFormat = session.getAttribute(SESSION_DATE_FORMAT).toString();
  final DateTimeFormatter parser = DateTimeFormat.forPattern(dateFormat);
  final String title = collectSummary(request);
  final String calendar = session.getAttribute(SESSION_CALENDAR) != null ? session.getAttribute(SESSION_CALENDAR).toString() : null;
  final String from = session.getAttribute(SESSION_FROM).toString();
  final String to = session.getAttribute(SESSION_TO).toString();

  calendarService.createEvent(calendar, title,
      parser.parseDateTime(from),
      parser.parseDateTime(to));

  SimpleCard card = new SimpleCard();
  card.setTitle(messageService.de("event.new.card.title"));
  card.setContent(messageService.de("event.new.card.content", title, from, to));

  session.removeAttribute(BasicSpeechlet.KEY_DIALOG_TYPE);

  return SpeechletResponse.newTellResponse(
      speechService.speechNewEventSaved(request.getLocale()),
      card);
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:24,代码来源:NewEventSpeechlet.java

示例2: handleIntentRequest

import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
@Override
public SpeechletResponse handleIntentRequest(Intent intent, Session session) {
    Object sessionQuestion = session.getAttribute(SkillConfig.SessionAttributeYesNoQuestion);

    SpeechletResponse response = SkillLogic.isAnswerToAnotherEncode(intent, session) ?
                    SkillResponses.getEncodeAskResponse(intent, session) :
                SkillLogic.isAnswerToAnotherSpell(intent, session) ?
                        SkillResponses.getSpellAskResponse(intent, session) :
                    SkillLogic.isAnswerToAnotherExercise(intent, session) ?
                            SkillResponses.getExerciseAskResponse(intent, session) :
                        SkillLogic.isAnswerToAnotherTry(intent, session) ?
                                SkillResponses.getExerciseRepeatResponse(intent, session) :
                                    SkillLogic.hasExercisePending(intent, session) ?
                                        SkillResponses.getHelpDuringExercise(intent, session) :
                                            SkillResponses.getHelpAboutAll(intent, session);

    // reset session attribute if unchanged
    if (sessionQuestion != null && sessionQuestion.toString().equals(session.getAttribute(SkillConfig.SessionAttributeYesNoQuestion)))
        session.removeAttribute(SkillConfig.SessionAttributeYesNoQuestion);
    return response;
}
 
开发者ID:KayLerch,项目名称:alexa-morser-coder-skill,代码行数:22,代码来源:YesIntentHandler.java

示例3: 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;
}
 
开发者ID:KayLerch,项目名称:alexa-morser-coder-skill,代码行数:31,代码来源:SkillResponses.java

示例4: getExerciseCancelResponse

import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
 * This one handles a cancel request in an ongoing exercise
 * @param intent the intent provided by the user
 * @param session the current session with exercise data
 * @return the corresponding speechlet response to the cancellation request
 */
public static SpeechletResponse getExerciseCancelResponse(Intent intent, Session session) {
    // read out the word (if any) which was given as a morse code to the user
    String sessionWord = session.getAttributes().containsKey(SkillConfig.SessionAttributeExercisedWord) ? session.getAttribute(SkillConfig.SessionAttributeExercisedWord).toString() : null;
    String strContent = "";
    if (sessionWord != null && !sessionWord.isEmpty()) {
        strContent += ResponsePhrases.getCorrectAnswerIs() + "<p>" + sessionWord + "</p>";
    }
    strContent += " <p>" + ResponsePhrases.getWantAnotherCode() + "</p>";
    SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
    outputSpeech.setSsml("<speak>" + strContent + "</speak>");
    SpeechletResponse response = SpeechletResponse.newTellResponse(outputSpeech);
    response.setShouldEndSession(false);

    session.removeAttribute(SkillConfig.SessionAttributeExercisedWord);
    session.setAttribute(SkillConfig.SessionAttributeYesNoQuestion, SkillConfig.YesNoQuestions.WantAnotherExercise);
    return response;
}
 
开发者ID:KayLerch,项目名称:alexa-morser-coder-skill,代码行数:24,代码来源:SkillResponses.java

示例5: handleDrWhoIntent

import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
private SpeechletResponse handleDrWhoIntent(IntentRequest intentReq, Session session) {
	SpeechletResponse response = null;
	//check state
	if(session.getAttribute(SESSION_KNOCK_STATE) != null 
			&& STATE_WAITING_DR_WHO.compareTo((Integer)session.getAttribute(SESSION_KNOCK_STATE)) == 0) {			
		response = newTellResponse(" Exactly. How did you know?", false);
		//Clear final state
		session.removeAttribute(SESSION_KNOCK_STATE);
	}
	else {
		response = newTellResponse("You have to say knock knock first.", false);
	}
	return response;	
}
 
开发者ID:jneong,项目名称:CS370_Echo_Demo,代码行数:15,代码来源:KnockKnockConversation.java

示例6: handleIntentRequest

import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
@Override
public SpeechletResponse handleIntentRequest(Intent intent, Session session) {
    // keep in mind what question was denied
    Object sessionQuestion = session.getAttribute(SkillConfig.SessionAttributeYesNoQuestion);

    // "have another try?" on the same morse code was denied
    SpeechletResponse response = SkillLogic.isAnswerToAnotherTry(intent, session) ?
            // so finish the current exercise and play back the correct answer
            SkillResponses.getExerciseFinalFalseResponse(intent, session) :
            // "have another exercise?" with a new code was denied
            SkillLogic.isAnswerToAnotherExercise(intent, session) ?
                    // this means leaving the app and say good bye
                    SkillResponses.getGoodBye(intent, session) :
                    // "have another encoding?" was denied
                    SkillLogic.isAnswerToAnotherEncode(intent, session) ?
                            // this means leaving the app and say good bye
                            SkillResponses.getGoodBye(intent, session) :
                            // "have another code spelled out?" was denied
                            SkillLogic.isAnswerToAnotherSpell(intent, session) ?
                                    // this means leaving the app and say good bye
                                    SkillResponses.getGoodBye(intent, session) :
                                    // none of the above questions was answered, so No-intent is not expected in current context
                                    // before giving the user a help check if there is an ongoing exercise
                                    SkillLogic.hasExercisePending(intent, session) ?
                                            // if so, play back help information dedicated to the exercise
                                            SkillResponses.getHelpDuringExercise(intent, session) :
                                            // otherwise: give general hints
                                            SkillResponses.getHelpAboutAll(intent, session);

    // reset session attribute if unchanged
    if (sessionQuestion != null && sessionQuestion.toString().equals(session.getAttribute(SkillConfig.SessionAttributeYesNoQuestion)))
        session.removeAttribute(SkillConfig.SessionAttributeYesNoQuestion);
    return response;
}
 
开发者ID:KayLerch,项目名称:alexa-morser-coder-skill,代码行数:35,代码来源:NoIntentHandler.java

示例7: getExerciseFinalFalseResponse

import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
/**
 * This one handles the final decision of user to not have any more attempts on an ongoing exercise
 * Instead (because he gave up be denying another guess) the correct answer is given by Alexa in the
 * resulting response of this method
 * @param intent intent given by the user
 * @param session current session with some data of the exercise
 * @return the corresponding speechlet response to the surrender
 */
public static SpeechletResponse getExerciseFinalFalseResponse(Intent intent, Session session) {
    // read out the word (if any) which was given as a morse code to the user
    String sessionWord = session.getAttributes().containsKey(SkillConfig.SessionAttributeExercisedWord) ? session.getAttribute(SkillConfig.SessionAttributeExercisedWord).toString() : null;

    SkillLogic.decreaseScore(session, 1);

    String strSpelled = sessionWord.length() <= SkillConfig.ExerciseWordMaxLengthForSpelling ?
            SsmlUtils.getBreakMs(300) + " spelled " + MorseUtils.getSsmlSpellout(sessionWord) : "";

    String strContent = ResponsePhrases.getCorrectAnswerIs() + SsmlUtils.getBreakMs(300) +
            sessionWord + strSpelled +
            "<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);

    // decrease the length of exercise words
    SkillLogic.decreaseExercisesLevel(session);

    session.removeAttribute(SkillConfig.SessionAttributeExercisedWord);
    session.setAttribute(SkillConfig.SessionAttributeYesNoQuestion, SkillConfig.YesNoQuestions.WantAnotherExercise);
    return response;
}
 
开发者ID:KayLerch,项目名称:alexa-morser-coder-skill,代码行数:37,代码来源:SkillResponses.java

示例8: handleDenied

import com.amazon.speech.speechlet.Session; //导入方法依赖的package包/类
private SpeechletResponse handleDenied(IntentRequest request, Session session) {
  session.removeAttribute(BasicSpeechlet.KEY_DIALOG_TYPE);

  return SpeechletResponse.newTellResponse(speechService.speechCancelNewEvent(request.getLocale()));
}
 
开发者ID:rainu,项目名称:alexa-skill,代码行数:6,代码来源:NewEventSpeechlet.java


注:本文中的com.amazon.speech.speechlet.Session.removeAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。