Search in sources :

Example 1 with Session

use of com.amazon.speech.speechlet.Session in project amos-ss17-alexa by c-i-ber.

the class BlockCardService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) {
    IntentRequest request = requestEnvelope.getRequest();
    Session session = requestEnvelope.getSession();
    // TODO: Use account later to actually block a card
    Account account = AccountFactory.getInstance().getAccount(number);
    if (request.getIntent().getName().equals("AMAZON.YesIntent")) {
        String cardNumberObj = (String) session.getAttribute("BlockCardService.CardNumber");
        if (cardNumberObj != null) {
            long cardNumber = Long.parseLong(cardNumberObj);
            return getSpeechletResponse("Karte " + cardNumberObj + " wurde gesperrt.", "", false);
        }
        return null;
    } else if (request.getIntent().getName().equals("AMAZON.NoIntent")) {
        session.setAttribute("BlockCardService.CardNumber", null);
        return getSpeechletResponse("Okay, tschüss.", "", false);
    } else {
        String bankCardNumber = request.getIntent().getSlot("BankCardNumber").getValue();
        if (bankCardNumber == null) {
            String speechText = "Wie lautet die Nummber der Karte?";
            String repromptText = "Sagen Sie auch die Nummer der Karte. Zum Beispiel: Sperre Karte 12345.";
            return getSpeechletResponse(speechText, repromptText, false);
        } else {
            session.setAttribute("BlockCardService.CardNumber", bankCardNumber);
            String speechText = "Möchten Sie die Karte " + bankCardNumber + " wirklich sperren?";
            String repromptText = "Bitte bestätigen Sie, indem Sie 'ja' sagen.";
            return getSpeechletResponse(speechText, repromptText, true);
        }
    }
}
Also used : Account(model.banking.account.Account) IntentRequest(com.amazon.speech.speechlet.IntentRequest) Session(com.amazon.speech.speechlet.Session)

Example 2 with Session

use of com.amazon.speech.speechlet.Session in project amos-ss17-alexa by c-i-ber.

the class EditCategoriesService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    Intent intent = requestEnvelope.getRequest().getIntent();
    String intentName = intent.getName();
    LOGGER.info("Intent Name: " + intentName);
    Session session = requestEnvelope.getSession();
    String context = (String) session.getAttribute(DIALOG_CONTEXT);
    switch(intentName) {
        case DELETE_CATEGORY_INTENT:
            return deleteCategory(intent, session);
        case YES_INTENT:
            if (context.equals(DELETE_CATEGORY_INTENT)) {
                return performDeletion(intent, session);
            }
            if (context.equals(ADD_CATEGORY_INTENT)) {
                return addNewCategory(intent, session, true);
            }
            return null;
        case NO_INTENT:
            return getResponse(SERVICE_CARD_TITLE, "OK, verstanden. Dann bis bald.");
        case ADD_CATEGORY_INTENT:
            return addNewCategory(intent, session, false);
        case SHOW_CATEGORIES_INTENT:
            return showAllCategories(intent, session);
    }
    return null;
}
Also used : Intent(com.amazon.speech.slu.Intent) Session(com.amazon.speech.speechlet.Session)

Example 3 with Session

use of com.amazon.speech.speechlet.Session in project amos-ss17-alexa by c-i-ber.

the class ReplacementCardService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    Intent intent = requestEnvelope.getRequest().getIntent();
    String intentName = intent.getName();
    Session session = requestEnvelope.getSession();
    LOGGER.info("Intent Name: " + intentName);
    String context = (String) session.getAttribute(DIALOG_CONTEXT);
    LOGGER.info("Context: " + context);
    if (REPLACEMENT_CARD_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, REPLACEMENT_CARD_INTENT);
        return askForCardNumber(session, false);
    } else if (PLAIN_NUMBER_INTENT.equals(intentName)) {
        return askIfBlockedOrDamaged(intent, session);
    } else if (REPLACEMENT_CARD_REASON_INTENT.equals(intentName)) {
        return askForConfirmation(intent, session);
    } else if (YES_INTENT.equals(intentName)) {
        return orderReplacement(intent, session);
    } else if (NO_INTENT.equals(intentName)) {
        return cancelDialog();
    } else {
        throw new SpeechletException("Unhandled intent: " + intentName);
    }
}
Also used : SpeechletException(com.amazon.speech.speechlet.SpeechletException) Intent(com.amazon.speech.slu.Intent) Session(com.amazon.speech.speechlet.Session)

Example 4 with Session

use of com.amazon.speech.speechlet.Session in project amos-ss17-alexa by c-i-ber.

