Search in sources :

Example 6 with Session

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

the class ContactTransferService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    Intent intent = requestEnvelope.getRequest().getIntent();
    Session session = requestEnvelope.getSession();
    String intentName = intent.getName();
    String context = (String) session.getAttribute(DIALOG_CONTEXT);
    switch(intentName) {
        case CONTACT_TRANSFER_INTENT:
            return contactTransfer(intent, session);
        case CONTACT_CHOICE_INTENT:
            return contactChoice(intent, session);
        case YES_INTENT:
            if (context.equals(CONTACT_CHOICE_INTENT)) {
                return performTransfer(intent, session);
            }
            return null;
        case NO_INTENT:
            session.setAttribute(DIALOG_CONTEXT, "");
            return getResponse(CONTACT_TRANSFER_CARD, "Okay, verstanden. Dann bis zum nächsten Mal.");
        // adds standing order to category
        case PLAIN_CATEGORY_INTENT:
            return transactionCategoryResponse(intent, session);
        default:
            return null;
    }
}
Also used : Intent(com.amazon.speech.slu.Intent) Session(com.amazon.speech.speechlet.Session)

Example 7 with Session

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

the class BalanceLimitService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    Intent intent = requestEnvelope.getRequest().getIntent();
    Session session = requestEnvelope.getSession();
    SessionStorage.Storage sessionStorage = SessionStorage.getInstance().getStorage(session.getSessionId());
    model.db.User user = (User) DynamoDbMapper.getInstance().load(model.db.User.class, USER_ID);
    if (intent.getName().equals(SET_BALANCE_LIMIT_INTENT)) {
        Map<String, Slot> slots = intent.getSlots();
        Slot balanceLimitAmountSlot = slots.get("BalanceLimitAmount");
        if (balanceLimitAmountSlot == null || balanceLimitAmountSlot.getValue() == null) {
            return getAskResponse(CARD_TITLE, "Auf welchen Betrag möchtest du dein Kontolimit setzen?");
        }
        String balanceLimitAmount = balanceLimitAmountSlot.getValue();
        if (balanceLimitAmount.equals("?")) {
            return getErrorResponse("Der angegebene Betrag ist ungültig.");
        }
        sessionStorage.put(NEW_BALANCE_LIMIT, balanceLimitAmount);
        return getAskResponse(CARD_TITLE, "Möchtest du dein Kontolimit wirklich auf " + balanceLimitAmount + " Euro setzen?");
    } else if (intent.getName().equals(GET_BALANCE_LIMIT_INTENT)) {
        return getResponse(CARD_TITLE, "Dein aktuelles Kontolimit beträgt " + user.getBalanceLimit() + " Euro.");
    } else if (intent.getName().equals(YES_INTENT)) {
        if (!sessionStorage.containsKey(NEW_BALANCE_LIMIT)) {
            return getErrorResponse();
        }
        String balanceLimitAmount = (String) sessionStorage.get(NEW_BALANCE_LIMIT);
        user.setBalanceLimit(Integer.parseInt(balanceLimitAmount));
        DynamoDbMapper.getInstance().save(user);
        return getResponse(CARD_TITLE, "Okay, dein Kontolimit wurde auf " + balanceLimitAmount + " Euro gesetzt.");
    } else if (intent.getName().equals(NO_INTENT)) {
        return getResponse(CARD_TITLE, "");
    }
    return null;
}
Also used : User(model.db.User) User(model.db.User) Slot(com.amazon.speech.slu.Slot) Intent(com.amazon.speech.slu.Intent) SessionStorage(amosalexa.SessionStorage) Session(com.amazon.speech.speechlet.Session)

Example 8 with Session

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

the class StandingOrderService 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);
    LOGGER.info("Intent Name: " + intentName);
    LOGGER.info("Context: " + context);
    if (STANDING_ORDERS_INFO_INTENT.equals(intentName)) {
        LOGGER.info(getClass().toString() + " Intent started: " + intentName);
        session.setAttribute(DIALOG_CONTEXT, "StandingOrderInfo");
        return getStandingOrdersInfoResponse(intent, session);
    } else if (STANDING_ORDERS_DELETE_INTENT.equals(intentName)) {
        LOGGER.info(getClass().toString() + " Intent started: " + intentName);
        session.setAttribute(DIALOG_CONTEXT, "StandingOrderDeletion");
        return askForDDeletionConfirmation(intent, session);
    } else if (STANDING_ORDERS_MODIFY_INTENT.equals(intentName)) {
        LOGGER.info(getClass().toString() + " Intent started: " + intentName);
        session.setAttribute(DIALOG_CONTEXT, "StandingOrderModification");
        return askForModificationConfirmation(intent, session);
    } else if (STANDING_ORDERS_KEYWORD_INTENT.equals(intentName)) {
        LOGGER.info(getClass().toString() + " Intent started: " + intentName);
        session.setAttribute(DIALOG_CONTEXT, "StandingOrderKeyword");
        return getStandingOrdersInfoForKeyword(intent, session);
    } else if (STANDING_ORDERS_SMART_INTENT.equals(intentName) && session.getAttribute("StandingOrderToModify") == null) {
        LOGGER.info(getClass().toString() + " Intent started: " + intentName);
        session.setAttribute(DIALOG_CONTEXT, "StandingOrderSmartIntent");
        return smartUpdateStandingOrderConfirmation(intent, session);
    } else if (YES_INTENT.equals(intentName) && context != null && (context.equals("StandingOrderSmartIntent"))) {
        return smartUpdateStandingOrderResponse(session);
    } else if (context != null && (context.equals("StandingOrderSmartIntent")) && session.getAttribute("StandingOrderToModify") != null) {
        return smartCreateStandingOrderResponse(session);
    } else if (YES_INTENT.equals(intentName) && context != null && (context.equals("StandingOrderInfo"))) {
        return getNextStandingOrderInfo(session);
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals("StandingOrderDeletion")) {
        return getStandingOrdersDeleteResponse(intent, session);
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals("StandingOrderKeyword")) {
        return getStandingOrderKeywordResultsInfo(session);
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals("StandingOrderModification")) {
        return getStandingOrdersModifyResponse(intent, session);
    } else if (NO_INTENT.equals(intentName) && context != null && !(context.equals("StandingOrderDeletion") || context.equals("StandingOrderModification"))) {
        // Simply quit session with 'Tschuess'
        return getResponse(STANDING_ORDERS, "Okay, tschuess!");
    } else if (NO_INTENT.equals(intentName) && context != null && (context.equals("StandingOrderDeletion") || context.equals("StandingOrderModification"))) {
        // Ask for a correction afterwards
        return getCorrectionResponse(intent, session);
    } else {
        return null;
    }
}
Also used : Intent(com.amazon.speech.slu.Intent) Session(com.amazon.speech.speechlet.Session)

