Search in sources :

Example 1 with SessionStorage

use of amosalexa.SessionStorage in project amos-ss17-alexa by c-i-ber.

the class AuthenticationManager method isAuthenticated.

public static boolean isAuthenticated() {
    SessionStorage sessionStorage = SessionStorage.getInstance();
    Boolean authenticated = (Boolean) sessionStorage.getObject(AUTHENTICATION_SESSION, AUTHENTICATION_ATTRIBUTE);
    return authenticated == null ? false : authenticated;
}
Also used : SessionStorage(amosalexa.SessionStorage)

Example 2 with SessionStorage

use of amosalexa.SessionStorage in project amos-ss17-alexa by c-i-ber.

the class BankAccountService method getNextTransaction.

/**
 * returns a response with the next transaction in the list
 *
 * @param i index at the current postion in the transaction list
 * @return speechletResponse
 */
private SpeechletResponse getNextTransaction(int i) {
    List<Transaction> transactions = TransactionAPI.getTransactionsForAccount(account.getNumber());
    String transactionText = Transaction.getTransactionText(transactions.get(i));
    if (i - 1 < transactions.size()) {
        transactionText = transactionText + Transaction.getAskMoreTransactionText();
        SessionStorage sessionStorage = SessionStorage.getInstance();
        sessionStorage.putObject(sessionID, CONTEXT_FURTHER_TRANSACTION_INDEX, i + 1);
    }
    return getSSMLAskResponse(CARD_NAME, transactionText, REPROMPT_TEXT);
}
Also used : Transaction(model.banking.Transaction) SessionStorage(amosalexa.SessionStorage)

Example 3 with SessionStorage

use of amosalexa.SessionStorage in project amos-ss17-alexa by c-i-ber.

the class BankAccountService method onIntent.

@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
    Intent intent = requestEnvelope.getRequest().getIntent();
    sessionID = requestEnvelope.getSession().getSessionId();
    // get dialog context index
    SessionStorage sessionStorage = SessionStorage.getInstance();
    Integer furtherTransactionDialogIndex = (Integer) sessionStorage.getObject(sessionID, CONTEXT_FURTHER_TRANSACTION_INDEX);
    if (furtherTransactionDialogIndex != null) {
        if (intent.getName().equals(YES_INTENT)) {
            return getNextTransaction(furtherTransactionDialogIndex);
        }
        if (intent.getName().equals(NO_INTENT)) {
            return getResponse(CARD_NAME, ACCEPTANCE_TEXT);
        }
    }
    String slotValue = intent.getSlot(SLOT_NAME) != null ? intent.getSlot(SLOT_NAME).getValue().toLowerCase() : null;
    if (slotValue != null) {
        setAccount();
        if (transactionSlots.contains(slotValue)) {
            return handleTransactionSpeech();
        }
        String speech = account.getSpeechTexts().get(slotValue);
        return getSSMLResponse(CARD_NAME, speech);
    }
    return null;
}
Also used : Intent(com.amazon.speech.slu.Intent) SessionStorage(amosalexa.SessionStorage)

Example 4 with SessionStorage

use of amosalexa.SessionStorage 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 5 with SessionStorage

use of amosalexa.SessionStorage in project amos-ss17-alexa by c-i-ber.

the class BankAccountService method handleTransactionSpeech.

/**
 * responses each transaction from a account
 *
 * @return SpeechletResponse to alexa
 */
private SpeechletResponse handleTransactionSpeech() {
    List<Transaction> transactions = TransactionAPI.getTransactionsForAccount(account.getNumber());
    if (transactions == null || transactions.isEmpty()) {
        LOGGER.warn("Account: " + account.getNumber() + " has no transactions");
        return getResponse(CARD_NAME, EMPTY_TRANSACTIONS_TEXT);
    }
    StringBuilder stringBuilder = new StringBuilder(Transaction.getTransactionSizeText(transactions.size()));
    int i;
    for (i = 0; i < TRANSACTION_LIMIT; i++) {
        stringBuilder.append(Transaction.getTransactionText(transactions.get(i)));
    }
    if (i - 1 < transactions.size()) {
        stringBuilder.append(Transaction.getAskMoreTransactionText());
        SessionStorage sessionStorage = SessionStorage.getInstance();
        sessionStorage.putObject(sessionID, CONTEXT_FURTHER_TRANSACTION_INDEX, i);
    } else {
        return getResponse(CARD_NAME, LIST_END_TRANSACTIONS_TEXT);
    }
    return getSSMLAskResponse(CARD_NAME, stringBuilder.toString(), REPROMPT_TEXT);
}
Also used : Transaction(model.banking.Transaction) SessionStorage(amosalexa.SessionStorage)

Aggregations

SessionStorage (amosalexa.SessionStorage)5 Intent (com.amazon.speech.slu.Intent)2 Transaction (model.banking.Transaction)2 Slot (com.amazon.speech.slu.Slot)1 Session (com.amazon.speech.speechlet.Session)1 User (model.db.User)1