the class ContactService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    Intent intent = requestEnvelope.getRequest().getIntent();
    String intentName = intent.getName();
    Session session = requestEnvelope.getSession();
    String context = (String) session.getAttribute(DIALOG_CONTEXT);
    if (CONTACT_LIST_INFO_INTENT.equals(intentName)) {
        LOGGER.info(getClass().toString() + " Intent started: " + intentName);
        session.setAttribute(DIALOG_CONTEXT, CONTACT_LIST_INFO_INTENT);
        return readContacts(session, 0, 3);
    } else if (CONTACT_ADD_INTENT.equals(intentName)) {
        session.getAttributes().clear();
        session.setAttribute(DIALOG_CONTEXT, CONTACT_ADD_INTENT);
        return askForNewContactConfirmation(intent, session);
    } else if (CONTACT_DELETE_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, CONTACT_DELETE_INTENT);
        return deleteContact(intent, session, false);
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals(CONTACT_ADD_INTENT)) {
        return createNewContact(session);
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals(CONTACT_DELETE_INTENT)) {
        return deleteContact(intent, session, true);
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals(CONTACT_LIST_INFO_INTENT)) {
        return continueReadingContacts(intent, session);
    } else if (NO_INTENT.equals(intentName)) {
        return getResponse(CONTACTS, "OK, dann nicht. Auf wiedersehen!");
    } else {
        throw new SpeechletException("Unhandled intent: " + intentName);
    }
}
Also used : SpeechletException(com.amazon.speech.speechlet.SpeechletException) Intent(com.amazon.speech.slu.Intent) Session(com.amazon.speech.speechlet.Session)

Example 5 with Session

use of com.amazon.speech.speechlet.Session in project amos-ss17-alexa by c-i-ber.

the class SavingsPlanService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    Intent intent = requestEnvelope.getRequest().getIntent();
    String intentName = intent.getName();
    Session session = requestEnvelope.getSession();
    LOGGER.info("Intent Name: " + intentName);
    String context = (String) session.getAttribute(DIALOG_CONTEXT);
    String withinDialogContext = (String) session.getAttribute(WITHIN_DIALOG_CONTEXT);
    LOGGER.info("Within context: " + withinDialogContext);
    // adds standing order to category
    if (PLAIN_CATEGORY_INTENT.equals(intentName)) {
        return standingOrderCategoryResponse(intent, session);
    }
    if (SAVINGS_PLAN_INTRO_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, "SavingsPlan");
        return askForBasicAmount(session);
    } else if (context != null && context.equals("SavingsPlan") && withinDialogContext != null) {
        if ((PLAIN_NUMBER_INTENT.equals(intentName) || PLAIN_EURO_INTENT.equals(intentName)) && withinDialogContext.equals("BasicAmount")) {
            return saveBasicAmountAndContinue(intent, session);
        }
        if ((PLAIN_NUMBER_INTENT.equals(intentName) || PLAIN_EURO_INTENT.equals(intentName)) && withinDialogContext.equals("MonthlyPayment")) {
            return saveMonthlyPaymentAndContinue(intent, session);
        }
        if ((PLAIN_NUMBER_INTENT.equals(intentName) || PLAIN_YEARS_INTENT.equals(intentName)) && withinDialogContext.equals("Duration")) {
            return saveDurationAndContinue(intent, session);
        } else if (YES_INTENT.equals(intentName)) {
            return createSavingsPlan(intent, session);
        } else if (NO_INTENT.equals(intentName)) {
            return getAskResponse(SAVINGS_PLAN, "Nenne einen der Parameter, die du aendern willst " + "oder beginne neu, indem du \"Neu\" sagst.");
        } else if (SAVINGS_PLAN_CHANGE_PARAMETER_INTENT.equals(intentName)) {
            return askAgainForParameter(intent, session);
        } else if (SAVINGS_PLAN_NEW_INTENT.equals(intentName)) {
            session.getAttributes().clear();
            session.setAttribute(DIALOG_CONTEXT, "SavingsPlan");
            return askForBasicAmount(session);
        } else if (STOP_INTENT.equals(intentName)) {
            return getResponse("Stop", "");
        } else {
            throw new SpeechletException("Unhandled intent: " + intentName);
        }
    } else {
        throw new SpeechletException("Unhandled intent: " + intentName);
    }
}
Also used : SpeechletException(com.amazon.speech.speechlet.SpeechletException) Intent(com.amazon.speech.slu.Intent) Session(com.amazon.speech.speechlet.Session)

Aggregations

Session (com.amazon.speech.speechlet.Session)13 Intent (com.amazon.speech.slu.Intent)9 SpeechletException (com.amazon.speech.speechlet.SpeechletException)6 IntentRequest (com.amazon.speech.speechlet.IntentRequest)4 SessionStorage (amosalexa.SessionStorage)1 Slot (com.amazon.speech.slu.Slot)1 Map (java.util.Map)1 Account (model.banking.Account)1 TransferTemplate (model.banking.TransferTemplate)1 Account (model.banking.account.Account)1 Category (model.db.Category)1 User (model.db.User)1