Example 9 with Session

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

the class BudgetTrackerService 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);
    String withinDialogContext = (String) session.getAttribute(WITHIN_DIALOG_CONTEXT);
    if (withinDialogContext == null) {
        withinDialogContext = "";
    }
    if (CATEGORY_LIMIT_INFO_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, CATEGORY_LIMIT_INFO_INTENT);
        return getCategoryLimitInfo(intent);
    } else if (PLAIN_CATEGORY_INTENT.equals(intentName)) {
        return getCategoryLimitInfo(intent);
    } else if (CATEGORY_LIMIT_SET_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, CATEGORY_LIMIT_SET_INTENT);
        return saveSlotValuesAndAskForConfirmation(intent, session);
    } else if ((PLAIN_NUMBER_INTENT.equals(intentName) || PLAIN_EURO_INTENT.equals(intentName)) && context != null && context.equals(CATEGORY_LIMIT_SET_INTENT)) {
        Map<String, Slot> slots = intent.getSlots();
        String newLimit = slots.get(NUMBER_SLOT_KEY) != null ? slots.get(NUMBER_SLOT_KEY).getValue() : null;
        if (newLimit == null) {
            return getAskResponse(BUDGET_TRACKER, "Das habe ich nicht ganz verstanden. Bitte wiederhole deine Eingabe.");
        }
        session.setAttribute(CATEGORY_LIMIT, newLimit);
        String categoryName = (String) session.getAttribute(CATEGORY);
        return askForConfirmation(categoryName, newLimit);
    } else if (CATEGORY_SPENDING_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, intentName);
        return saveSpendingAmountForCategory(intent, session, false);
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals(CATEGORY_SPENDING_INTENT) && !withinDialogContext.equals("createCategory")) {
        return saveSpendingAmountForCategory(intent, session, true);
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals(CATEGORY_SPENDING_INTENT) && withinDialogContext.equals("createCategory")) {
        String categoryName = (String) session.getAttribute("categoryName");
        String amount = (String) session.getAttribute("categoryAmount");
        Category category = new Category(categoryName);
        DynamoDbMapper.getInstance().save(category);
        return getResponse(BUDGET_TRACKER, "Ich habe die Kategorie " + categoryName + " erstellt und " + amount + " Euro hinzugefuegt.");
    } else if (YES_INTENT.equals(intentName) && context != null && context.equals(CATEGORY_LIMIT_SET_INTENT)) {
        return setCategoryLimit(session);
    } else if (NO_INTENT.equals(intentName) && context != null && context.equals(CATEGORY_LIMIT_SET_INTENT)) {
        return askForCorrection(session);
    } else if (STOP_INTENT.equals(intentName) && context != null && context.equals(CATEGORY_LIMIT_SET_INTENT)) {
        return getResponse("Stop", null);
    } else if (CATEGORY_STATUS_INFO_INTENT.equals(intentName)) {
        session.setAttribute(DIALOG_CONTEXT, intentName);
        return getCategoryStatusInfo(intent);
    } else {
        throw new SpeechletException("Unhandled intent: " + intentName);
    }
}
Also used : Category(model.db.Category) SpeechletException(com.amazon.speech.speechlet.SpeechletException) Intent(com.amazon.speech.slu.Intent) Map(java.util.Map) Session(com.amazon.speech.speechlet.Session)

Example 10 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 = AccountAPI.getAccount(ACCOUNT_ID);
    if (request.getIntent().getName().equals(YES_INTENT)) {
        String cardNumberObj = (String) session.getAttribute("BlockCardService.CardNumber");
        if (cardNumberObj != null) {
            long cardNumber = Long.parseLong(cardNumberObj);
            return getResponse(BLOCK_CARD, "Karte " + cardNumberObj + " wurde gesperrt.");
        }
        return null;
    } else if (request.getIntent().getName().equals(NO_INTENT)) {
        session.setAttribute("BlockCardService.CardNumber", null);
        return getResponse(BLOCK_CARD, "Okay, tschüss.");
    } else if (request.getIntent().getName().equals(BLOCK_CARD_INTENT)) {
        String bankCardNumber = request.getIntent().getSlot("BankCardNumber").getValue();
        if (bankCardNumber == null) {
            return getAskResponse(BLOCK_CARD, "Wie lautet die Nummber der Karte?");
        } else {
            session.setAttribute("BlockCardService.CardNumber", bankCardNumber);
            return getAskResponse(BLOCK_CARD, "Möchten Sie die Karte " + bankCardNumber + " wirklich sperren?");
        }
    }
    return null;
}
Also used : Account(model.banking.Account) IntentRequest(com.amazon.speech.speechlet.IntentRequest) 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